Leaving home wall switch - Here is my idea

Tags: #<Tag:0x00007f1b943d4170> #<Tag:0x00007f1b93d37358>


This is to cover the “returning home” functionality. That’s easier. Many ways to reliably detect if someone is home. I’m talking about a reliable way to tell if noone is home.


Hi! I am using ble keychain with room-assistant installed on rpi3 located near to the entrance and bunch of automation based on presence detectors in the rooms. When we go out we take keys with us and family group becomes not_home status. Works quite reliable almost two years for me. For emergency and maintenance tasks there is zigbee button which turns off all home/away automation, turns away cameras and marks us home.
For visual identification I use wall mounted tablet with fully kiosk browser - it lights up when seeing or hearing someone. Here in lovelace picture entity card turning color from b/w when family member arriving.
Hope this (or part of it) might help:)


how did you do the bluetooth presence detection ?
with iBeacon in hass and specific hardware for bluetooth ? or other ?


We always have bluetooth enabled on our phones. I just use the basic bluetooth tracker and the basic bluetooth capability of the pi. Our house is not huge, but it is two floors plus a basement and my pi is centrally located, so it seems to cover things pretty well.

        - platform: bluetooth_tracker

This will start populating the known_devices.yaml file with devices as they are discovered. You can edit/manage this file to change the icons, and tracking status, etc.

  hide_if_away: false
  mac: BT_FC:12:34:56:78:90
  name: Me
  picture: /local/snowman.png
  track: true


Why wifi is a drawback?? I use wifi for everything that is possible


I’m using wifi presence detection via my router (ddwrt) for my self and my wife - it works flawlessly for the last few months since i set it up.
With this, I can automatically shut off heating etc. when nobody is home.


Somehow I consider WiFi slow and energy consuming compared to zwave band zigbee. I might be wrong.


Energy consuming perhaps but that I will take. Slow, not my setup. And a solid network that zwave never come close to. For me it has never been a question. I trust my system to just work and keep me secure. Thats why a Pi has never been an option. The cost if I compare to a “pro” system is minimal. I will say that I use mqtt as much as possible to speed things up.


For me, tracking based on WiFi is a non-starter because I typically have it turned off on my phone unless I explicitly need it, so it is never on when I first arrive home. Bluetooth, however, is always on for connections to my watch and car.


Well I dont use any tracking so you can be right. But I use wifi for as much devices I can find. Switches, bulbs, ac smoke alarm, temperature sensors etc. Works perfect for me


mine is in a rack cabinet so a bad cover but i will try

mine iphone is already in known_devices (i think it’s because i use the tracking in home assistant for ios ), so I’m afraid there is confusion between ios component detection and bluetooth detection, because entity_id will be device_tracker.iphone1 in both case ???
how do you manade your “bluetooth zone” or that fact that your device is detected by the bluetooth
i will try that.


I don’t want to ruin your discussion, but my original question was about reliable “leaving home” detection. “Coming home” detection is easy.


I have implemented someting similar to what you are looking at. We have a large kitchen, living room, dining room area and I have one z-wave switch near the exit that triggers a NodeRed flow to turn off all the lights, radio, TV & amp (via Harmony) and drop the heating temperature.
It’s a standard Schneider UK style light switch, but it’s spring loaded so we just give it a quick flick when we are going to bed. I also have another one at the front door that triggers the same flow and also turns off most of the other lights in the house when we are going out.
Overall, this works well, and had been very reliable except when someone presses it by mistake and plunges us into darkness and turs off the TV at a critical moment!

I’m in the process of setting up presence detection using BLE, but that is not so urgent now.

Regarding the Z-Wave / Wi-Fi debate, I use both - an Aeotec Z-Stick and Ubiquiti units scattered around the house. It’s a three story house with concrete walls and floors on the ground and first floor, but the Z-Wave mesh has no problems reaching from the ground floor to the top of the house or out into the back garden. The Wi-Fi also works well, but is slightly less reliable and I occasionally have to restart devices that have disconnected.


in my opinion there is two way:

  • a physical button (xiaomi switch is probably the less expensive) who launch a script exit/enter home is a solution but you always need to make an action by clicking the button
  • a detection based on … geolocalisation of your smartphone, bluetooth detection for your smartphone, wifi detection of your smartphone, you don’t need to do any manual interaction, you just need to have your phone with you.

personally i like the detection because no manual action, … i keep manual action for my home alarm who is not connected for security reason.

there is really many many possibilities, and there is not really one who is better than all other, but actually, i like the idea of dap35 to use ios geoloc detection and bluetooth detection.

if you really need to be sure that it will work, you can also make both, a physical switch, and if you forgot to push on it, a automation with zone detecction


Two of our iPhones have the iOS app installed, so they use GPS based location to determine home/not_home status. I didn’t have to set up any zone definition for those. I believe it is using the location settings (latitude/longitude) in your configuration.yaml file.

Bluetooth is really a single zone, since the pi can either ‘see’ a device, or not. Either way, you should see a device_tracker. entry for each device you are tracking show up in the states < > page of the UI.


I have an unique setup : I use Xiaomi door sensor with one part on my key and the other part on key holder.
When I’m at home, I always put back the key in the key holder so that the two part of the Xiaomi door sensor are connected. ( I’ve made a custom key holder from some Lego parts).
When I leave the apartment, I take out the key from the key holder which made the Xiaomi door sensor to be open.
All my home/away automation are based on the Xiaomi door sensor state.
I’ve the same set-up on my wife key with a second door sensor and as long as we put our key in our spot it works perfectly to know who is home or not.


Brilliant! Just brilliant!


That’s great, but you need to train your wife, try that with millenial children.

Don’t forget, you don’t have to use just one detection method. You can combine them with a bayesian sensor. See https://diyfuturism.com/index.php/2017/11/26/presence-detection-with-home-assistant-bayesian-probability/ for an example.


That’s a good idea.
And in combination with that, generally on xiaomi device you have a state attributes who give you the battery level, … interesting to charge battery when they are too low.


Didn’t know that before, but really interesting to simplify scripts and automation, in place of testing each tracker, you can for exemple create a bayesian sensor “someone at home” who combine all smartphone of family (and key holder or other), and test only this sensor in scripts and automation.