Hi,
I have created with some search and c&p an automation for my lights depending on motion detection and the sun state. The automation works, but has one problem.
If the light turn on at sun blow_horizon (especial early in the morning) and the sun rise is also over the horizon the light doesn’t turn off.
Can someone give me a suggestion how can I solve this? Also at sunset, I want to turn the lights on 30min before the sun is below the horizon, but I can’t set a negative vale -30min or so.
My personal solution for a similar problem was to create an input_boolean helper with automations that follow its state to control the light, with another automation that watches the input_boolean for being on for the desired time period and then flips it (the input-boolean that controls the light) off. I have it set to turn the outside light on for five minutes when the dog lets himself out at night, with an added benefit that the turn-off timer doesn’t reset when he comes back inside or walks past the dog door and triggers the lights-on automation a second time…
My understanding is that you want the light to turn on at motion, but only when the sun is down, is that correct?
in that case: the below should work:
The trigger is any state change of your motion sensor, but it will only work when the sun is below the horizon. (I’ve removed the condition of 1 minute of sunset as I believe that would prevent it from triggering at any longer time the sun was down).
When trigger and condition are true, then it chooses between:
If motion is ‘on’ and light is ‘off’ → turn light on
If motion is ‘off’ for 1 minute and light is ‘on’ → turn light off
Just a curious question, lets say you just use the turn on light, how long time will your motion detector take before “detecting” again ?
I have 4 Aqara motion detector, Default seems to be ca 60 seconds ( Detecting intervals)
which made me use 2 simple short automation ( for 2 of them )
Trigger = Motion-Detected > Sun_below Horizon> Turn on light
Trigger =No-Motion-Detected> Turn of Light
Which gives me time, to go to Bed, (as long as im moving around, there is light, 1min under the blanket, Lights turn of , … and another Room, primarily a walk through Area, same “automation”, moving around lights are on, out of area, light turns of while “no motion detected” after Default 1min) … Don’t complicate a simple function
Since you asked a question about my sun2 custom integration in relation to this topic, I thought I’d share my thoughts here.
I generally agree with @tom_l’s solution, although I see two problems with it.
First, I don’t think it will work for turning the light off, because it has a condition that the sensor should have been off for a minute, which it can’t be when it has just turned off (i.e., triggered by going off.)
Second, it doesn’t address your question about how to include the 30 minutes that precede sunset.
Before I give my suggested solution, I’ll comment (like I think maybe others already have), that you should probably use the sun’s elevation as opposed to time-based offsets from sunrise/sunset, since the rate at which the sun rises and falls changes throughout the year.
Anyway, here’s what I’d suggest:
- id: '1643474163000'
alias: Licht Schlafzimmer nach Sonnenuntergang
description: ''
trigger:
- platform: state
entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_429fd407_ias_zone
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_429fd407_ias_zone
from: 'on'
to: 'off'
for:
hours: 0
minutes: 1
seconds: 10
action:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_429fd407_ias_zone
state: 'on'
- condition: state
entity_id: light.blitzwolf_decke
state: 'off'
- condition: or
conditions:
- condition: sun
before: sunrise
# The following means after 30 minutes before sunset.
- condition: sun
after: sunset
after_offset: "-00:30:00"
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.blitzwolf_decke
- conditions:
- condition: state
entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_429fd407_ias_zone
state: 'off'
- condition: state
entity_id: light.blitzwolf_decke
state: 'on'
sequence:
- service: light.turn_off
data: {}
target:
entity_id: light.blitzwolf_decke
Your way works. It seems that I had an understanding issue with the sunset. I have thought every day has only one sunset with a specific time, so in my opinion it only works one times a day