Node-RED, trigger sequence on HA Start

Thanks Greg! This looks like a pretty elegant solution. I’ll give it a shot this weekend.

I’m trying to setup something just like this myself but I’ve never done anything with a shell command before. Read the docs and tried to create my own but it doesn’t work. What should my automation and/or shell command look like to create this?

Hi @Greg, could you please elaborate a bit on how to set up the execution of a shell command? I am a bit unsure where the ha_running line you posted is meant to go.

Have a look at https://www.home-assistant.io/components/shell_command/ for how to define a shell command.

On there it gives an example:

# Example configuration.yaml entry
# Exposes service shell_command.restart_pow
shell_command:
  restart_pow: touch ~/.pow/restart.txt

So substitute that for what I wrote:

shell_command:
   ha_running: 'curl http://url:port/hass/running'

You can call it anything you like, ha_running was just what made sense to me at the time.

Hi there,

I assume you are using the HA-websocket node. This node can handle all the HA events including Start-Up and Shutdown, as well other useful ones like “new-device” or “new-service”

Alternatively you can use “webhook” commands between NR and other systems like HA or motionEye.

There is no need for any shell or curl command.

Thanks for the clarfification @Greg! The url http://url:port/hass/running is that something that is usually called during startup? Because it gives me a 404 (unless I am also supposed to change that url to something else)

@xx_Nexus_xx yes, I am using node-red-contrib-home-assistant-websocket which doesnt seem to have a HA-websocket node. Perhaps I can install an additional palette?

Try create a yaml automation that triggers on homeassistant.start event put the action to delay 10-20 seconds then send a custom event. That event should appear and can be easily filtered with the event node.

1 Like

@xx_Nexus_xx do you know what the actual event_type, topic & payload values are? I have tried sticking a debug node on the all events node, but on a HA restart, it autofreshes my NR (I have it running in Hass.io) so I can’t grab it.

Any new ideas?

Similar to subzero’s solution above, I have a yaml automation that is triggered on HA start. After a 15 second delay, it turns on an input_boolean. An event state node triggers the flow when the boolean changes.

Another possible solution for those using node-red-contrib-home-assistant-websocket:

[{"id":"b66320a5.f8586","type":"server-events","z":"d0505e55.8a4b8","name":"","event_type":"home_assistant_client","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":160,"y":590,"wires":[["b46e7e0a.fef1f"]]},{"id":"b46e7e0a.fef1f","type":"switch","z":"d0505e55.8a4b8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"running","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":590,"wires":[[]]}]
4 Likes

What is the real motivation of this task? Sometimes it’s not about HA restart but about NodeRed restart instead, for example in order to initialize flow variables. Then Timestamp node is sufficient enough:

image

[{"id":"9bc0038d.3d9d58","type":"inject","z":"4339335e.61187c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":100,"wires":[["55dc8473.fd8404"]]}]
2 Likes

Hello! thx for this one! I like it very much. The only issue is that every time I deploy flows, it triggers the entire thing (because NR reconnects to HA). Anyway around that?

don’t deploy all flows but changed nodes only instead (see drop down part of deploy button)

3 Likes

What @maxym said

2 Likes

Ok did not know :sweat_smile: thx!

thank you, this worked for me and seems like a great solution as it does not require creating an automation in home assistant or messing with shell commands

This has been the solution I’ve been looking for since forever. I wish I could make this the “accepted answer”.

Works perfect, thanks!