I have a KaKu motion sensor that need to enable a light when there is motion after sunset and before sunrise. After a minute the lamp needs to go off again.
The automation is working properly but only when I don’t have the sun condition configured.
For some reason the sun condition is not working although my home assistent shows the state of sun properly. What is going wrong?
This is my current code:
alias: Light on Motion Hall Upstairs
trigger:
- platform: state
from: 'off'
to: 'on'
entity_id: binary_sensor.kaku_motion_sensor_hall_upstairs
condition:
- condition: and
conditions:
- condition: sun
before: sunrise
after: sunset
action:
- service: light.turn_on
target:
entity_id:
- light.kaku_dimmer_hall_upstairs
- light.kaku_dimmer_hall_downstairs
data:
brightness_pct: 67
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- service: light.turn_off
target:
entity_id:
- light.kaku_dimmer_hall_upstairs
- light.kaku_dimmer_hall_downstairs
mode: single
I first had it without the AND condition but that wasn’t working either. Any ideas?
I’m in agreement with 123 Taras here. I believe that sun currently wraps around to the next day so you actually can do after sunset and before sunrise, but that always triggers my “maybe not” worrier. The below horizon takes care of that ambiguity.
This sunrise/sunset conditional error occurs fairly often. It’s natural to assume one must logically AND the two conditions, only because most people are unaware of how “midnight” is handled (serves as a dividing line).
The documentation attempts to clarify it in the section’s second paragraph but the accompanying YAML example doesn’t appear immediately after the paragraph but at the very end of the section.
Anyway, if the goal is to simply make the condition confirm it’s between sunset and sunrise, then it’s easier to use a State Condition that looks for below_horizon.
Nevertheless, this is what Home Assistant is suggesting when you select Sun as the Condition Type.
It then should better not be possible to select it, to prevent one to be led to confusions.
The automation editor doesn’t make any suggestions, it just shows the items which can be configured. I think it is unwanted to not allow certain configurations because some users expect it to work differently while it can still be useful for others.
Anyway it doesn’t make sense to post these comments in a topic which is solved. Better keep these topics “clean” and make a feature request if you think things should be done differently.
That works perfectly fine, but it’s a recent addition to the code. Your issue is somewhere else.
Instead of bashing people you don’t know, how about you create a separate post with a question? This isn’t a video game forum and posts like this will not be tolerated.
condition: <-- this is needed apparently
condition: or
conditions:
- condition: sun
after: sunset
after_offset: '-01:00:00'
- condition: sun
before: sunrise
before_offset: '01:00:00'