I have an automation that turns on two different lights an hour before sunset. This automation has two entities in it. For one of the entities if it is after 8pm, I do not want that entity to have its lights turned on. Is there a way to do this?
I belive you’d need to use two separate automations, or node-red.
An action like this should work:
action:
- service: light.turn_on
entity_id: light.foo
- condition: time
before: '20:00:00'
- service: light.turn_on
entity_id: light.bar
Or a little fancier…
action:
- service: light.turn_on
data_template:
entity_id: "{{ 'light.foo, light.bar' if now().hour < 20 else 'light.foo' }}"
1 Like
so would the below incorporate the change needed. switch 2 is the one I want to not turn on if after 8
- alias: Hall Lights - Sunset
trigger:
platform: sun
event: sunset
offset: “-00:30:00”
action:- service: switch.turn_on
data_template:
entity_id: “{{ ‘switch.wenzhou_mtlc_electric_appliances_enerwave_unknown_type_0123_id_0345_switch_3, switch.wenzhou_mtlc_electric_appliances_enerwave_unknown_type_0123_id_0345switch_2’ if now().hour < 20 else ‘switch.wenzhou_mtlc_electric_appliances_enerwave_unknown_type_0123_id_0345_switch_3’ }}”
condition:
condition: time
weekday:- mon
- tue
- wed
- thu
- fri
- sat
- sun
- service: switch.turn_on
I can’t confirm your indentation without you properly formatting the YAML with three backticks (```) above and below the code…but the template looks fine. You can remove the condition at the bottom, that won’t do anything anyway.
thats think out side the box
didn’t think to have a condition in side a action
will have give it a go
1 Like
Thank you for your help
Also you could use a service-template with complex conditions for every individual action.