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

 找回密码
 立即注册
查看: 7915|回复: 21

[技术探讨] Esphome控制夏普W380空气净化器遇到的问题。

[复制链接]

1

主题

50

帖子

195

积分

注册会员

Rank: 2

积分
195
金钱
144
HASS币
0
发表于 2021-5-6 00:19:23 | 显示全部楼层 |阅读模式
本帖最后由 kingmos 于 2021-5-6 11:44 编辑

小白一个,一直是看着论坛各位大侠的葫芦比着画四不像的瓢,受益良多!
这次是看了https://post.smzdm.com/p/a07m0dn8/,看样子可以把家里的W380纳入到HA的管辖范围里来。

马上动手就拆:提醒一下,W380底边的螺丝有个三叉的特异螺丝,需要专用的螺丝刀。
电路板背面如图:
IMG_20210505_23500422222.jpg

file:///C:/Users/King/AppData/Local/Temp/msohtmlclip1/01/clip_image002.png
和继电器连接:
IMG_20210505_23495211111.jpg
file:///C:/Users/King/AppData/Local/Temp/msohtmlclip1/01/clip_image004.png

前面板上竟然有大大的5V,莫非夏普早就知道我要改装?

IMG_20210505_235015.jpg
file:///C:/Users/King/AppData/Local/Temp/msohtmlclip1/01/clip_image006.jpg


file:///C:/Users/King/AppData/Local/Temp/msohtmlclip1/01/clip_image008.jpg

现在遇到的问题:

1.    面板上有8个键,nodemcu上使用了:D1,D2,D5,D6,D7,D8, 不够,还差两个,其他接口还有那些能使用而不影响单片机运行呢?
switch:                             ##设备类型;
  - platform: gpio                  ##平台;  
    id: air_close                    ##ID 为继电器开关; 
    pin: GPIO5
    icon: "mdi:fan-off"
    name: "air_close" 
  - platform: gpio                  ##平台;  
    id: air_water_open                    ##ID 为继电器开关; 
    pin: GPIO4 
    icon: "mdi:fan-off"
    name: "air_water_open" 
  - platform: gpio                  ##平台;  
    id: air_open                    ##ID 为继电器开关; 
    pin: 
      number: GPIO14                   ##管脚D5
      inverted: no                 ## inverted 参数,表示高电平有效,即继电器是高电平触发;
    icon: "mdi:fan-off"
    name: "air_open"                   ##自定义名称,最好起关联的名称;   
  - platform: gpio
    id: air_kill_open
    pin: GPIO12
    icon: "mdi:fan"
    name: "air_kill_open"
  - platform: gpio
    id: air_changewind
    pin:
      number: D7
      inverted: no
    icon: "mdi:fan"
    name: "air_changewind"
  - platform: gpio
    id: air_lightchange
    pin:
     number: D8
     inverted: no
    icon: "mdi:fan"
    name: "air_lightchange"


2.    按键应该短按后释放,而switch操纵的继电器按下后会使按键长时间闭合。按照教程,可以使用模板:
  - platform: template

    name: "Gate Remote"

    icon: "mdi:gate"

    internal: yes

    turn_on_action:

    - switch.turn_on: switch_0

    - delay: 500ms

- switch.turn_off: switch_0


但没教多个按键怎么写,我就每个都写了一遍:
  - platform: template
    name: "off1"
    icon: "mdi:gate"
    internal: yes
    turn_on_action:
    - switch.turn_on: air_close
    - delay: 500ms
    - switch.turn_off: air_close
  - platform: template
    name: "off2"
    icon: "mdi:gate"
    internal: yes
    turn_on_action:
    - switch.turn_on: air_water_open
    - delay: 500ms
    - switch.turn_off: air_water_open
  - platform: template
    name: "off3"
    icon: "mdi:gate"
    internal: yes
    turn_on_action:
    - switch.turn_on: air_open
    - delay: 500ms
    - switch.turn_off: air_open
  - platform: template
    name: "off4"
    icon: "mdi:gate"
    internal: yes
    turn_on_action:
    - switch.turn_on: air_kill_open
    - delay: 500ms
    - switch.turn_off: air_kill_open
  - platform: template
    name: "off5"
    icon: "mdi:gate"
    internal: yes
    turn_on_action:
    - switch.turn_on: air_changewind
    - delay: 500ms
    - switch.turn_off: air_changewind
  - platform: template
    name: "off6"
    icon: "mdi:gate"
    internal: yes
    turn_on_action:
    - switch.turn_on: air_lightchange
    - delay: 500ms
    - switch.turn_off: air_lightchange
  - platform: template
    name: "off7"
    icon: "mdi:gate"
    internal: yes
    turn_on_action:
    - switch.turn_on: air_Ionswitch
    - delay: 500ms
    - switch.turn_off: air_Ionswitch
目前是switch已经正常了,可以控制继电器,是按下去的效果,继电器保持闭合,但瞬时开关丝毫没有效果,按键不会在500毫秒后弹起。那位大侠可以解惑?

回复

使用道具 举报

2

主题

65

帖子

1075

积分

金牌会员

Rank: 6Rank: 6

积分
1075
金钱
1010
HASS币
0
发表于 2021-5-6 02:38:48 | 显示全部楼层
本帖最后由 fenytk 于 2021-5-6 02:46 编辑

瞬间开关https://esphome.io/components/switch/gpio.html#momentary-switch另外,控制转接可以用npn三极管或是光耦,继电器板太占地方了

回复

使用道具 举报

1

主题

172

帖子

2138

积分

金牌会员

Rank: 6Rank: 6

积分
2138
金钱
1966
HASS币
0
发表于 2021-5-6 08:55:13 | 显示全部楼层
分享一个供楼主参考,另外可以用binary_sensor检查电源LED来判断开关状态

esphome:
  name: $device_name
  platform: ESP8266
  board: nodemcuv2
  esp8266_restore_from_flash: yes

substitutions:
  #设备名称
  device_name: air_purifier

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

#------- WIFI AP配置 -------
  ap:
    ssid: $device_name
    password: "1234567890"
captive_portal:

web_server:
  port: 80

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: D6
      mode: INPUT_PULLUP
    name: "Air Purifier Power"
    filters:
      - delayed_off: 1200ms

switch:
  - platform: gpio
    pin: D1
    inverted: yes
    id: filter
  - platform: gpio
    pin: D2
    inverted: yes
    id: anion
  - platform: gpio
    pin: D3
    inverted: yes
    id: on_off
  - platform: gpio
    pin: D4
    inverted: yes
    id: speed
  - platform: template
    name: "Air Purifier on off"
    turn_on_action:
    - switch.turn_on: on_off
    - delay: 500ms
    - switch.turn_off: on_off
  - platform: template
    name: "Air Purifier Speed"
    turn_on_action:
    - switch.turn_on: speed
    - delay: 500ms
    - switch.turn_off: speed
  - platform: template
    name: "Air Purifier Anion"
    turn_on_action:
    - switch.turn_on: anion
    - delay: 500ms
    - switch.turn_off: anion
  - platform: template
    name: "Air Purifier Filter Reset"
    turn_on_action:
    - switch.turn_on: filter
    - delay: 3500ms
    - switch.turn_off: filter
  - platform: template
    name: "Air Purifier Child Lock"
    turn_on_action:
    - switch.turn_on: filter
    - delay: 100ms
    - switch.turn_on: speed
    - delay: 3100ms
    - switch.turn_off: speed
    - delay: 100ms
    - switch.turn_off: filter
  - platform: restart
    name: "Air Purifier Restart"
回复

使用道具 举报

1

主题

50

帖子

195

积分

注册会员

Rank: 2

积分
195
金钱
144
HASS币
0
 楼主| 发表于 2021-5-6 11:24:32 | 显示全部楼层
fenytk 发表于 2021-5-6 02:38
瞬间开关https://esphome.io/components/switch/gpio.html#momentary-switch另外,控制转接可以用npn三极管 ...

就是参考这个写的,但估计写的不对,没有效果

npn三极管或是光耦,继电器板太占地方了----是挺占地儿,但复杂的咱不是不会麽
回复

使用道具 举报

1

主题

50

帖子

195

积分

注册会员

Rank: 2

积分
195
金钱
144
HASS币
0
 楼主| 发表于 2021-5-6 11:25:43 | 显示全部楼层
MattSmell 发表于 2021-5-6 08:55
分享一个供楼主参考,另外可以用binary_sensor检查电源LED来判断开关状态

多谢援手,我先研究一下看看嫩不嫩看懂,看不懂我就照抄一下
回复

使用道具 举报

1

主题

50

帖子

195

积分

注册会员

Rank: 2

积分
195
金钱
144
HASS币
0
 楼主| 发表于 2021-5-6 11:41:07 | 显示全部楼层
本帖最后由 kingmos 于 2021-5-6 11:42 编辑
MattSmell 发表于 2021-5-6 08:55
分享一个供楼主参考,另外可以用binary_sensor检查电源LED来判断开关状态

仔细看了一遍,除了没有


binary_sensor:
  - platform: gpio
    pin:
      number: D6
      mode: INPUT_PULLUP
    name: "Air Purifier Power"
    filters:
      - delayed_off: 1200ms

这段以外,瞬时开关写的都是一样的,我这个每个瞬时模板多定义了
icon: "mdi:gate"
    internal: yes
应该没有影响吧,今天回去删了试试。
另外是不是没有贴全,感觉最后没有结束。
回复

使用道具 举报

1

主题

172

帖子

2138

积分

金牌会员

Rank: 6Rank: 6

积分
2138
金钱
1966
HASS币
0
发表于 2021-5-6 13:01:13 | 显示全部楼层
kingmos 发表于 2021-5-6 11:41
仔细看了一遍,除了没有

需要隐藏不在前台显示的 switch 才用 internal: yes,你把 template 的 switch 隐藏了,操控的还是 gpio 的 switch
回复

使用道具 举报

1

主题

50

帖子

195

积分

注册会员

Rank: 2

积分
195
金钱
144
HASS币
0
 楼主| 发表于 2021-5-6 14:41:42 | 显示全部楼层
MattSmell 发表于 2021-5-6 13:01
需要隐藏不在前台显示的 switch 才用 internal: yes,你把 template 的 switch 隐藏了,操控的还是 gpio  ...

是啊,但是实际在模块的网页中操纵开关,继电器并不会闭合后延时打开,好像template没有起作用
回复

使用道具 举报

1

主题

50

帖子

195

积分

注册会员

Rank: 2

积分
195
金钱
144
HASS币
0
 楼主| 发表于 2021-5-6 16:37:49 | 显示全部楼层
MattSmell 发表于 2021-5-6 08:55
分享一个供楼主参考,另外可以用binary_sensor检查电源LED来判断开关状态

厉害了厉害了,你的代码就执行成功啦
回复

使用道具 举报

1

主题

50

帖子

195

积分

注册会员

Rank: 2

积分
195
金钱
144
HASS币
0
 楼主| 发表于 2021-5-6 17:05:27 | 显示全部楼层
MattSmell 发表于 2021-5-6 13:01
需要隐藏不在前台显示的 switch 才用 internal: yes,你把 template 的 switch 隐藏了,操控的还是 gpio  ...

原来如此,第一次看还没有看懂。多谢指教!!!
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-20 11:33 , Processed in 0.068736 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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