hello to all
is there anyway to transform the following automation in only one single automation?
thanks
- id: AmbilighOn
alias: Ligar Ambilight
trigger:
platform: state
entity_id: media_player.tv_da_sala
to: 'on'
condition:
condition: time
after: '20:00:00'
#evoluir para estores fechados
action:
service: light.turn_on
entity_id: light.yeelight_color2_04cf8c842ee1
- id: AmbilighOFF
#evoluir para se estores abertos
alias: Desligar Ambilight
trigger:
platform: state
entity_id: media_player.tv_da_sala
to: 'off'
action:
service: light.turn_off
entity_id: light.yeelight_color2_04cf8c842ee1
tom_l
May 7, 2019, 12:19pm
2
Sure it’s possible but it would complicate things and possibly make them difficult to understand. One automation isn’t always better than two.
- id: AmbilightControle
alias: "Ao Controle Ambilight" ## Apologies if Google Translate mangled that.
trigger:
platform: state
entity_id: media_player.tv_da_sala
condition:
condition: or
conditions:
- condition: time
after: '20:00:00'
- conditon: template
value_template: "{{ trigger.to_state.state == 'off' }}"
action:
service_template: >
{% if trigger.to_state.state == 'on' %}
light.turn_on
{% else %}
light.turn_off
entity_id: light.yeelight_color2_04cf8c842ee1
1 Like
tom_l:
id: AmbilightControle alias: “Ao Controle Ambilight” ## Apologies if Google Translate mangled that. trigger: platform: state entity_id: media_player.tv_da_sala condition: condition: or conditions: - condition: time after: ‘20:00:00’ - conditon: template value_template: “{{ trigger.to_state.state == ‘off’ }}” action: service_template: > {% if trigger.to_state.state == ‘on’ %} light.turn_on {% else %} light.turn_off entity_id: light.yeelight_color2_04cf8c842ee1
thanks a lot
i will try it
well it gives me the following errror
missed comma between flow collection entries at line 262, column 6:
{% if trigger.to_state.state == ’ …
^
tom_l
May 7, 2019, 10:16pm
5
This is what I mean about complicating things. It was a fairly simple mistake but you were unable to spot it. Copying code from helpful people on the forum isn’t any good if you don’t understand it. Later on if something changes in your set up, are you going to be able to fix it?
You could have done if you kept the simpler two automation method of accomplishing this task.
action:
service_template: >
{% if trigger.to_state.state == 'on' }}
light.turn_on
{% else %}
light.turn_off
{% endif %}
entity_id: light.yeelight_color2_04cf8c842ee1
One thing to note is that this will switch the light off if the media player becomes any state other than ‘on’ after 8pm. e.g. ‘unavailable’.
1 Like