Hi Guys,
I’ve just another automation question but first let me explain what I’m trying to achieve.
I’ve ordered a few ESP8266 and I want to create a switch for some lights e.g. I’m using the limitless led.
Now an issue I have is I need to match the status of essentially 2 switches as an example the limitless led has no clue about the mutt switch so I created the following automation to turn on and off the lights if e.g. the button is pressed on my ESP8266 switch and also two more automations to match the state to the ESP8266 if the light is switched on via the WebUI.
I came up with this:
### Turn on light when MQTT button is pressed
- alias: MQTT button livingroom on
hide_entity: true
trigger:
- platform: state
entity_id: switch.mqtt_test
to: 'on'
action:
- service: homeassistant.turn_on
entity_id: light.livingroom_door
### Turn off light when MQTT button is pressed
- alias: MQTT button livingroom off
hide_entity: true
trigger:
- platform: state
entity_id: switch.mqtt_test
to: 'off'
action:
- service: homeassistant.turn_off
entity_id: light.livingroom_door
## Update light when light is turned off by other means
- alias: MQTT state button livingroom on
hide_entity: true
trigger:
- platform: state
entity_id: light.livingroom_door
to: 'on'
action:
service: mqtt.publish
data:
topic: 'home/test/stat'
payload: 'on'
### Update light when light is turned off by other means
- alias: MQTT button livingroom off
hide_entity: true
trigger:
- platform: state
entity_id: light.livingroom_door
to: 'off'
action:
service: mqtt.publish
data:
topic: 'home/test/stat'
payload: 'off'
Now I’m wondering is there any better way to do this ? This would be 4 automation rule per switch I’d like to reduce this but unsure how to do it. I will need to match the status because if I switch on the light via the webui then the switch will think it’s still off and on the first press try to turn it on which isn’t the correct thing to do that means I need to somehow sync the states.
Any ideas suggestions etc appreciated.