Hello all,
I have a problem with an automation which has 2 usecases:
- Trigger light on when i’m home after sunset.
- Trigger lights on when i’m coming home after sunset.
I have a template condition set that demands that the last_changes state is not changed for the last 15 minutes.
This is to prevent false triggers (i use netgear tracking and once in a while it says i’m not home when i actually am and otherwise).
Now the first usecase is working, but the second one is not.
The template condition is returning false and I think this is because i’m coming home and the person state changes, and then the template condition uses that as last_changed, so that’s well within the 15 minutes offcourse, so it doesn’t get triggered.
I think what i want is a template condition that says that my previous state was in that state for 15 minutes, but I don’t know how to do that.
Any help is really appreciated.
This is my automation code:
id: lightsOnSunset15
alias: Lights on 15 minutes before sunset
trigger:
- platform: state
entity_id: person.owner
to: home
- platform: sun
event: sunset
offset: '-00:15:00'
condition:
- condition: state
entity_id: person.owner
state: home
- condition: template
value_template: >-
{{ as_timestamp(states.person.owner.last_changed) + 900 < as_timestamp(now()) }}
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: '-00:15:00'
- condition: sun
before: sunrise
before_offset: '+01:00:00'
action:
- service: homeassistant.turn_on
entity_id: light.light