I asked for some help on the forums with this, and it was suggested I post in the forums as it may be a little complex. Hoping someone can help get me started!
In short, I currently have a device configured like this (topic, etc has been simplified for clarity):
- platform: mqtt
name: "My Device"
state_topic: "things/my-device/mode/read"
state_on: "3"
state_off: "4"
command_topic: "things/my-device/mode/write"
payload_on: "{\"value\":\"3\"}"
payload_off: "{\"value\":\"4\"}"
value_template: "{{ value_json.value }}"
This works great. Toggling the switch writes either {"value":"3"}
or {"value":"4"}
to the command topic as it should, and the state is shown correctly.
However, the device actually has 2 switches (we’ll call them A and B), not one, and they are both reported by same MQTT topic. The values are:
Value | A | B
------|-----|---
1 | on | off
2 | off | on
3 | on | on
4 | off | off
Until now, I’ve only been interested in toggling both switches together, so switching the mode
value from 3
to 4
worked fine. But now I’d like to toggle them independently.
I think what I need is a template switch, but I’m unclear how to combine that with MQTT. Again, I think the way it should work is that I make two switches - A and B.
A would be configured such that it is on
if value
is 1 or 3
, else off
. B would be configured to be on
if value
is 2 or 4
. Then the payload_on
and payload_off
fields for each switch would need to check the value of the other switch and set the appropriate value. Am I on the right lines?
Any help would be appreciated!