It’s easy to create an automation for each light so when it changes state, check the brightness value and if below certain value, set it to minimum.
But is there a way to do this automatically with any lights using just 1 automation with help of templates?
This template will give us the list of lights currently on and their settings. Can add count to the end for a count.
{% set domain = 'light' %}
{% set state = 'on' %}
{{ states[domain] | selectattr('state','eq', state) | list }}
This is the result for 2 lights that supports brightness (ones don’t won’t have brightness in its attributes):
[<template TemplateState(<state light.living_room_tv_light_bulb=on; supported_color_modes=['brightness'], color_mode=brightness, brightness=1, is_deconz_group=False, friendly_name=Living Room TV Light Bulb, supported_features=41 @ 2021-04-14T15:17:54.410311+01:00>)>, <template TemplateState(<state light.study_light=on; supported_color_modes=['brightness'], color_mode=brightness, brightness=2, is_deconz_group=False, friendly_name=Study Light, supported_features=41 @ 2021-04-14T15:18:01.420260+01:00>)>]
Question is, how do I then extract the entity ID and brightness values from that, using template codes?
With those 2 bits of information, I can then do a test to see whether the value is below certain number and finally run light.turn_on service to set the value as desired.
So, plan is: (psudo code)
Trigger:
- lights_on_count != saved lights_on_count
Action:
- updated saved lights_on_count
- extract all brightness and entity ID out of the fields
- condition continue if any brightness value is less than my desired minimum
- set the lights with brightness lower than minimum to minimum using service call
Any help or different way to achieve this is much appreciated.
Thanks!