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:
Create a boolean input and listen to changes of its state and let Nabu Casa call something like ‘input_boolean.turn_on’
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.
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.
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 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:
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.
Check the box for expose to home assistant so it creates a switch
Create a script in HA
Add a call service action to that script, choose nodered.trigger and specify the switch you created
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.
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
It will turn my bulbs red and play a fireplace video on my tele with some background music.