本帖最后由 shadowba 于 2022-7-14 16:42 编辑
一颗esp8266通过esphome控制车辆部分硬件,是不是搞的太多了,8266会不会吃不消。大部分控制都在8266内部实现。如果有时间我觉得还应该加上车内温度采集。左右灯是通过继电器直接驱动原车左右灯,主要用来锁车或开锁时提供灯光提示,根据个人需要可以不接入。车门通过微动开关捕捉驾驶位手扣的位置来实现,发动机,充电等等需要拆开仪表盘,把表盘上的相应指示灯通过光耦隔离后接入,说白了只要有电子基础都挺简单,无非就是一些开关量信号。另外加入了逼格满满的NFC刷卡开门关门,扩展模块都是用的I2C总线,以节约8266io接口,至于汽车电瓶电量消耗问题,目前还可接受。欢迎探讨!目前实现如下功能:
1.远程开,关车门,后背箱。。。(已接入小爱语音)
2.手机NFC通过左侧后视镜内NFC模块开关车门,解决地库没手机信号车辆无法控制,实际发现NFC更便捷,不用拿手机点来点去
3.开关锁车后鸣笛,同时闪光
4.车辆启动后自动感应光线强弱,实现自动大灯,并延时关闭
5.车辆充电、启动状态远程推送至手机微信
6.以后出门不用找钥匙了
编程小白代码如下,仅供参考,能力不同,欢迎优化
i2c:
- id: bus_a
sda: 4
scl: 14
scan: true
pn532_i2c:
update_interval: 1s
mcp23017:
- id: 'mcp23017_hub'
address: 0x20
pcf8574:
- id: 'pcf8574_hub'
address: 0x21
pcf8575: true
binary_sensor:
- platform: pn532
uid: XX-XX-XX-XX
name: "Car-NFC Sensor"
icon: "mdi:nfc"
on_press:
then:
- if:
condition:
- binary_sensor.is_on: carlock
then:
- switch.turn_on: relay8
- if:
condition:
- binary_sensor.is_off: carlock
then:
- switch.turn_on: relay7 #打开开锁继电器
- platform: gpio # 光照传感器示廓灯
pin:
mcp23xxx: mcp23017_hub
# Use pin B7
number: 15
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-parking-lights sensor"
icon: "mdi:car-parking-lights"
device_class: light
id: parking
filters:
- delayed_on: 1s
- delayed_off: 15s
on_press:
then:
- if:
condition:
- binary_sensor.is_on: engine
then:
- switch.turn_on: relay10 #自动打开示廓灯
on_release: #感应不到光线
then:
- switch.turn_off: relay10 #自动打开示廓灯
- platform: gpio # 传感器近光灯控制
pin:
mcp23xxx: mcp23017_hub
# Use pin B6
number: 14
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-light-dimmed-light sensor"
icon: "mdi:lightbulb-on"
device_class: light
id: dimmed
filters:
- delayed_on: 1s
- delayed_off: 10s
on_press:
then:
- if:
condition:
and:
- binary_sensor.is_on: engine
- binary_sensor.is_on: parking
then:
- switch.turn_on: relay5 #自动打开近光灯
on_release: #感应不到光线
then:
- switch.turn_off: relay5 #自动关闭近光灯
- platform: gpio # 发动机状态传感器
pin:
mcp23xxx: mcp23017_hub
# Use pin B5
number: 13
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-engine sensor"
device_class: running
icon: "mdi:engine"
id: engine
on_press:
then:
- if:
condition:
- binary_sensor.is_on: parking
then:
- switch.turn_on: relay10 #自动打开示廓灯
- if:
condition:
and:
- binary_sensor.is_on: dimmed
- binary_sensor.is_on: parking
then:
- switch.turn_on: relay5 #自动打开近光灯
- delay: 1s
- switch.turn_on: relay4 # 玻璃升降控制
- delay: 3s
- switch.turn_on: relay3 # 打开WIFI热点充电
on_release:
then:
- switch.turn_off: relay3 # 关闭WIFI热点充电
- switch.turn_off: relay10 #否则关闭近光灯
- switch.turn_off: relay5 # 关闭示廓灯控制
- delay: 1800s
- switch.turn_off: relay4 # 玻璃升降控制
- platform: gpio # 充电传感器
pin:
mcp23xxx: mcp23017_hub
# Use pin B4
number: 12
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-charging sensor"
device_class: battery_charging
icon: "mdi:ev-station"
id: charging
on_press:
- switch.turn_on: relay3 # 打开WIFI热点充电
on_release:
then:
- switch.turn_off: relay3 # 关闭WIFI热点充电
- platform: gpio # 充电插头传感器
pin:
mcp23xxx: mcp23017_hub
# Use pin B3
number: 11
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-power-plug sensor"
device_class: plug
icon: "mdi:power-plug"
- platform: gpio # 打开充电口
pin:
mcp23xxx: mcp23017_hub
# Use pin A0
number: 0
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-plug-button"
icon: "mdi:ev-plug-type2"
on_press:
- switch.toggle: relay14
- platform: gpio # 行李箱解锁
pin:
mcp23xxx: mcp23017_hub
# Use pin A1
number: 1
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-back-button"
icon: "mdi:car-back"
on_press:
- switch.toggle: relay1
- platform: gpio # 自动大灯开关
pin:
mcp23xxx: mcp23017_hub
# Use pin A2
number: 2
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-light-auto-button"
icon: "mdi:lightbulb-auto"
on_press:
- switch.toggle: relay10 # 关闭自动示阔灯控制
- switch.toggle: relay5 # 关闭自动近光灯控制
- platform: gpio # 后排座椅加热总控
pin:
mcp23xxx: mcp23017_hub
# Use pin A3
number: 3
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-seat-heater-bl-button"
icon: "mdi:car-seat-heater"
on_press:
- switch.toggle: relay12 # 座椅加热前左
- platform: gpio # 座椅加热前右
pin:
mcp23xxx: mcp23017_hub
# Use pin A4
number: 4
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-seat-heater-fl-button"
icon: "mdi:car-seat-heater"
on_press:
- switch.toggle: relay13
- platform: gpio # 座椅加热前右
pin:
mcp23xxx: mcp23017_hub
# Use pin A5
number: 5
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Car-seat-heater-fr-button"
icon: "mdi:car-seat-heater"
on_press:
- switch.toggle: relay12
- platform: gpio # 防盗门控制
pin:
mcp23xxx: mcp23017_hub
# Use pin A6
number: 6
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: true
name: "Door-key-button"
icon: "mdi:door-closed-lock"
- platform: gpio # 车辆上锁状态监测
pin:
mcp23xxx: mcp23017_hub
# Use pin A6
number: 7
# One of INPUT or INPUT_PULLUP
mode:
input: true
pullup: true
inverted: false
name: "Car-lock sensor"
device_class: lock
icon: "mdi:car"
id: carlock
switch:
- platform: gpio
name: "Car-light-R" # 右转向灯
pin:
pcf8574: pcf8574_hub
number: 0
mode:
output: true
inverted: true
icon: "mdi:arrow-right-bold"
id: relay
on_turn_on:
- delay: 500ms
- switch.turn_off: relay
- platform: gpio
name: "Car-back" # 行李箱解锁
pin:
pcf8574: pcf8574_hub
number: 1
mode:
output: true
inverted: true
icon: "mdi:car-back"
id: relay1
on_turn_on:
- delay: 500ms
- switch.turn_off: relay1 # 行李箱解锁
- switch.turn_on: relay # 右转向灯
- switch.turn_on: relay15 # 左转向灯
- delay: 500ms
- switch.turn_off: relay # 右转向灯
- switch.turn_off: relay15 # 左转向灯
- platform: gpio
name: "Car-seat-heater-fl" # 座椅加热前左
pin:
pcf8574: pcf8574_hub
number: 2
mode:
output: true
inverted: true
icon: "mdi:car-seat-heater"
id: relay2
on_turn_on:
- delay: 1800s
- switch.turn_off: relay2
- platform: gpio
name: "Wifi-battery-charging" #WIFI热点充电继电器控制
pin:
pcf8574: pcf8574_hub
number: 3
mode:
output: true
inverted: true
icon: "mdi:battery-charging"
id: relay3
- platform: gpio
name: "Car-windshield" # 玻璃升降控制
pin:
pcf8574: pcf8574_hub
number: 4
mode:
output: true
inverted: true
icon: "mdi:car-windshield"
id: relay4
- platform: gpio
name: "Car-light-dimmed" # 近光灯控制
pin:
pcf8574: pcf8574_hub
number: 5
mode:
output: true
inverted: true
icon: "mdi:lightbulb-on"
id: relay5
- platform: gpio
name: "Car-mirror-close" # 后视镜折叠
pin:
pcf8574: pcf8574_hub
number: 6
mode:
output: true
inverted: true
icon: "mdi:mirror"
id: relay6
interlock: [relay9]
on_turn_on:
- delay: 3.5s
- switch.turn_off: relay6
- platform: gpio
name: "Car-door-open" # 车门开锁
pin:
pcf8574: pcf8574_hub
number: 7
mode:
output: true
inverted: true
icon: "mdi:car-door"
id: relay7
on_turn_on:
- switch.turn_on: relay11 #鸣笛控制
- delay: 500ms
- switch.turn_off: relay7 # 关闭车门开锁继电器
- switch.turn_on: relay9 # 后视镜展开
- switch.turn_on: relay15 # 左转向灯
- delay: 500ms
- switch.turn_on: relay11 #鸣笛控制
- switch.turn_on: relay # 右转向灯
- delay: 500ms
- switch.turn_on: relay15 # 左转向灯
- delay: 500ms
- switch.turn_on: relay # 右转向灯
- platform: gpio
name: "Car-door-lock" # 车门上锁
pin:
pcf8574: pcf8574_hub
number: 8
mode:
output: true
inverted: true
icon: "mdi:car-door-lock"
id: relay8
on_turn_on:
- switch.turn_on: relay11 #鸣笛控制
- delay: 500ms
- switch.turn_off: relay8 # 车门上锁
- switch.turn_on: relay6 # 后视镜折叠
- switch.turn_on: relay # 右转向灯
- switch.turn_on: relay15 # 左转向灯
- delay: 500ms
- switch.turn_off: relay # 右转向灯
- switch.turn_off: relay15 # 左转向灯
- delay: 500ms
- switch.turn_on: relay # 右转向灯
- switch.turn_on: relay15 # 左转向灯
- delay: 500ms
- switch.turn_off: relay # 右转向灯
- switch.turn_off: relay15 # 左转向灯
- delay: 60s
- switch.turn_off: relay4 # 玻璃升降控制
- platform: gpio
name: "Car-mirror-open" # 后视镜展开
pin:
pcf8574: pcf8574_hub
number: 9
mode:
output: true
inverted: true
icon: "mdi:mirror"
id: relay9
interlock: [relay6]
on_turn_on:
- delay: 3.5s
- switch.turn_off: relay9
- platform: gpio
name: "Car-little-light" # 示廓灯
pin:
pcf8574: pcf8574_hub
number: 10
mode:
output: true
inverted: true
icon: "mdi:car-parking-lights"
id: relay10
- platform: gpio
name: "Car-whistle" # 鸣笛控制
pin:
pcf8574: pcf8574_hub
number: 11
mode:
output: true
inverted: true
icon: "mdi:bullhorn-variant"
id: relay11
on_turn_on:
- delay: 1ms
- switch.turn_off: relay11
- platform: gpio
name: "Car-seat-heater-fr" # 座椅加热前右
pin:
pcf8574: pcf8574_hub
number: 12
mode:
output: true
inverted: true
icon: "mdi:car-seat-heater"
id: relay12
on_turn_on:
- delay: 1800s
- switch.turn_off: relay12
- platform: gpio
name: "Car-seat-heater-bl" # 座椅加热后左
pin:
pcf8574: pcf8574_hub
number: 13
mode:
output: true
inverted: true
icon: "mdi:car-seat-heater"
id: relay13
on_turn_on:
- delay: 1800s
- switch.turn_off: relay13
- platform: gpio
name: "Car-ev-plug" # 充电口
pin:
pcf8574: pcf8574_hub
number: 14
mode:
output: true
inverted: true
icon: "mdi:ev-plug-type2"
id: relay14
on_turn_on:
- delay: 100ms
- switch.turn_off: relay14
- platform: gpio
name: "Car-light-L" # 左转向灯
pin:
pcf8574: pcf8574_hub
number: 15
mode:
output: true
inverted: true
icon: "mdi:arrow-left-bold"
id: relay15
on_turn_on:
- delay: 500ms
- switch.turn_off: relay15
|