I am having a watershed moment with my home automation journey.
I have just moved/switched from ZHA to zigbee2mqtt. The first day of the move has been the best decision I have made in years…
However…
I use these 4 major building blocks in my HA system
- Home Assistant
- Node Red (Automations)
- ESPhome (Physical Switch Devices)
- And now zigbee2mqtt (The lights)
How I have in the past controlled lights was to send a command to Node Red from my switch
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 400ms
then:
- if:
condition:
or:
- not:
- api.connected:
- switch.is_off: 'load1'
then:
- switch.toggle: 'load1'
- homeassistant.event:
event: esphome.top_yoga_room
data:
title: Single Click
Using the State Node I could basically see what the state of the Lights were and turn them off or on.
But an issue with ZigBee devices is the network can get cluttered.
So I tried this…
- homeassistant.service:
service: light.toggle
data:
entity_id: light.living_room_ceiling
Which is toggling the zigbee2mqtt group of lights.
But that caused another issue. Sometimes the state of the group is not reflected in Home Assistant correctly.
So, then I thought, use MQTT…
Have Node Red (using the Round Robin node) Send ‘on’ or ‘off’ payloads via the mqtt publish node
That works in a clumsy way. So, now I am reading this…
And for testing I was wondering is it possible to have a physical toggle switch once pushed determine the MQTT state of the light group then send a MQTT message in the opposite?
Ex.
[D][binary_sensor:036]: 'pico Button': Sending state ONe
[D][binary_sensor:036]: 'pico Button': Sending state OFFe
If zigbee2mtqq light is off, then send "mqtt payload on"
else send "mqtt payload off"
So, the esphome device does not even talk to Home Assistant.
This is an example of my switch
So the question is can a “physical toggle switch” when pressed determine via MQTT the current state of a zigbee2mqtt group, then determined on the result (if/then) publish an “on or off” payload via MQTT?
I have never used Lambdas or templates. I try to research and sit on the shoulders of smarter people than me.
P.S
A quick proviso, if this is not a good/best solution I would love to hear ways that this has been solved. The disconnect between the state of a zigbee2mqtt group and Home Assistant is not 100%, so the above is what I came up with.