Hello,
I wrote a simple automation which turn off lights when nobody is in house AND sun is above horizon and it works:
- alias: "Turn off lights"
trigger:
- platform: state
entity_id: XXXXXXX
from: 'home'
to: 'not_home'
action:
- service: light.turn_off
data_template:
entity_id: >-
{% if is_state('sun.sun', 'above_horizon') %}
group.all_lights
{% else %}
light.yeelight_rgb_XXXXXXX
{% endif %}
- delay: 00:00:02
- service: notify.telegram
data:
message: 'all the lights have been turned off'
I added these lines of code but it doesn’t works:
- alias: "Turn off all lights"
trigger:
- platform: state
entity_id: XXXXXXXXX
from: 'home'
to: 'not_home'
action:
- service: light.turn_off
data_template:
entity_id: >-
{% if is_state('sun.sun', 'above_horizon') %}
group.all_lights
{% set msg_txt="'all the lights have been turned off" %}
{% else %}
light.yeelight_rgb_XXXXXX
{% set msg_txt="Turn off only some lights" %}
{% endif %}
- delay: 00:00:02
- service: notify.telegram
data_template:
message: "{{ msg_txt }}"