Alexa! Turn off "everything in [room name]!" - best way to implement this using Node Red

For quite a while I have had the ability to tell Alexa “Turn off everything in [room name]” and she would turn a select number of lights/devices off. The way I was doing it was by creating a group within Alexa called “Everything in [room name]” but that got to be a pain when changes on the home automation side caused devices to drop off in Alexa. While the devices were easily added back into Alexa, they were not automatically added back to the groups. This issue was prevalent when I was using SmartThings given the number of times I had to exclude/include devices thus causing then to drop off the groups.

Now that I am using the far better Home Assistant platform and Node Red, I set out to find a way to have the same functionality without having to bother configuring stuff in Alexa (their app is so insanely poor!!). To do this I created a Help called “Everything in Office” and a few groups of lights/devices to limit the number of individual devices I need to work with in Node Red.

I am aware that many nodes, if not all, allow me to put multiple devices so they can all be turned on/off but that makes it harder for me to see what is being turned on/off so I use a node per device. If this creates inefficiencies or additional mesh traffic, please let me know.

My first attempt is below… it works but it is fairly complicated to replicate for all the rooms so I wonder whether there is an easier way to accomplish it.

The basics are that the 4 events: state nodes are 3 groups and a ceiling fan feed into the BooleanLogic Ultimate node (Gate 4). If any of the 4 nodes are on, then I turn on the “Everything in Office” helper. On the contrary, if ALL of the groups/devices are off, I turn the helper off.

Although it would appear that Alexa sends the on/off command to HA to toggle the helper regardless of its state, I prefer to actually make it reflect the correct state of things as this may break in the future or could simply be confusing to troubleshoot.

When the helper is toggled off, Node Red will turn off all the desired devices. Here I already see an issue as I really only need to actually turn off all the devices if I am issuing the command to do so via Alexa. If it is the node turning the helper off, it is doing so because all the devices are already off.

Adding a check to confirm that a device being turned off is actually on is easy but this is getting messy. Since I have to replicate this at least 13 times, likely more, I would like it to be as simple as possible.

I do not want to use HA’s room/area to toggle stuff, assuming it is possible (I haven’t looked into it), as it would toggle a lot of other devices that I do NOT want to toggle. In other words, when I leave a room and want to turn everything off, I actually only want to turn off all lights and devices that are normally off (like a TV, amplifier, table lamps, etc) but not outlets, for example, that are always on by default.

I’d love to get feedback on how to make this more efficient, simpler, better… etc.

[{"id":"bbffc5cda9d68280","type":"server-state-changed","z":"10166deaea152eef","name":"Everything in Office","server":"6f1799ba.17e938","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.everything_in_office","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":190,"y":400,"wires":[[],["3ab480d337c9ab2e"]]},{"id":"d09b6890bf67f12b","type":"link in","z":"10166deaea152eef","name":"Office Devices","links":["3ab480d337c9ab2e"],"x":790,"y":400,"wires":[["0059890465bd4959","646dc692a9c20197","e64d0e6fa0447b3c","dbc43c2176b8a809"]],"l":true},{"id":"3ab480d337c9ab2e","type":"link out","z":"10166deaea152eef","name":"Office","mode":"link","links":["d09b6890bf67f12b","eff68d7bc73d5c11"],"x":390,"y":400,"wires":[],"l":true},{"id":"eff68d7bc73d5c11","type":"link in","z":"10166deaea152eef","name":"Office Lights","links":["3ab480d337c9ab2e"],"x":790,"y":320,"wires":[["a28cba1c514b8aa9"]],"l":true},{"id":"0059890465bd4959","type":"api-call-service","z":"10166deaea152eef","name":"Office Fan >> off","server":"6f1799ba.17e938","version":5,"debugenabled":false,"domain":"fan","service":"turn_off","areaId":[],"deviceId":["d0af55ea5c082ccdeb12a040568bd88a"],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1070,"y":400,"wires":[[]]},{"id":"8ba1bf4b04a2c47d","type":"api-call-service","z":"10166deaea152eef","name":"Everything in Office >> on","server":"6f1799ba.17e938","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.everything_in_office"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1090,"y":160,"wires":[[]]},{"id":"4514201f600dcce4","type":"api-call-service","z":"10166deaea152eef","name":"Everything in Office >> off","server":"6f1799ba.17e938","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.everything_in_office"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":830,"y":220,"wires":[[]]},{"id":"a2c7f6a82cf8a37b","type":"server-state-changed","z":"10166deaea152eef","name":"All Office Lights","server":"6f1799ba.17e938","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.all_office_lights","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":200,"y":100,"wires":[["dfc615faed066153"]]},{"id":"a28cba1c514b8aa9","type":"api-call-service","z":"10166deaea152eef","name":"All Office Lights >> off","server":"6f1799ba.17e938","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.all_office_lights"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1080,"y":320,"wires":[[]]},{"id":"646dc692a9c20197","type":"api-call-service","z":"10166deaea152eef","name":"Shedder >> off","server":"6f1799ba.17e938","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":["64d2b9e52a20dc821dd33d4775261001"],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1060,"y":460,"wires":[[]]},{"id":"e64d0e6fa0447b3c","type":"api-call-service","z":"10166deaea152eef","name":"Office Workbench Instruments >> off","server":"6f1799ba.17e938","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.office_workbench_instruments"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1130,"y":520,"wires":[[]]},{"id":"d74e84904e0e94ce","type":"server-state-changed","z":"10166deaea152eef","name":"Office Workbench Instruments","server":"6f1799ba.17e938","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.office_workbench_instruments","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":160,"y":160,"wires":[["dfc615faed066153"]]},{"id":"be62367e21db59aa","type":"server-state-changed","z":"10166deaea152eef","name":"Office Workbench Tools","server":"6f1799ba.17e938","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.office_workbench_tools","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":180,"y":220,"wires":[["dfc615faed066153"]]},{"id":"dbc43c2176b8a809","type":"api-call-service","z":"10166deaea152eef","name":"Office Workbench Tools >> off","server":"6f1799ba.17e938","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.office_workbench_tools"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1110,"y":580,"wires":[[]]},{"id":"dfc615faed066153","type":"BooleanLogicUltimate","z":"10166deaea152eef","name":"","filtertrue":"both","persist":true,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":"4","topic":"result","restrictinputevaluation":false,"delayEvaluation":0,"x":450,"y":180,"wires":[[],["cd31d796426aff4d"],[]]},{"id":"cd31d796426aff4d","type":"switch","z":"10166deaea152eef","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":180,"wires":[["28157b391a5ca02f"],["4514201f600dcce4"]]},{"id":"28157b391a5ca02f","type":"api-current-state","z":"10166deaea152eef","name":"Everything in Office - off?","server":"6f1799ba.17e938","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.everything_in_office","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":830,"y":160,"wires":[["8ba1bf4b04a2c47d"],[]]},{"id":"f6cd1d66f4fc34de","type":"comment","z":"10166deaea152eef","name":"Everything in Office","info":"","x":150,"y":40,"wires":[]},{"id":"d8b527059a253b90","type":"server-state-changed","z":"10166deaea152eef","name":"Office Fan","server":"6f1799ba.17e938","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"fan.office_fan","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":220,"y":280,"wires":[["dfc615faed066153"]]},{"id":"0af74fc6eca18837","type":"comment","z":"10166deaea152eef","name":"Ignore shredder. Good to turn off but no need to track","info":"","x":300,"y":340,"wires":[]},{"id":"6f1799ba.17e938","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Edit: Being able to turn ON the lights/devices in the “Everything in Office” group is of little to no use in my case… so if the solution doesn’t allow it, even better.

Edit2: Google appears to have a super annoying “feature” that interprets “Everything in [room name]” as all the devices it knows are in that room so it turns literally everything on/off which I certainly do NOT want. A work around was to remove rooms from Google and just let it see the devices but when I recently re-activated device sharing with Google, I noticed that Home Assistant provides the rooms too… any way to fix this??

Edit3: The link in/out nodes are unnecessary, I know. I used them initially as a way to make this a bit cleaner as I thought it was going to be quite messy otherwise. I’ll likely get rid of them.

I’m partial to node-red-contrib-alexa-home-skill. It’s take a bit of reading to set up, but once you do it’s pretty slick. You create the device in a web interface, then your node is the actual device the echo sees. It is pretty configurable to do whatever you want, including turn off only.

Below is my entire flow to voice control my basement dimmer. I just set this one up, but you can use normal language when changing it “Computer, change basement dimmer to 60%” or “Computer, decrease basement dimmer by 20%”.
image

Part of my media center setup, my TV makes this be stupidly complicated so I cut some out. As sumple as “Echo, turn on XBox”:

Regarding this.
Do not leave rooms empty in Google Home app.
Unless they fixed it, what happens is that google assumes you want everything to turn off/on or even toggle depending on the device.
That was very annoying until I figured out why it was doing that.

1 Like

@Hellis81 - How do I prevent Google from turning on/off everything in a given room? I want it to act on the helper and not what they think I want to control. Of course, one way might be to use different words that Google does not recognize as some special command but I have been using this for years so I would rather not… plus I can’t think of another way of saying it in natural language.

Not sure I understand. I do have control of all my devices, etc via Alexa. I am trying to replicate what I had in Alexa which was simply a group of select devices per room named “Everything in [room name]”. I want to do it in HA/Node Red so that I don’t have to bother with Alexa and it will work. The helpers are all Alexa needs to know about and control, and Node Red will do the rest.

I am interested in your use case, but am not sure I understand what you are doing. Is it a way to control stuff without exposing all the devices to Alexa?

You can specify the device group/type with google assistant if you don’t want EVERY device to turn off.

“Hey google, turn of the lights in bed 1 and play kenny g on spotify in bed 1”

Bit longer to say for sure but get’s the job done.

I think a way around it would be to create two booleans for each room.
One named turn off everything that is always on.
One named turn on everything that is always off.

When google interacts with these the automation sees that you want to turn on or off things and you should be able to specify nicely what exactly should happen.
Then just reset the boolean to it’s previous state again.

With this setup you define your own devices (nodes in NR) that send appropriate payloads out. This way you don’t care how messed up the echo groups are.

So, you are only exposing the node devices to the echo system, not any actual devices.

Hopefully that makes sense.

I expose very few of my switches or lights directly to alexa, but with node red I can control everything I want to.

It depends on what kind of switches you use though, most of mine are zwave so my controls scheme is different for what you would use

If all your switches are alexa compatible, I expect they are wifi. If they are tuya type switches, you can use localtuya to control but getting the local key can be tricky. I use this for some of my switches, imho worth it in the long run.

There are likely other ways for either NR or HA to control your switches and lights, but it depends what you are using.

You can also use the alexa remote applestrudel pallete to control switches and things that are alexa controlled. I use it mostly to send voice messages to my dots.

IMHO, I wouldn’t worry about turning things off if they are already off, the extra traffic isn’t enough to be concerned about for the complexity it adds to your flows.
I have a good night flow that turns off all the downstairs lights, and I don’t check to see what’s on, just turn it all off.

Randy

@randytsuch I have about 90 zwave and 90 zigbee devices so both mesh networks are a bit congested. Reducing traffic is actually something I need to improve on as the congestion is causing me issues. I agree the checks complicate the flows but that is better than failing automations due to congestion. I just don’t know whether there is a better way of doing it. I’ve read stuff about multicast helping send one command over many but have not looked into it yet to see how it applies to me or how to leverage it.

Nearly 300 things are exposed to Alexa automatically by HA so I can already easily control all actionable devices (dimmers, switches, etc). My issue here is not controlling stuff via Alexa… that works great already, but rather creating a group called “Everything in Office” (just an example of one room) that will allow me to tell Alexa to “Turn off everything in office” when I leave the room. However, I do NOT want Alexa to turn off 100% of the devices in the room… when I leave the office I want to turn off all lights and several devices but a few others need to stay on. Why? Imagine you are in a living room with a TV connected to a switchable outlet, and you have a table lamp and a main light. When you leave you would turn off the TV (not the outlet powering it!) and the two lights. At night I turn off the outlet as well to reduce parasitic current draw (~16W when TV is powered off).

The easy solution to what I want is to just create an Alexa group that has the devices I want, but I am trying to move that portion to HA/NR so that the functionality is retained even in the event I wipe all devices from Alexa and sync them back (with Alexa groups you have to set it up all over again and I have lost count of how many times I have to go back to fix stuff).

Hopefully this makes me end goal a bit clearer :slight_smile:

Alex, you’re trying really hard to do a thing that is fighting native Alexa functionality. Maybe consider a different path.

How about this instead:
Use Alexa Media Player (I think you already have it installed) to expose TTS (AND the last spoken to attribute)
Where I’m going with this is create a module that uses the Alexa last spoken attribute (as a template sensor so it’s always updated) and Alexa actionable notifications such that when you trigger a phrase like:

Alexa turn off my stuff.

It then FIGURES out context based on which Echo heard the request. THEN forwards the ‘turn off’ to whatever flow you want.

If you’re in the kitchen, turn off my stuff would trigger, note it came from the kitchen echo then trigger the scene, automation, script, flow or whatever you want when turn off my stuff is spoken and understood by the kitchen echo.

This way you’re not messing with groups and therefore any additional ‘things’ Alexa’ wants to turn off.

1 Like

I’m tellin ya, you’ve got to look at these nodes I linked above. You could define whatever you want to call it. Let’s say “office devices”.

When you tell the echo to turn off “office devices” it sends the command to NR, which spits out an “off” payload. Then you connect your appropriate call-service nodes as needed.

This is literally the whole flow:
image

1 Like

@Hilo4321 - If Alexa will unconditionally trigger the off command without worrying whether it is on or not, then it seems like the perfect, and simple solution! I will try this right away, thank you!

@NathanCu - I need to look into what you propose but it sounds more advanced than what I can currently do. Also, one big issue is that I have at least 15 echos around the house and very frequently the one that hears and acts is actually quite far away and in another room. I’d love to be able to tweak the microphone gain on some of them but I am not aware of any way to do so.

Yep, it has no idea. Just spits out the command you give it. Read the docs carefully, there are a couple links in there.

@Hilo4321 - I just saw that it requires an account on a site in the UK. I would rather not add another cloud element to the mix… but I’ll keep this option in my back pocket.

I actually just thought of a simple solution…

The Echo will say ok to the command to “Turn off everything in Office” regardless of whether the helper called “Everything in Office” is actually on or off BUT if it is already off, NR won’t see a state change so nothing happens (or maybe Alexa doesn’t even issue the command). Given the actual state of the helper does not matter, I simply reset it after 500ms to on.

I guess I can skip the “is it on” check for each device given the command is not issued frequently… maybe I can do it for groups given the number of devices there may actually cause a storm on the mesh.

Fair enough. I didn’t really care because I’m already dealing with amazon. These are my only cloud devices.

Seems like an easy enough solution.

Have you considered a button helper? I don’t know of those show up for the echos, but then you don’t have rely on a “hacky” solution, not that there’s anything inherently wrong with that.

EDIT: You could also consider using groups, though they are limited to one type of device (e.g. light.xxxx). Workaround for that is using a template, I think.

Snippet from Group page:

By default, when any group member entity is on , the group will also be on .

Here is some info on what I figured out about Node Red and Alexa

I used the to use the cloud based alexa palette, but converted to

Which is local, but had some problems getting it to work. I have to run it on a PC because I was never able to get it working on my pi.

But I do have GitHub - 586837r/node-red-contrib-alexa-remote2
running on a pi, and you can do some pretty sophisticated flows with it, using it to interpret commands you say to Alexa. Examples in my link above.

BTW, can’t you define scenes in HA for each room? I don’t use scenes, but seems like they would help.

My latest iteration is:

The inject node triggers once upon flow deploy so that the toggle helper is on by default… otherwise the first time around it won’t work, or if the helper is somehow switched off and the reset fails, it will stop working. I believe the inject should work even upon reboot of HA so this should be a pretty good way to ensure the helper is on by default.

@Hilo4321 - I did consider the button as you suggested but I assumed that turn on/off for a button would not work… however I have not verified this. I guess I should check… :slight_smile:

If you only want off, then it doesn’t matter, since you are using NR :smiley:

EDIT: I suppose the echo command might be goofy. Worth a test run though.

@Hilo4321 - I meant that Alexa might not take a “Turn off” command for a momentary button as typically those are default off and push to turn on.

To verify I just tested it:

image

Given it is shared as a scene to Alexa, only “Turn on” works. You get the message “sorry it is not supported” if you try to use “Turn off”.

This could be handy for other stuff though… :slight_smile: