Hi,
Firstly, I thoroughly suspect I just don’t know the right search term for what I am trying to do, so if you have suggestions, please tell me.
What I have is a remote node-red instance that is using MQTT to communicate back to HA. This remote device’s purpose is to act as an irrigation controller and switch on/off six relays. I am trying to determine what is the “best” way to expose the six relays back to HA via MQTT for control and automation within HA.
Option 1
The easiest would be exposing each relay as a separate MQTT switch. The downside would be that I’d need the irrigation controller to turn off any active relay when another one activates so that only one relay is active at a time (not enough water pressure to have many running simultaneously).
I am comfortable implementing this option.
Option 2
Expose a single MQTT switch as the “Irrigation Control ON/OFF” and a second entity as a MQTT Select or MQTT Number to allow the user to choose which relay should be used.
I think I can also implement this option by subscribing to the topics for each entity and performing an action if either changes.
Option 3
A single MQTT switch (or other MQTT entity if better suited) that includes the relay number as an attribute. To me, this seems similar to a light that has a state (on/off) and other attributes (brightness, colour, etc).
This option seems the most elegant, but I am struggling to understand how to practically implement it. Looking at the MQTT switch docs, there is the value_template (along with payload_on/off and state_on/off) but I don’t understand:
- How the value_template fits in in general - is it what is HA is expecting to receive or what format it sends a payload in?
- How do I send these payloads to the remote device from HA? As in when I want to have a front end control to turn on/off a specific relay? or the same from an automation?
- How do I send the correct status update from my remote device if something locally changes what relay is active and it’s state?
I have read the Templating docs page and have a basic understanding of the mechanics of the syntax.
Does anyone have suggestions of a good way to proceed in building this link between my remote device and Home Assistant?
Regards,