have been weeks that I can not find the right configuration my idea is as follows: turn on the lights after sunset keep them on until 11pm and then turn on by PIR until 04:00 am.
this is the current configuration, which at this moment the lights come on regularly after sunset but remain on without the other automations intervening. is anyone so kind to help me?
- alias: 'Luci strada sera accese'
trigger:
platform: sun
event: sunset
offset: "-00:30:00"
condition:
condition: and
conditions:
- condition: time
before: '22:59:59'
action:
- service: homeassistant.turn_on
entity_id: "switch.luci_giardino"
- alias: 'Luci strada notte'
trigger:
platform: state
entity_id: binary_sensor.motion
to: 'on'
condition:
condition: and
conditions:
- condition: time
after: '23:00:00'
before: '03:00:00'
action:
- service: homeassistant.turn_on
entity_id: "switch.luci_giardino"
- delay:
seconds: 120
- service: homeassistant.turn_off
entity_id: "switch.luci_giardino"
Why are you using an and condition when you don’t have 2 conditions? I’m removing your and condition because it’s pointless and may be causing problems for you.
Also, you don’t really need the condition for turning on because 30 minutes after sunset should always be before 11 pm. Unless you live at the top of Sweden or something. I’ll leave the condition in, but if you live in an area where the sunset is always before 11 pm, then you don’t need the condition in the 'Luci strada sera accese' automation.
Next, you need to turn them off in order to turn them on by PIR. So at 11 pm, they need to shut off, otherwise they will stay on until PIR is triggered, so in theory, they could stay on all night if nothing moves.
lastly, you have all your entity_id’s in quotes. You don’t need to do that. I don’t think it hurts or helps your config, either way, I removed the quotes.
- alias: 'Luci strada sera accese'
trigger:
- platform: sun
event: sunset
offset: "-00:30:00"
condition:
- condition: time
before: '22:59:59'
action:
- service: homeassistant.turn_on
entity_id: switch.luci_giardino
- alias: 'turn off lights at 11pm'
trigger:
- platform: time
at: '23:00:00'
action:
- service: homeassistant.turn_off
entity_id: switch.luci_giardino
- alias: 'Luci strada notte'
trigger:
- platform: state
entity_id: binary_sensor.motion
to: 'on'
condition:
- condition: time
after: '23:00:00'
before: '04:00:00'
action:
- service: homeassistant.turn_on
entity_id: switch.luci_giardino
- delay:
seconds: 120
- service: homeassistant.turn_off
entity_id: switch.luci_giardino
it works, really thank you very much for dedicating your time and expertise to me. I thought about putting two conditions because I believed that the first condition was the sunset the second condition the time. I will study the logic that you used for future projects thanks again.