Im wondering if i can make a automation for my PIR sensor.
Today i have a automation that "if motion = on " and “Sun = sunset” = turn on lamp
If no motion in 20 min = turn off lamp
But if im in the room before sunset, then the PIR is “on”, and when sunset happend the lamp does not turn on. Can i get the lamp to turn on if motion in my room and sunet is happening?
automation front_motion_lights:
alias: Front motion lights in dark
trigger:
platform: state
entity_id: binary_sensor.outside_motion
state: 'on'
condition:
condition: or
conditions:
- condition: sun
before: sunrise
- condition: sun
after: sunset
action:
service: switch.turn_on
entity_id: switch.outside_lights
In your situation, the “trigger” would be PIR sensor turning to ‘on’ and the condition would be after sunset. Below is an example of the automation:
- alias: Turn on Lights with Motion after sunset
trigger:
platform: state
entity_id: sensor.front_porch_sensor
to: 'on'
condition:
condition: and
conditions:
- condition: sun
after: sunset
action:
- service: switch.turn_on
entity_id: switch.front_porch_light_switch_33_0
To turn it off, you would have a second automation that checks for no motion after 20 minutes:
- alias: Turn off Lights with No Motion after 20 minutes after Sunset
trigger:
platform: state
entity_id: sensor.front_porch_sensor
to: 'off'
for:
minutes: 20
condition:
condition: and
conditions:
- condition: sun
after: sunset
action:
- service: light.turn_off
entity_id: switch.front_porch_light_switch_33_0
I have preferred using a template condition for sun angle. Sometimes it is dark in my house at sunset and I really want lights on before the sun is actually below the horizon.
The above works well and if your trigger is your PIR sensor once the sun is below an angle of 10 degrees (or whatever you choose) it will kick on the light.