below is my current Fader automation. It is activated by an input_boolean.sz_fade entity; when it is turned on, it will set various WLED lights to nightlight mode (which means they will slowly fade darker and darker until they turn off).
Unfortunately, when this nightlight switch is activated, even those lights that are currently not turned on will initiate nightlight mode (so they will first turn on, then turn off), which can be a bit annoying.
I thought of using if as a template, but there must be an easier approach:
# (...)
action:
- service: switch.turn_on
data:
entity_id: >
{% if is_state('light.sz_bett', 'on') and is_state('light.sz_tv', 'on') and is_state('light.sz_window', 'on') %}
- switch.light.sz_bett_nightlight
- switch.light.sz_tv_nightlight
- switch.light.sz_window_nightlight
{% else if (......) %}
# multiple different conditions, for example, if "bett" and "tv" are on and "window" is off, return
# - switch.light.sz_bett_nightlight
# - switch.light.sz_tv_nightlight
# only
{% endif %}
This would mean that Iād have to create conditions for each case
I am having a rather hard time with jinja2, so I donāt know what to doā¦ but is it possible to say āthese are all lights; check all of their statuses, then return those that are currently on onlyā?
Tomās solution was my first approach, as I could understand it more easily (the selectattr part confuses me a bit and seems to return more than expected, output below).
However, this does not work. even though it should. My entire package for this is listed below. When I check it for errors via settings -> server control -> check configuration, it will show no errors. IF I create an error on purpose and check again, it will show this error (so the .yaml file is being checked by Home Assistant!). However, the automation does not show in developer settings -> state. The automation ought to be named automation.l_sz_fader, but it is not there (after multiple restarts and manually re-loading automations).
I renamed the .yaml file to something else and restarted again, but the automation is still not there. Perhaps this is related to this issue, but I could usually fix it by renaming the yaml filesā¦
I just came up with this, and it seems to work. I used the same line for entity_id, removed the >, and changed {% %} to {{ }}. Now the automation will show up and it seems to work fine.