MQTT Switch for Node Red Control

Hi

I keep seeing on the forums to create a simple MQTT switch to plug into Node Red to enable/disable certain flows. Eg using the Traffic Node.

If you do this could you please show me your config yaml for the MQTT switch. I’m just not sure if I have it set correctly.

This is what I have. But the output in node red is on or off.

  • platform: mqtt
    name: “Node Red Stop Go Switch”
    command_topic: “switch/nodered/set”
    payload_on: “enable”
    payload_off: “disable”
    retain: false

Regards

Update:

These switches can pass on the payload I want.

However, there is no state with this setup.

Is there a setting to show feedback from node red if it is on/off or True/False or engaged/disengade.

Which ever payload I have sent,

I would recommend using an input_boolean in Home Assistant.

Thanks, however, I wonder if there is a way to create a global or flow wide variable that stores a virtual state that updates on changing the payload.

Found a very simple solution

I just published to the state topic via mqtt.

would you mind sharing how?

Things have changed so much since then, for example the ability to expose switches from Node Red to HA simplifies all this.