Triggering Node-RED flow from HA

Hi,

I’m just getting started with NR (and still fairly new to HA). I have an NR flow setup which does the following,

  1. Turns on the Sonos wall plug, if not already on
  2. Waits for the Sonos to start
  3. Sets the volume
  4. Plays a given radio station

In order to trigger this from HA, I’ve defined switches in NR, listen for a state change to start the above routine and finally turn off the switch. While this works, however creating additional switches seems a little messy. Is there a cleaner way to achieve this?

If by switch you are referring to an input_boolean, then yes. That is the way you would typically manually trigger a NR flow from HA.

If you have the NR custom component installed in HA you can use the nodered.trigger service to start a flow on an exposed node.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/custom_integration/event-nodes.html
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/custom_integration/switch.html#use-cases

Personally, I use MQTT to trigger NR flows from Lovelace.

Rig the Lovelace button to send a (blank) message to a custom topic, and then subscribe to that topic in NR using the MQTT in node. Voila!

1 Like

Thanks for the tip.
MQTT makes it much simpler.
You can f.eks make a topic
ha/custom/button
The you can reuse the topic for many types of button by setting data to
button#1
button#2
button_bed_room

Then use a change node to test for what payload