I am very helpless to get a very simple automation running by configuring it just by clicking.
There is a PIR (motion sensor) installed and the light has to be turned on from sunset to sunrise with a little offset time.
I combined the sunset and sunrise condition with an OR.
First condition “sunset”, second condition “OR” with nested sunrise.
This is the created YAML:
alias: Nachts Küchenlicht an
description: ''
trigger:
- type: motion
platform: device
device_id: 71d03128e2337c0e9f7f4ca0a4eda047
entity_id: binary_sensor.pir_kueche_occupancy
domain: binary_sensor
condition:
- condition: sun
after: sunset
after_offset: '-00:30:00'
- condition: or
conditions:
- condition: sun
before: sunrise
enabled: true
action:
- type: turn_on
device_id: 01358ce094d47f3ef55aba5004e96228
entity_id: switch.kuechenlicht
domain: switch
mode: single
Is this automation working for you? I’m assuming not as you have raised a query…
I use a YAML Time of Day (TOD) binary sensor to determine if it is day or night. They recently added Helpers for TOD to the UI but it cannot take the sun as reference, only time:
- platform: tod
name: Night
after: sunset
before: sunrise
- platform: tod
name: Day
after: sunrise
before: sunset
Anyway, I usually add these sensors as conditions in my automations to determine if its night or day. Hope that helps.
And since you are using ‘sun’ … at some point during the night the sunset changes…so you also have to add a condition to deal with that .e.g alike: time < sunrise && sunset < sunrise
There is no need for that.
The sun only acts on ONE day, so at midnight both sunrise and sunset will change to the current values of that day. In other words sunset can never be earlier than sunrise.
Ah…yes… I made a small mistake when I cam using NEXT_sunrise in one of my automations, thanks for correction
Edit:…or … not… when it is 23:00 the next_sunset is still earlier that day (say 20:00) and a bit later will change to 20:01 the day after where next_sunrise does not change…anyhow just do with this info what you want
Your midnight and the HAOS midnight might not be the same, but the sunrise and sunset will still change at the same time.
I guess it could be an issue, if sunrise or sunset is in that one hour window.
Personally I use a custom component called sun2, that list both yesterdays, todays and tomorrows value, so I have no issues like this.
It works!
Maybe other people have this problem, too.
What to click in the automatisation-page:
Click OR in the first option and then add all the options that you want to have ored.
There are multiple ways to do that, one way is as follows. Below, I am assuming (based on your original post’s condition) that you want the light to come on 1 hour before sunset. If that is not the case and you want it to turn on 1 hour after sunset, remove the negative from the offset value.