I have a lot of spotlight (hue) they are in groups (~10 in each groups), sometimes i have one spot that turn itself on (voltage drop i guess), i want to automate this check :
if only one bulb of the group is turned on, then turn it off.
What would be the simplest way to do this ? do i have to make one automation rule for each bulb ? (it would take me ages)
alias: "Turn off single light bulb in group cuisine"
trigger:
- platform: time_pattern
minutes: "/5"
condition:
condition: template
value_template: >
# this counts the light bulb that are on and if less than 2 are open, it will turn off the whole group
{{ states | selectattr('entity_id', 'in', state_attr('light.cuisine_2','entity_id')) | selectattr('state','in',['on','open']) | list | length < 2 }}
action:
- service: light.turn_off
target:
entity_id:
- light.cuisine_2
I tried to add this code into a new automation > go into YALM mode and paste it.
But when i have to save it says :
Message malformed: Integration ‘’ not found
I tried to mess around and change the format, but i can’t get it to work.
alias: Turn off single light bulb in group cuisine
trigger:
- platform: time_pattern
minutes: /5
condition:
- condition: template
value_template: >
# this counts the doors that are open and if we have any that are open,
the notify will occur {{ states | selectattr('entity_id', 'in',
state_attr('group.cuisine','entity_id')) |
selectattr('state','in',['on','open']) | list | length < 2 }}
action:
- service: light.turn_off
target:
entity_id:
- light.cuisine_2
mode: single
It seems to work as intended, but there is one last issue.
While testing it i found out that my light.turn_off service is acting weird when the bulb is already off, its turning the bulb on then off.
which is quite annoying.
So i have to add a condition in my action so it turns off only the bulb that is on.
I was sort of thinking that from your original post that you never just have one light one from the group…so then you would just be looking for a count = 1 to know to turn it off…
Instead of using hard coded light.cuisine_2 you should be able to use trigger.entity_id:
The trigger shouldn’t be time based, you should be able to have it trigger when the group or when a light goes on. I think you might have to use a comma separated list of the lights though instead of the group if you only want to have it turn it off if it is on.
trigger:
platform: state
entity_id: light.cuisine_1,light.cuisine_2,light.cuisine_3,light.cuisine_4,etc
to: 'on'
so your final would look like:
alias: Turn off single light bulb in group cuisine
trigger:
platform: state
entity_id: light.cuisine_1, light.cuisine_2, light.cuisine_3, light.cuisine_4
to: 'on'
condition:
- condition: template
value_template: >
{{ states | selectattr('entity_id', 'in',state_attr('group.cuisine','entity_id')) | selectattr('state','==','on') | list | length == 1 }}
action:
- service: light.turn_off
target:
entity_id: "{{ trigger.entity_id }}"
mode: single