How I handled scenes in node-red

I wanted to implement my scenes with Node-RED, so that I could invoke them with Alexa’s scene capability, but I couldn’t find a whole lot of info out there. So, I thought I’d write up my solution in case anyone found it useful.

On the Home Assistant side, I built a few “empty” scenes that I could trigger via Alexa, etc:

- name: TV Scene
  entities: {}
- name: Bedtime Scene
  entities: {}
- name: Good Morning Scene
  entities: {}

(The {} indicates an empty dictionary in YAML.)

Now I have some scenes I could trigger.

On the Node-RED side, I created a flow that starts with an “events” node that watches all “call_service” events, then checks the property inside each of those events to see if it was a scene activation. If it was, the second switch (“Which scene?”) routes each scene to the right place. (I’m using Link nodes to simplify the layout and reduce the amount of wire noise.)

Then, for each scene, I have an “Inject” node so I can test the scene, and this also serves as documentation to show which scene is which, since Links can’t have text associated with them.

I’m not sure if this is the best way to do it, but it worked for me! Hope it helps someone out. If you want the JSON for the nodes, I’ve uploaded them here: https://gist.github.com/tgerla/d6ffbb6314ce1587efbb2b2e70a13e68

15 Likes

This is how I did it.

I created a few input booleans to run my scripts.
I placed them in a single group so I can easily reset all of them to off after that any of them has been executed.

In node red I look for changes of the booleans to trigger my node red scripts.
I also turn off the group after my commands are done.

I then expose my booleans to my google assistant.
Then I created routines in the google assistant app to allow me to say “okay google, bedtime” instead of “okay google, turn on bedtime”. And the same goes for “good bye”, “good night” etc…

7 Likes

Thank you. This was exactly what I was looking for.

Thank you guys for sharing where you arrived, both methods are very helpful!

Let me suggest one more method

2 Likes

Really love when you find a good suggestion and it also answers another question thats been at me. I’ve been wondering how to format syntax in ‘data’ in the properties for lights for a few days now getting used to Node Red. Thanks alot for the link with the pics.

Still working of is there a better option to do this?

I have similar situation: I want to create bistable button using node red

  1. input source is sonoff RF switch
  2. button activates scene “light_01_on” - second click activates scene “light_01_off”

Assuming you can use other input triggers that Node Red - how to achieve toggle of current state?

It’s easy to relay on previous state of red node executed action, but can you actually be aware of last executed scene? could you provide some more examples on how to use input booleans for that? I think i’am lost trying to create scripts, automations and input booleans… :slight_smile:

Just to add, since they are scenes, I usually group all the nodes from one scene whithin one subflow. It looks a lot cleaner and tied up. So you get this:

Instead of this:

Once you create them, they show up in the palette in the left side as individual nodes, so you can easly drag and drop the scene again in whatever flow.

3 Likes