This is my third tutorial and I will like to thank @rlkoshak, @will_stewart1a and @mstormi for their valuable input and improvement suggestion. Please leave comments below of how to further improove it!
I believe the term “Presence” takes on multiple levels of scale and granularity, which could be serviced by different techniques. So the first question you should ask yourself what should you use the presence for? Do you need it at all?
I personally use it for 3 things: Light control, Heating and Notification, we will get back to this later, lets first start with some definition:
-
Intra-building: Within a room in a building (e.g, FIND, bluetooth beacon,camera, or similar).
-
On Premises: Inside or within a very short distance of a building or other finite location (e.g, geofence of 7 to 50 meters from building/location boundary, depending on location ‘footprint’ and urban/suburban/exurban density considerations). Phone WIFI presence could work here.
-
Near Premises: Within some end user definable distance as ‘near’, in order to identify when a person is approaching/leaving home for purposes of HVAC control, outside light control, setting security system mode, etc. There could be multiple geofences of differing distances for different purposes (as HVAC control may need more time to ramp up, as one example) 0.5 to 3 kms might be such example distances, with the aforementioned urban/suburban/exurban considerations. Owntracks1 or other solutions could work here
-
Away: Anything considered beyond ‘Near Premises’.
-
Timeliness is another important aspect, as different User Stories have differing needs. Knowing the presence of a person with respect to whole house HVAC or security mode settings only requires knowing within a 10-20 seconds that a person has entered or exited a Near Premises geofence. Intra-building movement events for Lighting or ‘following’ music, as two examples, would be expected to react below 1 seconds. Near Premises events for heating needs to be known at least 20 minutes before.
Hence, “Presence” can be realized with a combination of techniques, tailored to the specific circumstances and objectives. This is how I do it:
I have a switch item called Presence_Home
which expires every 20 minutes. 20 minutes needs to be slightly larger than the update rate of any of your sensors.
The easy part is to detect if you are sure you are at home, the tricky part is to find out that absolutely no one is at home! (Guest might sleep and you went to work, you dont want them to wake up 3 hours later to a freezing cold flat do you?, because presence assumed since your phone left the premises that no one is home…)
Lets make a list of items that triggers that you are home:
-
Phone
I do have phone, fitbit, so does my girlfriend, however I can not expect all guest to have so, So after using OH for 3 years I actually removed the phone from presence detection at home , however I would recommend using the phones bluetooth and wifi if you can set static IP to your device in your router(I can not sadly…) -
Light switches Everytime light switch are pressed send
Presence_Home.sendCommand(ON)
-
Voice control Everytime Alexa/Google Home etc receives a command
Presence_Home.sendCommand(ON)
-
Noise control Everytime noise level above 40dB detected send
Presence_Home.sendCommand(ON)
Nice when watching a movie!
-
CO2 level Everytime CO2 level is above 500ppm send
Presence_Home.sendCommand(ON)
Only way to detect that someone is sleeping as far as I know…
Recomended values:
What are safe levels of CO and CO2 in rooms?
CO2
250-350ppm Normal background concentration in outdoor ambient air
350-1,000ppm Concentrations typical of occupied indoor spaces with good air exchange
1,000-2,000ppm Complaints of drowsiness and poor air.
2,000-5,000 ppm Headaches, sleepiness and stagnant, stale, stuffy air. Poor concentration, loss of attention, increased heart rate and slight nausea may also be present.
5,000 Workplace exposure limit (as 8-hour TWA) in most jurisdictions.
>40,000 ppm Exposure may lead to serious oxygen deprivation resulting in permanent brain damage, coma, even death.
CO
9 ppm CO Max prolonged exposure (ASHRAE standard)
35 ppm CO Max exposure for 8 hour work day (OSHA)
800 ppm CO Death within 2 to 3 hours
12,800 ppm CO Death within 1 to 3 minutes
-
Camera On every detection send
Presence_Home.sendCommand(ON)
Only way to detect that guest are at your place.
Usage:
-
Workmode for heating So what I do is to check if Presence_Home changed to OFF and time of day is morning i changed timeofday to work and that triggers my heating rule.
-
Holiday mode Then I also have our calendar events, when this gets triggered I checked if presence is off and if so I activate holiday mode. (It happens that weekends trips get cancel and I forget to update my calendar
)
-
Leaving work, on way home?? I use geofence on my phone to detect when I leave work, if this is before time of day afternoon(15.30) I will settime of day to afternoon, then if no presence detected within 20 minutes it willl go back to work(Like I had a job meeting, or went somewhere after work etc…)
-
Guest over In addition I do also have netamo welcome camera to detect if guest are over(activate heating in guest room), lower the whisky bar when my dad arrives, etc…
-
Notifications I only get notifications if I(facial recognition) or my GF is home( or both of us if we are both home) home and time of day is either day or evening for such as watering plants, change batteries etc…
IMPLEMENTATION IN OpenHAB
So this works pretty sweet for me… I currently have no need to know that I am in a certain room. This is how it looks like:
My .item file :
Switch Presence_Kim "Kim" (Group_MyOpenhab)
Switch Presence_Yulia "Yulia" (Group_MyOpenhab)
Switch Presence_Family "Family" (Group_MyOpenhab)
Switch Presence_Guest "Guests" (Group_MyOpenhab)
Switch Presence_Home "Somebody is at home" (Group_MyOpenhab) {expire="25m,command=OFF" }
Switch Precense_Intruders "Someone uknown is home" (Group_MyOpenhab)
//Camera netatmo.items i.e Switch Welcome_Yulia_Home "Person [%s]" {netatmo="camera=sdgadsgdsagasdghb#dfhgfdhdfhdfhdfh#OutOfSight"}
//Switches contact.items i.e Contact Contact_BathroomL {gpio="pin:24 debounce:0 activelow:yes"}//SW3
Switch Location_Leaving_Work_Kim "Kim is Leaving work" (Group_MyOpenhab)
Switch Location_Arriving_Home_Kim "Kim arrived home" (Group_MyOpenhab)
Switch Location_Leaving_Home_Kim "Kim left home" (Group_MyOpenhab)
//Phones
Switch Mobile_Wlan_Kim "Cell Kim" <network> {channel="network:device:phone_kim:online"}
DateTime Kim_LastSeen "Kim Last seen" <network> {channel="network:device:phone_kim:lastseen"}
DateTime Presence_Home_LastUpdate "[%1$tm/%1$td %1$tH:%1$tM]"
Switch Mobile_Wlan_Yulia "Cell Yulia"
//String UnknownDevices "Unknown Devices in Range: [%s]" { bluetooth="?" }
//Number NoOfPairedDevices "Paired Devices in Range: [%d]" { bluetooth="!" }
and my rules :
rule "Noise Level"
when
Item Netatmo_Indoor_Noise received update
then
if (Netatmo_Indoor_Noise.state>35.0){
Presence_Home.sendCommand(ON)
}
end
rule "Sensor update"
when
Item Presence_Home received update
then
Presence_Home_LastUpdate.postUpdate( new DateTimeType() )
//if (vWorkMode.state.toUpperCase()="GUESTS"){
//if now - last uknown seen > 2h and (vTimeOfDay.state.toUpperCase()="EVENING" or vTimeOfDay.state.toUpperCase()="NIGHT" {
// vWorkMode.sendCommand("NORMAL")
//}
//}
end
rule "CO2 update"
when
Item Group_Max_CO2 received update
then
if (Group_Max_CO2.state<600){
Presence_Home.sendCommand(OFF)
}
end
rule "Camera update"
when
Item Group_Camera_Person_Home changed from OFF to ON
then
Presence_Home.sendCommand(ON)
end
rule "Camera unknown update"
when
Item Group_Camera_Unknown_Home changed from OFF to ON
then
Presence_Home.sendCommand(ON)
// if workMode=holiday then sendEmail("intruders")
//if workMode="Normal" and timeOfDay = evening or imeOfDay = "NIGHT" {
// workMode = "GUEST"
//}
end
BOTTOM LINE
The main point is that everyone needs to look at their unique situation and choose sensors that make sense for their family and house. Often dealing with pets is something that gets forgotten until the cat starts triggering the intrusion alarm in the middle of the night because the PIR’s are too sensitive. Also you need to calibrate and fine tune the levels for your application. Next tutorial will be about timing events and notifications.
Some further reading suggestions:
Wills tutorial
Markus tutorial on FIND
Rich’s Tutorial