Hi all, I’ve got a bit stuck on an automation and wondering if anyone can help. I’m trying to make the 2 Lifx bulbs outside my courtyard toilet turn red when the toilet is in use to act as a sort of ‘busy’ indicator. When the toilet is no longer in use, I want the bulbs to copy the state of the other courtyard lights.
So far I have the following action:
action:
- service: light.turn_on
data_template:
entity_id:
- light.outer_toilet_1
- light.outer_toilet_2
color_temp: >-
{% if is_state("light.outer_lounge_sofa","on") and state_attr("light.outer_lounge_sofa","color_temp") != None %}
{{ state_attr("light.outer_lounge_sofa","color_temp") }}
{% else %}
285
{% endif %}
The problem with this is when the outer_lounge_sofa light is a non white color, then its attributes do not contain “color_temp” but instead contain rgb_color and hs_color. Similarly, when the outer_lounge_sofa is a white color, then its attributes do not contain either rgb_color or hs_color but instead contain “color_temp”.
This is why in the else section I have hard coded the warm white color of 285, but this is more of a failsafe than a solution.
Ideally I would like the following to work:
action:
- service: light.turn_on
data_template: >-
{% if is_state("light.outer_lounge_sofa","on") and state_attr("light.outer_lounge_sofa","color_temp") != None %}
entity_id:
- light.outer_toilet_1
- light.outer_toilet_2
color_temp: {{ state_attr("light.outer_lounge_sofa","color_temp") }}
{% elif is_state("light.outer_lounge_sofa","on") and state_attr("light.outer_lounge_sofa","rgb_color") != None %}
entity_id:
- light.outer_toilet_1
- light.outer_toilet_2
rgb_color: {{ state_attr("light.outer_lounge_sofa","rgb_color") }}
{% endif %}
however I haven’t figured out a way to encapsulate entity_id or rgb_color inside a template.
Any help much appreciated!