『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 3765|回复: 33

[新奇玩法] 这样是不是有点为难8266了

[复制链接]

37

主题

267

帖子

2149

积分

论坛DIY达人

积分
2149
金钱
1882
HASS币
20
发表于 2022-3-24 13:36:45 | 显示全部楼层 |阅读模式
本帖最后由 shadowba 于 2022-7-14 16:42 编辑

一颗esp8266通过esphome控制车辆部分硬件,是不是搞的太多了,8266会不会吃不消。大部分控制都在8266内部实现。如果有时间我觉得还应该加上车内温度采集。左右灯是通过继电器直接驱动原车左右灯,主要用来锁车或开锁时提供灯光提示,根据个人需要可以不接入。车门通过微动开关捕捉驾驶位手扣的位置来实现,发动机,充电等等需要拆开仪表盘,把表盘上的相应指示灯通过光耦隔离后接入,说白了只要有电子基础都挺简单,无非就是一些开关量信号。另外加入了逼格满满的NFC刷卡开门关门,扩展模块都是用的I2C总线,以节约8266io接口,至于汽车电瓶电量消耗问题,目前还可接受。欢迎探讨!目前实现如下功能:
1.远程开,关车门,后背箱。。。(已接入小爱语音)
2.手机NFC通过左侧后视镜内NFC模块开关车门,解决地库没手机信号车辆无法控制,实际发现NFC更便捷,不用拿手机点来点去
3.开关锁车后鸣笛,同时闪光
4.车辆启动后自动感应光线强弱,实现自动大灯,并延时关闭
5.车辆充电、启动状态远程推送至手机微信
6.以后出门不用找钥匙了

Screenshot_20220713_220247.jpg

Screenshot_20220713_220406.jpg


编程小白代码如下,仅供参考,能力不同,欢迎优化
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
回复

使用道具 举报

5

主题

265

帖子

1899

积分

金牌会员

Rank: 6Rank: 6

积分
1899
金钱
1634
HASS币
0
发表于 2022-3-24 13:54:35 | 显示全部楼层
这个不错。可以讲一下咋搞的吗。
回复

使用道具 举报

54

主题

317

帖子

1371

积分

金牌会员

Rank: 6Rank: 6

积分
1371
金钱
1054
HASS币
0
发表于 2022-3-24 15:16:17 来自手机 | 显示全部楼层
不难为,8266吃得消
回复

使用道具 举报

0

主题

50

帖子

1643

积分

金牌会员

Rank: 6Rank: 6

积分
1643
金钱
1593
HASS币
0
发表于 2022-3-24 17:23:03 | 显示全部楼层
控制的是什么车?
回复

使用道具 举报

0

主题

26

帖子

394

积分

中级会员

Rank: 3Rank: 3

积分
394
金钱
368
HASS币
0
发表于 2022-3-24 17:58:11 | 显示全部楼层
佩服lz 发挥到极致了这是 不过有些模块太多会遇到启动的时候加载问题,连不上wifi
后面找到有设置优先级的参数解决了这个问题
回复

使用道具 举报

34

主题

691

帖子

4423

积分

论坛元老

Rank: 8Rank: 8

积分
4423
金钱
3722
HASS币
50
发表于 2022-3-24 18:37:54 | 显示全部楼层
啥车能这么折腾,,我的秋名山神车五菱宏光只怕吃不消.
回复

使用道具 举报

16

主题

222

帖子

1711

积分

金牌会员

Rank: 6Rank: 6

积分
1711
金钱
1489
HASS币
0
发表于 2022-3-24 22:53:25 | 显示全部楼层
能不能介绍一下怎么搞?
回复

使用道具 举报

8

主题

361

帖子

3745

积分

论坛元老

Rank: 8Rank: 8

积分
3745
金钱
3384
HASS币
10
发表于 2022-3-25 02:45:50 | 显示全部楼层
esp01这么能这么玩才叫NB
回复

使用道具 举报

15

主题

636

帖子

2181

积分

金牌会员

Rank: 6Rank: 6

积分
2181
金钱
1545
HASS币
0
发表于 2022-3-25 08:28:23 | 显示全部楼层
你一个8266 01s干了整车厂的一大部分电路控制的活,你让整车厂的零部件供应商怎么活?
回复

使用道具 举报

37

主题

267

帖子

2149

积分

论坛DIY达人

积分
2149
金钱
1882
HASS币
20
 楼主| 发表于 2022-3-25 09:18:23 | 显示全部楼层
telanx 发表于 2022-3-25 08:28
你一个8266 01s干了整车厂的一大部分电路控制的活,你让整车厂的零部件供应商怎么活? ...

,关键是图个乐趣,不能老看动作片,对不
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-8 05:04 , Processed in 0.172499 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表