Automation condition time and sun

I tried every combination, but it won’t work…
I want if the light’s are off, but only at night, to turn on the lights if the motion sensor detects.

Here is my automations.yaml

- id: tuinlichtPIR
  alias: Tuinlicht aan bij beweging in poort
  trigger:
    - platform: state
      entity_id: binary_sensor.pir_poort_1
      to: 'on'
  condition:
    condition: and
    conditions:
      - condition: time
        after: '19:00:00'
      - condition: sun  
        before: sunrise
  action:
    service: switch.turn_on
    entity_id: switch.rfx_tuinlicht

When I change the condition to:

  condition: time
  after: '19:00:00' 

then it works, but when I try to make the combination with the sun, nothing.

Any ideas to help me into the light.

In what part of the world does the sun rise after 7pm?

The Netherlands? :wink: No, but I want the lights to switch on, after 19:00. And before sunrise.
How should I do that??

I changed the

before: sunrise 

to

after: sunrise

Then the lights will turn on at motion. Should I see the time window only from 0:00 till 23:59? Or what am I doing wrong?

Change the and to or.

(and put it back to before sunrise)

That works! Thanks.

But I not sure if I understand how it works. I just read that the time can be: after 19:00 untill before 5:00. (So during the night)
Is: “before sunrise” the same as: 00:00 untill sunrise?

Exactly that :+1:

Thanks!

Starting to understand the system. :grinning:

1 Like

so, when:
Next Sun Rise 6:39
Next Sun Set 18:35

condition:
condition: or
conditions:
- condition: sun
after: sunset
after_offset: “-01:00:00”
- condition: sun
before: sunrise
after_offset: “01:00:00”

its works from 17:35 to 7:39am ?

i thinking about turn on lights in the night on motion:

  • id: led on
    alias: led on
    trigger:
    • entity_id: binary_sensor.motion_sensor_1xxxx
      from: ‘off’
      platform: state
      to: ‘on’
      condition:
      condition: or
      conditions:
      - condition: sun
      after: sunset
      after_offset: “-01:00:00”
      - condition: sun
      before: sunrise
      after_offset: “01:00:00”
      action:
    • data: {}
      entity_id: switch.espurna_9xxx
      service: homeassistant.turn_on
- id: tuinlichtPIR
  alias: Tuinlicht aan bij beweging in poort
  trigger:
    - platform: state
      entity_id: binary_sensor.pir_poort_1
      to: 'on'
  condition:
    condition: or
    conditions:
      - condition: time
        after: '19:00:00'
      - condition: sun  
        before: sunrise
  action:
    service: switch.turn_on
    entity_id: switch.rfx_tuinlicht

This works for me.