×
Recipes Smarthome

Smarthome | Jun 10, 2020

OpenHAB Presence Detection without Network Binding

OpenHAB presence detection with Android App

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.

Why Network Binding may not help?

  • Network Binding cannot be implemented when your OpenHAB installation is not running in the local network (For example: OpenHAB is on a Cloud server)
  • Network Binding is hard to implement when your house has multiple local networks. (For example: house has multiple Wi-Fi hotspots with different SSIDs)

How to implement OpenHAB Presence Detection without network binding?

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

Your email address will not be published. Required fields are marked *