A group is on if any member of it is on. At the same time, a group being on does not necessarily mean all of its members are on - there just needs to be at least one member on. That’s on the state side of things.
On the service side of things, when you turn on a group, it recursively finds all the components in the group and any sub-groups, and turns them all on.
So, when you turn on outside_front_lights, that turns on all of its members (i.e., both switches.) Now that those switches are on that makes group.outside_front_lights on. And now that it is on that makes group.outside_lights on. That doesn’t mean, however, that group.outside_outlet (and its members) have been turned on.
I know I could probably test this (and probably will) but thought I’d ask. I feel like my goodnight routine is getting a bit combersome, as in once in a while I find a light or switch that does not get turned off. It’s been happening a bit more lately, so I wanted to break up the lights in to a few different groups depending on type, etc. Anyway I have this automation
- alias: Light alert
trigger:
- platform: state
entity_id: input_select.security_system
to: 'Armed (Home)'
for:
minutes: 3
- platform: state
entity_id: input_select.security_system
to: 'Armed (Away)'
for:
minutes: 3
condition:
- condition: state
entity_id: group.good_night_devices_full
state: 'on'
action:
- service: homeassistant.turn_off
entity_id:
- group.good_night_devices_full
- delay:
seconds: 15
- condition: state
entity_id: group.good_night_devices_full
state: 'on'
- service: notify.pushbullet_notifications
data_template:
target:
- !secret pauls_secret_email
title: Lights failed to turn off
message: >
{% set lights_on = states | selectattr('entity_id', 'in', state_attr('group.good_night_devices_full','entity_id')) | selectattr('state','eq','on') | map(attribute='name') | join(', ') %}
The following Lights failed to turn off: {{ lights_on }}. This was the second attempt. Please turn off using the app.
Basically the master group is a group of groups. Will this work? Will it return the name of a group or the entity in the sub group?
Well I think it would work based on my template testing, but it will not tell me which lights are on,just which groups are on. Need to parse the groups in the groups, haha. I’ll see what I can come up with
total hack here, but this could work with 2 layers.
{% set entities = states.group | selectattr('entity_id', 'in', state_attr('group.good_night_devices_full','entity_id')) | selectattr('state','eq','on') | map(attribute='attributes.entity_id') | list | join(', ') | replace('(','') | replace(')','') | replace("'",'') | replace('"','') %}
{% set entities = entities.split(', ') %}
{% set lights_on = states | selectattr('entity_id', 'in', entities) | selectattr('state','eq','on') | map(attribute='name') | list %}
The following Lights failed to turn off: {{ lights_on }}. This was the second attempt. Please turn off using the app.
{% set all = namespace(lights = []) %}
{% for group in state_attr('group.good_night_devices_full', 'entity_id') %}
{% set all.lights = all.lights + state_attr(group, 'entity_id')|list %}
{% endfor %}
The following Lights failed to turn off: {{
states|selectattr('entity_id', 'in', all.lights)
|selectattr('state', 'eq', 'on')
|map(attribute='name')|join(', ')
}}. This was the second attempt. Please turn off using the app.
Some lighting technologies support scenes. Instead of sending ten individual commands to turn off ten lights, you program all ten lights to be part of a scene (example: all ten lights turn off when they receive scene command #1). Now you can send one scene command to control ten lights. The advantage is less communications traffic (one command traveling on the network instead of ten) and speed (all lights react simultaneously).
If your lights normally respond well when operated individually but sometimes not when operated as a group, network congestion may be the culprit and using a scene may improve reliability.
Funny you mention Scenes. I posted this yesterday trying to get a good understanding of scenes.
So, scenes are aware of the state of all lights in the scene? I do use scenes quite a bit to turn on lights, but not so much for turning off groups of lights.
My goodnight routine turns off lights, switches, zwave, hue, zigbee, and a couple media players as well.
I know how to scene these items, but it really comes down to awareness. I just needed to know for sure thats how scene’s worked.
I was referring to the (hardware-based) scenes provided by some lighting technologies not the (software-based) Scenes provided by Home Assistant.
The Scenes in Home Assistant don’t reduce network traffic because they still send ten commands for ten lights.
Z-Wave and Zigbee support scenes but you’d have to confirm the devices you have support the feature.
You could create two ‘All Lights Off’ (hardware) scenes, one for Z-Wave and another for Zigbee. Use either an automation, script, Scene, etc in Home Assistant to call the two ‘All Lights Off’ scenes plus whatever additional commands to turn off other things (that don’t support hardware-based scenes). The advantage of this approach is that you send only one Z-Wave and one Zigbee command to control multiple lights thereby minimizing traffic on their respective RF networks.
Ahh, got it thanks. Yeah I don’t have any scene controllers at the moment. Well, I guess I have hue scenes. My lights are about 50% hue, 40% zwave (wall switches controlling ceiling lights, etc) and 10% zigbee plugs.
I might have a look at a scene controller. So if I understand correctly, if I get a scene controller for zwave lets say, that it will be aware of the state of the other lights, and send the commands to just the lights that need to be changed. Neat
You know this and the template from @petro have got me thinking about my whole goodnight and goodbye routines. I could use this to determine what lights/devices are on, and only send “off” commands to those. Which would greatly reduce my zwave network traffic. 50% of the devices in the group I use are usually off, but I have them in the group to turn off, just in case.
I never said you needed a ‘scene controller’. I have no idea where you go the idea of a ‘scene controller’.
Whatever Z-Wave/Zigbee controllers you are currently using are likely to support the sending of scene commands.
FWIW, Philips Hue uses the Zigbee protocol.
Using (hardware) scenes reduces the need for templates (to determine which lights are still off). Why? Because a scene is just one command to turn off all lights. It’s very efficient.
Think of a (hardware) scene as a broadcast message. Instead of communicating separately with each device, you blast one message heard by all devices. The ones that understand the broadcasted message comply as per their programming (when I receive scene command #1, I have been programmed to turn myself off).
Sorry, misunderstood. When you say hardware scenes I assumed (incorrectly) you were talking about a scene controller.
I guess I dont understand then. Can you give me an example of a device that are talking about. Most of my zwave devices are in wall GE dimmers and switches. I’ve never noticed and “Scene” stuff, but never looked for it either. I use HA scenes at the moment, which I understand from what you’ve said is not the same. How do I set scenes using hardware?
I do know that hue is zigbee, but all if my devices are still using the hue hub, I prefer it that way. Easier for me anyway, to integrate with other apps outside of HA.
I have several scenes, but most of them happen to use my hue lights but here is one that includes a zwave light as well
- name: TV Lights
entities:
light.kitchen_cabinet_bottoms:
state: on
brightness: 152
rgb_color: [255, 240, 198]
light.kitchen_cabinet_tops:
state: on
brightness: 191
rgb_color: [164, 234, 255]
light.living_room_lamp_two:
state: off
light.living_room_lamp_one:
state: on
brightness: 190
rgb_color: [255, 207, 120]
light.left_shelf_lights:
state: on
brightness: 71
rgb_color: [246, 255, 254]
light.tv_backlights:
state: on
brightness: 71
rgb_color: [246, 255, 254]
light.right_shelf_lights:
state: on
brightness: 71
rgb_color: [246, 255, 254]
light.alcove_light:
state: on
brightness: 150
color_temp: 444
light.sconce_light:
state: on
The seem to come on or turn off at the same time. I use
service: scene.turn_on
to turn on the scene. That was my question in the begining, but I think I’ve not fully understood scenese. @123, has confused me a bit. This is a “software” scene, right? What would be a hardware scene?
If I have a mixture of device types in my scene, zwave and Hue in my case, does my example above smart? I have another scene that has the state of many of these lights to “off” when turn on that scene, does it send commands to all lights “off” even if they are already off?
Typically with management software designed for the lighting technology. I don’t use Z-Wave or Zigbee so I can’t offer any examples. I know Homeseer can configure z-wave scenes … but that’s of no help for Home Assistant users. I’ll leave it to experienced Z-Wave/Zigbee users to chime in and explain the details.
In the Home Assistant Scene you defined (a software-based scene), you listed all the lights and how they should be controlled. When this Scene is executed, Home Assistant will run through that list and send commands to each light. So that’s one command transmitted per light.
Now imagine that you could program each physical light with the same information. So something like “turn myself on and set my brightness to 75% and my color to warm yellow” would be programmed into the lighting device itself and identified as “scene #1”. Another light’s “scene #1” could be “turn myself on and set my brightness to 50% and my color to bright red”. Now if you transmit a command to activate “scene #1” (just one command that’s broadcasted to all devices) the devices that have “scene #1” programming will set themselves accordingly. The devices that don’t have "scene #1’ programming just ignore the command.
That’s how a hardware-based scene works. However, I caution you that the term “scene” is not universal and lighting technologies may use other terms like groups, associations, receive components, etc. Plus there may be subtle variations in how they implement the functionality.
I’m not entirely convinced that the software scenes are the same as scripts anymore. A while back scenes was overhauled. If the lights come on in unison, chances are it’s utilizing the zwave scene control. Otherwise you’d see them come on/off in a sequence. I guess the only way to tell would be to monitor the zwave traffic.
Thanks @123 and @petro. I now have a more information on scenes and controller software. The issue I initially reported is pretty small. Once in a while I come downstairs in the morning and find a light on that should have been turned off. For the most part Home Assistant groups and HA scenes have served me pretty well. I think that the simple template and automation to come back behind me and “clean up” or maybe my new thought to use a template to only send off commands to lights that are on will really help.
My usual routine is to use scenes throughout the day/evening to set lighting based on what’s going on. TV, casual, evening, etc. Then to turn off whatever is on when I go to bed or leave.
Again, really appreciate the knowledge, it will help me in future en devours.