Hi Everyone,
So I’ve been re-jigging my automations for the last day or so ever since I changed presence to a binary_sensor and my wife ended up waking me up at 3AM telling me the lights were turning on automatically in the middle of the night
So rather than putting time delays into my presence detection, I thought I’d try a different method by introducing time checks into the automations themselves. I decided to try small and go from there:
- alias: Home-Lights Auto-On (1800-2000)
trigger:
- platform: state
entity_id: input_select.chris_status_dropdown
to: 'Home'
- platform: state
entity_id: input_select.chris_status_dropdown
to: 'Home'
condition:
condition: and
conditions:
- condition: time
after: '18:00:00'
before: '20:00:00'
- condition: or
conditions:
- condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.binary_sensor.chris_presence.last_changed) | int > 60 }}'
- condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.binary_sensor.val_presence.last_changed) | int > 60 }}'
action:
- service: light.turn_on
entity_id: light.kitchen_table, light.living_room_east_lamp, light.living_room_west_lamp
So if I understand this correctly, it should work this way:
- If my (or my wife’s) status changes to ‘Home’
- It’s between 6 and 8pm
- If the last_update for the binary_sensor the tracks hers and my presence fired at least 60 seconds from the time this automation runs
Then run the automation.
Am I understanding this correctly? Been fighting presence detection and automations firing based on it for the last 24 hours and I’m close to giving up and using someone elses procedure for it but I think I’m doing the right thing here based on the following criteria:
- My wife and I have cellphones with Owntracks installed, a “Home” location setup & shared (HASS sees this as a known_device)
- We both have a BLE Tile which using @Bit-River’s BLE python script, checks every 3 seconds for presence of Tile
- A nmap scan of my entire local network, 192.168.1.0/24
My presence detection works like so (based on @philhawthorne presence-not-so-binary article which you can find here: https://pastebin.com/UuPL8dUL
(I copied out the relevant sections…)
Hoping someone can spot something or give me some pointers on this and also clarify I understand the logic in the above automation in this post as I think I do.
-Chris