Smarthome | Jun 10, 2020
Presence detection is mandatory for a Smart Home to act smarter. Presence of each member can help to determine how the routines should work with and without family members.
OpenHAB usual way of presence detection requires the network binding. Why network binding is not practical always is because when your OpenHAB installation is in cloud and when it does not have a local IP, there is no easy way to implement it.
For this purpose, OpenHAB Android app is required. Now OpenHAB Android app’s Send device information to server option can be used to send the user’s connected network information to OpenHAB server. This is available in Settings, under Miscellaneous.
In the section Schedule based, it is possible to send the device Battery level, Charging state, Wi-Fi name and DND mode (do not disturb). Therefore, all to be done is to define these as items in OpenHAB for each house member and write the rules.
First add the items to people.items file.
String person_alex "Alex [%s]" <boy>
String person_alex_wifi "Connected to [%s]" <none>
String person_alex_call "Call state [%s]" <none>
Number person_alex_battery "Battery [%d %%]" <none>
String person_alex_power_state "Charging state [%s]" <none>
String person_alex_dnd "Do not disturb [%s]" <none>
DateTime person_alex_update "Last update [%1$tb-%1$te %1$tH:%1$tM:%1$tS]" <none>
Then write a rule to check the presense by looking into your Wi-Fi SSID. To make this work your home Wi-Fi SSID should not be a common one. It should be unique for your home.
rule "people_alex"
when
Item person_alex_wifi received update
then
if (person_alex_wifi.state == "My WiFi SSID 1" || person_alex_wifi.state == "My WiFi SSID 2") {
person_alex.postUpdate("IN")
person_alex_update.postUpdate(now.toString)
}
else {
person_alex.postUpdate("OUT")
person_alex_update.postUpdate(now.toString)
}
end
The rule checks if your Wi-Fi SSID is My WiFi SSID 1 or My WiFi SSID 2. If it is OpenHAB will update person_alex as IN. If not person_alex will be marked as OUT. You can extend this to detect if you are at work or a friend’s place too.
Leave a Reply