Nabu Casa best way to start node red sequence

I am new to Node RED and Nabu Casa and I just want your opinion on the following ‘requirement’.
Let’s say I want to be able to say ‘Hey Google start watering my garden plants’, I know I can create a routine in the Google Home app or in IFTTT (if I want a custom response). In my use case I would like a Node RED sequence to be fired after ‘launching’ such command. I only found 2 ways to do this:

  1. Create a boolean input and listen to changes of its state and let Nabu Casa call something like ‘input_boolean.turn_on’
  2. I also saw another user @Muttly who created a script which in its turn sets a boolean and triggers a sequence: Trigger nodered flow from script

Are there any better ways that I am still missing?

Those are honestly the easiest. Set up google home to call the input Boolean when that particular phrase is said. That’s how I have all my “scenes” set up. Just make sure that the input Boolean gets reset to off. Otherwise you can’t call it again. The nice thing is. With the input Boolean you can have other flows call it not just google. It makes automations start to connect.

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