Nabu Casa best way to start node red sequence

And do you also set the boolean by having a script for it:

water_time:
  alias: Water Garden
  sequence:
    - service: input_boolean.turn_on
      data:
        entity_id: input_boolean.water_time

Or is there a simpler way?

I use the UI to create my input booleans for exactly this purpose. It’s under “helpers” in the configuration page. I then do exactly as you said with node-red and watch for a state change on the input boolean.

1 Like

This is how I do that.

How to trigger a Node-RED flow from the Home Assistant UI

@mbonani

Really nice post! In your comment section someone mentions node-red-contrib-home-assistant-websocket, do you use it instead of the ‘default’ node-red-contrib-home-assistant? I am not sure which one is more stable.

I would say that node-red-contrib-home-assistant-websocket is the current “default”.

The other one hasn’t been updated in the past two years.

1 Like

Thanks, I’ll need to migrate :smiley:

EDIT: seems to be installed already

I just implemented your solution and I works, I was just wondering how performant it is, because the call_service node is called for every service call. For example if there are service calls after the switch it will triger the call_service node again for each call.

I have moved all my scripts to Node-RED using this exact solution and haven’t noticed any issues personally so I can vouch for it. I also recently moved most of my scenes over in the same way (switch on payload.event.domain = 'scene' and payload.event.service = 'turn_on') to handle the fact that none of my scenes work anymore since they can’t use scripts or other scenes in them.

That being said, if you don’t like this idea or if you have some scripts that don’t you dont want to completely move over to Node RED and just want a Node RED flow to be triggered as one step in a series of steps you can use custom events to do this pretty easily. Scripts have a fire event option for actions that lets you create an event with a custom name and whatever payload you want. You can then use the Events: All node to listed for that specific event and take whatever action you want from it.

Although actually I just noticed in the comments of that guide linked by @mbonani all these ways may now be in the past. Apparently @Kermit added a nodered.trigger service that lets you trigger an event node from a service call, he talks about it here. This sounds like the preferred way to solve this problem going forward. Looks like I have some research to do into how this new way works.

Alright I did some testing. It’s pretty easy to use but a bit awkward for the use case of something like triggering a node RED flow from a google assistant command. Basically you check the “Expose to home assistant” checkbox and deploy, letting it make a switch that can enable or disable that node in Node RED. Then you can use the nodered.trigger service and provide it the entity ID of the switch it created to start that flow.

Note that if the switch is off though this does nothing, it only executes the flow if the node is enabled. There’s also a number of other options you can use for controlling specifically how a state node is triggered (what entity to use for condition evaluation, whether to evaluate conditions, if skipping conditions which output do you use, etc.)

This is fantastic for some use cases, like one use case I have is I have a Node RED flow I call ‘Downstairs presence lights’. I have a few sensors downstairs that detect when someone is moving around and the node is triggered to turn on the lights when they detect someone. And I have it exposed to home assistant so I can enable it only when its dark outside since its bright enough during the day. But I also have an event that fires as soon as the front door is open and I want that event to trigger the lights immediately if its dark out without waiting on the sensors to pick someone up. nodered.trigger is perfect here since its already exposed and I just need to force fire it on door open

But the google assistant one is a bit awkward. To make use of it here what you’d have to do is this:

  1. Add an events: all node in node red. Give it a name for its event. Literally anything, you won’t use it, just something so its not watching for all events.
  2. Check the box for expose to home assistant so it creates a switch
  3. Create a script in HA
  4. Add a call service action to that script, choose nodered.trigger and specify the switch you created
  5. Expose that script to Google assistant and create a routine to turn it on when you say a key phrase

To me this seems way more difficult then just creating stub scripts and listening for the call-service event for your script. Plus now you have a listener for an event that’s never going to be fired and a switch you don’t actually want that will break your routine if toggled off.

I think I’ll stick with my way for now. If someone shows there is actually seriously negative consequences to listening for the call-service event then I’ll probably switch to just having my scripts fire a custom event with their name that I can listen on instead. It seems easier to me then the switch option in these cases. Plus for scripts that have parameters you can then put those parameters in the event payload which it looks like you can’t really do with nodered.trigger. You can only provide a payload for the service if using a state node and overriding its conditions.

@Jdruwe I’ve been using this method for months and I never noticed any performance impact, everything works almost instantly.

Wow thank you for your investigation, I was planning on doing the same but as you already did it I will also continue using the call-service approach.

Thanks for the info :smiley:

Can you post your flow here? I couldn’t quite replicate it. Trying to initiate a flow based on a Google Home saying. I’m stuck.

I know you can start a flow in node red with the the trigger node. Can the entity node that creates an entity in HA also trigger a flow?

@jaron you want to be able to say I’m stuck to Google home and it starts a flow?

No so I’m wanting to say pretty much anything like “hey google…movie time” and then it starts a node red flow, that turns on my projector with a IR reader, it turns on my receiver, then turns the receiver to the right input." stuff like that. Or maybe a different saying like “hey google…arm the house” and it goes through and runs a bunch of automations in node red. Does that make sense?

I have it working here, I made an automation trigger on ‘sexy time’ just for giggles :smiley:
It will turn my bulbs red and play a fireplace video on my tele with some background music.

lol can you post your flow code here? not sure how to do it and what nodes to use for getting this to work. thanks in advance

I followed the tutorial created by @mbonani -> https://bonani.tech/how-to-trigger-a-node-red-flow-from-the-home-assistant-ui/. Then I looked into using IFTTT to call a service when a google home command is triggered (more info here: https://www.juanmtech.com/integrate-google-assistant-with-home-assistant-cloud/)

@jaron I’ve done it multiple ways. You have a few options. In this one I just created an input_boolean, then went into Google Home app and set the routine to turn on the input_boolean as they will show in google home app. Then in Node Red just set the trigger to when the input_boolean turns on. At the end of the flow I turn the input_boolean back to off.

[{"id":"6c789af2.056ce4","type":"trigger-state","z":"b8c28a04.5e92f8","name":"mbtv_trig_input","server":"53a8fc13.2b2ef4","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_boolean.master_bed_tv_change_input","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"fl9ikijjktp","targetType":"this_entity","targetValue":"","propertyType":"property","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":3,"customoutputs":[{"outputId":"vwa17378r5t","messageType":"payload","messageValue":"true","messageValueType":"bool","comparatorPropertyType":"property","comparatorPropertyValue":"new_state.state","comparatorType":"is","comparatorValue":"on"}],"outputinitially":false,"state_type":"str","x":130,"y":80,"wires":[[],[],["db95581a.11d248"]]},{"id":"53a8fc13.2b2ef4","type":"server","z":"","name":"Home Assistant","addon":true}]