tiszavolgyi
(Peter Tiszavolgyi)
September 1, 2017, 12:09am
1
Hi,
In the following script I would like to turn on the living_room_lamp only after sunset. I believe if I would change the order and first turn off the avr/projector, after place the condition and after the turn_on lamp then the script would stop if the condition is not right (the sun is up), but I need this order since I do not want to be in a dark room for a moment… So probably the question is how to put a condition inside of the “-service” part in a script.
Thank you in advance!
turn_off_tv:
sequence:
- service: switch.turn_on
entity_id: switch.living_room_lamp
- delay:
seconds: 30
- service: script.turn_on
entity_id:
- script.avr_turn_off
- script.projector_turn_off
- script.projector_screen_up
aetolus
September 1, 2017, 11:52am
2
Sorry, misread you question - let me fix.
Something like this
turn_off_tv:
sequence:
- service_template: >
{% if is_state('sun.sun', 'below_horizon') %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
entity_id: switch.living_room_lamp
- delay:
seconds: 30
- service: script.turn_on
entity_id:
- script.avr_turn_off
- script.projector_turn_off
- script.projector_screen_up
1 Like
tiszavolgyi
(Peter Tiszavolgyi)
September 1, 2017, 2:16pm
3
Thanks a lot! I am not sure why did not I think for templates…
1 Like
tiszavolgyi
(Peter Tiszavolgyi)
September 5, 2017, 11:41pm
4
For some reason it is leading to an invalid configuration and I do not see what can be wrong. Any help would be much appreciated!
This is the code:
turn_off_tv:
sequence:
- service_template: >
{% if is_state('sun.sun', 'below_horizon') %}
switch.turn_on
{% else %}
switch.turn_off
{% end if %}
entity_id: switch.living_room_lamp
- delay:
seconds: 3
- service: script.turn_on
entity_id:
- script.avr_turn_off
- delay:
milliseconds: 200
- service: script.turn_on
entity_id:
- script.projector_turn_off
- delay:
milliseconds: 200
- service: script.turn_on
entity_id:
- script.projector_screen_up
And this is the relevant part of the config validation:
turn_off_tv: [source /home/tiszavolgyi/.homeassistant/scripts/livingroom.yaml:40]
sequence: [source /home/tiszavolgyi/.homeassistant/scripts/livingroom.yaml:41]
- entity_id: switch.living_room_lamp
service_template: {% if is_state('sun.sun', 'below_horizon') %}
switch.turn_on
{% else %}
switch.turn_off
{% end if %}
- delay: [source /home/tiszavolgyi/.homeassistant/scripts/livingroom.yaml:49]
seconds: 3
- entity_id: [source /home/tiszavolgyi/.homeassistant/scripts/livingroom.yaml:52]
- script.avr_turn_off
service: script.turn_on
aetolus
September 7, 2017, 12:32am
5
My fault, I got owned by autocorrect.
It’s probably because of this
{% end if %}
Should be
{% endif %}
tiszavolgyi
(Peter Tiszavolgyi)
September 7, 2017, 11:00pm
6
OMG, thanks, how could I be so lame did not recognize it… Sorry for that and thank you so much!
1 Like
aetolus
September 7, 2017, 11:12pm
7
Haha, no problem. It took me a minute to see it as well!