This might be a bleedingly obvious one but I just haven’t found anything in my search.
Ultimately I’m trying to create a difference between opening a door to leave vs opening a door to enter.
I have a lamp that turns on when the front door opens based on some basic ‘sunset’ conditions. But of course it will turn on when I leave at night also.
Id like to use my Xiaomi motion sensor to help simulate the difference between entry and exit. i.e, if there was motion in my living room within 1 minute of opening the door, then I’m mostly likely exiting and don’t want the lamp to turn on.
So, is there was a way I can call a condition for say: sensor state was ‘on’ (motion detected) within 1 minute ago? May also turn if the sensor state was ‘off’ for less than 1 minute?
@Bob_NL I’ve been trying to get this sucker up and running but it keeps throwing me errors:
ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/automations.yaml”, line 69, column 9
expected , but found ‘’
in “/config/automations.yaml”, line 70, column 91
I’ve tried changing ‘/’’ etc but no tangible dice.
Here is my code back to how you suggested it:
- alias: dusk_entry_lamp
trigger:
platform: state
entity_id: binary_sensor.door_window_sensor_158d0001ad5593
to: 'on'
condition:
condition: and
conditions:
- condition: sun
after: 'sunset'
after_offset: '-01:15:00'
- condition: state
entity_id: media_player.tv
state: 'off'
- condition: template
value_template: "{{ states.binary_sensor.motion_sensor_158d0001ad4b4a.attributes['No motion since'] > "60" }}"
action:
service: homeassistant.turn_on
entity_id: switch.plug_158d0001dca301
Line 69 is condition template
Line 70 is value template
(my indenting may not be perfect with this embedded code)
I feel like this is might be a simple formatting error?
Your errors are with the value template and the quotes being used. If you open it with " then you have to use ’ inside the expression otherwise it gets confused.
Seems to be working as I’d hoped but I also realised that some of my testing way flawed as the ‘no motion since’ on the dashboard doesn’t update as fast as I’d like sometimes but thats another story
Thankfully my indentation was all good, just poor first use of the code embed in the thread
Hopefully this will help someone else’s search. Here is my now (and hopefully forever) working automation. I’ll check back in if I break it
Intent - If I walk in the front door (Xiaomi door sensor) at dusk or later ~ 1.25 hours before sunset, turn on my lamp (Xiaomi smart plug).
But only we are coming home after a while. This would mean the TV is off. But to make sure its not triggered when I leave the apartment, make sure there has been no motion inside the apartment for at least a minute (which will probably be a little longer by the time it updates on default ping settings).
I’m leaving this unedited so that other people new to the space like me can see all the random digits and sensor names they might recognise in their own setup.
Thank you all for you help. Now onto the next drama
- alias: dusk_entry_lamp
trigger:
platform: state
entity_id: binary_sensor.door_window_sensor_158d0001ad5593
to: 'on'
condition:
condition: and
conditions:
- condition: sun
after: 'sunset'
after_offset: '-01:15:00'
- condition: state
entity_id: media_player.tv
state: 'off'
- condition: template
value_template: "{{ (states.binary_sensor.motion_sensor_158d0001ad4b4a.attributes['No motion since']) | int > 60 }}"
action:
service: homeassistant.turn_on
entity_id: switch.plug_158d0001dca301