I have many shelly1 devices controlling my main lights in each room. Based on lots of suggestions for stability I decided to run them all using MQTT and integrated them with HA as follows:
switch:
- platform: mqtt
unique_id: Hall_Main_Lights
name: "Hall Main Lights"
state_topic: "shellies/shelly1-8CAAB575877C/relay/0"
command_topic: "shellies/shelly1-8CAAB575877C/relay/0/command"
payload_off: "off"
payload_on: "on"
retain: "false"
These work great but I need to know if the light is on because of PIR sensor or switched at the wall.
There are are separate topics for these command topic above when switched from wifi (PIR) and input topic
"shellies/shelly1-E868E78722C1/input/0"
for switch changes.
To make it more complex i use edge switching so the switch toggles meaning switching up or down could be how it switches the relay on. But the input topic always shows switch state i.e. 1 for down 0 for up.
I thought of the following approach but it sounded to complex:
- Create a binary MQTT sensor for both command and input topics
- Monitor state changes for each with their own automation then set some helper
- drive my automation off the helper state change so I will know how the light was turned on.
I am still quite new to this so hoping smarter people than I have a better idea like some kind of template sensor or clever way to determine it using standard automation triggers/conditions
Thanks in advance for your help