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

 找回密码
 立即注册
查看: 617|回复: 4

[技术探讨] sonoff刷esphome固件调用service触发switch不成功

[复制链接]

4

主题

37

帖子

418

积分

论坛积极会员

积分
418
金钱
381
HASS币
0
发表于 2023-10-24 19:31:30 | 显示全部楼层 |阅读模式
本帖最后由 guanine 于 2023-10-24 19:33 编辑

sonoff,esp8285,刷esphome。button附加on_press事件内,调用服务toggle一个switch。switch已加入HA,可以APP远程开/关;
sonoff的button按下时,log有显示,自身的switch.s3也触发打开。说明HA收到button事件了。但是switch.bathroom_light_white不会被触发,也没有任何信息。

相同的配置,在其它ESPHOME(esp8266-12E、nodemcu)上,GPIO的binary_sensor,on_事件都可以触发服务联动switch。
换单开版的易位联,button是gpio0,同样无法调用service触发。


想不通,请教各位。有没有什么排除思路

esphome:
  name: sonoff
  platform: ESP8266
  board: esp8285

# Enable logging
logger:

# Enable Home Assistant API
api:

# Example configuration entry
mqtt:
  broker: xxxxxxx
  username: xxx
  password: xxx

# Example configuration entry
web_server:
  port: 80

ota:
  password: "xxx"

wifi:
  ssid: "xxx"
  password: "xxx"

captive_portal:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: true
    name: "Button1"
    on_press:
      - switch.toggle: s1
  - platform: gpio
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: true
    name: "Button2"
    filters:
    - delayed_on_off: 200ms
    on_release:
      then:
        - switch.toggle: s2
        - homeassistant.service:
            service: switch.toggle
            data: {entity_id: switch.bathroom_light_white}
  - platform: gpio
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: true
    name: "Button3"
    on_press:
      - switch.toggle: s3
      - homeassistant.service:
          service: switch.toggle
          data: {entity_id: switch.bathroom_light_white}

switch:
  - platform: gpio
    name: "SW1"
    pin: GPIO12
    id: s1
  - platform: gpio
    name: "SW2"
    pin: GPIO5
    id: s2
  - platform: gpio
    name: "SW3"
    pin: GPIO4
    id: s3
[19:26:38][C][mqtt.switch:042]:   Command Topic: 'sonoff-06/switch/sw3/command'
[19:26:38][C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Button1':
[19:26:38][C][mqtt.binary_sensor:023]:   State Topic: 'sonoff-06/binary_sensor/button1/state'
[19:26:38][C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Button2':
[19:26:38][C][mqtt.binary_sensor:023]:   State Topic: 'sonoff-06/binary_sensor/button2/state'
[19:26:38][C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Button3':
[19:26:38][C][mqtt.binary_sensor:023]:   State Topic: 'sonoff-06/binary_sensor/button3/state'
[19:27:54][I][ota:105]: Boot seems successful, resetting boot loop counter.
[19:28:28][D][binary_sensor:036]: 'Button3': Sending state ON
[19:28:28][D][switch:021]: 'SW3' Toggling ON.
[19:28:28][D][switch:037]: 'SW3': Sending state ON
[19:28:29][D][binary_sensor:036]: 'Button3': Sending state OFF
[19:28:31][D][binary_sensor:036]: 'Button2': Sending state ON
[19:28:31][D][binary_sensor:036]: 'Button2': Sending state OFF
[19:28:31][D][switch:021]: 'SW2' Toggling ON.
[19:28:31][D][switch:037]: 'SW2': Sending state ON
[19:28:33][D][binary_sensor:036]: 'Button2': Sending state ON
[19:28:34][D][binary_sensor:036]: 'Button2': Sending state OFF
[19:28:34][D][switch:021]: 'SW2' Toggling OFF.
[19:28:34][D][switch:037]: 'SW2': Sending state OFF
[19:28:34][D][binary_sensor:036]: 'Button3': Sending state ON
[19:28:34][D][switch:021]: 'SW3' Toggling OFF.
[19:28:34][D][switch:037]: 'SW3': Sending state OFF
[19:28:35][D][binary_sensor:036]: 'Button3': Sending state OFF



回复

使用道具 举报

18

主题

423

帖子

1909

积分

金牌会员

Rank: 6Rank: 6

积分
1909
金钱
1486
HASS币
0
发表于 2023-10-24 21:50:10 | 显示全部楼层
      - homeassistant.service:
          service: switch.toggle
          data: {entity_id: switch.bathroom_light_white}

这一段是要来干嘛的?


binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff Basic Button"
    on_press:
      - switch.toggle: fakebutton

switch:
  - platform: template
    name: "Sonoff Basic Relay"
    optimistic: true
    id: fakebutton
    turn_on_action:
    - switch.turn_on: relay
    - light.turn_on: led
    turn_off_action:
    - switch.turn_off: relay
    - light.turn_off: led
  - platform: gpio
    id: relay
    pin: GPIO12

output:
  - platform: esp8266_pwm
    id: basic_green_led
    pin:
      number: GPIO13
      inverted: True

light:
  - platform: monochromatic
    name: "Sonoff Basic Green LED"
    output: basic_green_led
    id: led

这是我在用的
服务里能正常调用开关 切换
回复

使用道具 举报

4

主题

37

帖子

418

积分

论坛积极会员

积分
418
金钱
381
HASS币
0
 楼主| 发表于 2023-10-24 22:48:28 | 显示全部楼层
kjjuhfv 发表于 2023-10-24 21:50
这一段是要来干嘛的?

switch.bathroom_light_white是HA里其它的开关,我可以用这个button去toggle其它switch/light类
回复

使用道具 举报

18

主题

423

帖子

1909

积分

金牌会员

Rank: 6Rank: 6

积分
1909
金钱
1486
HASS币
0
发表于 2023-10-24 23:09:47 | 显示全部楼层
guanine 发表于 2023-10-24 22:48
switch.bathroom_light_white是HA里其它的开关,我可以用这个button去toggle其它switch/light类 ...

原来是这个意思
其实我的做法是做成传感器
然后在ha自动化里根据这个传感器的状态实现自己想要的目的
回复

使用道具 举报

4

主题

37

帖子

418

积分

论坛积极会员

积分
418
金钱
381
HASS币
0
 楼主| 发表于 2023-10-24 23:32:53 | 显示全部楼层
kjjuhfv 发表于 2023-10-24 23:09
原来是这个意思
其实我的做法是做成传感器
然后在ha自动化里根据这个传感器的状态实现自己想要的目的 ...

你这个办法确实可以,我刚尝试了,成功。

不过我场景是卧室的三开面板控制其它房间的灯,这样做的话,要写3个自动化。
如果类似的需求多了,自动化脚本就会很乱呐。当然也有好处,面板控制的开关一遍,不用重刷固件。

想不通的问题只是,为什么同样配置在ESP8266-12e上可以正常运转。
代码没区别嘛,难道还和chip有关吗

  - platform: gpio
    pin:
      number: 13
      mode:
        input: true
        pullup: true
    name: IN1
    filters:
    - delayed_on_off: 200ms
    on_press:
      then:
        - homeassistant.service:
            service: switch.toggle
            data: {entity_id: switch.esp01_light}


  - platform: gpio
    pin:
      number: 12
      mode:
        input: true
        pullup: true
    name: IN2
    filters:
    - delayed_on_off: 200ms
    on_press:
      then:
        - homeassistant.service:
            service: switch.toggle
            data: {entity_id: switch.bathroom_light_white}
            #bathroom_light_white
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-2 06:22 , Processed in 0.102167 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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