Presence tutorial - my implementation

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:

  1. 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…)

  2. Light switches Everytime light switch are pressed send Presence_Home.sendCommand(ON)

  3. Voice control Everytime Alexa/Google Home etc receives a command Presence_Home.sendCommand(ON)

  4. Noise control Everytime noise level above 40dB detected send Presence_Home.sendCommand(ON) Nice when watching a movie!
    noise

  5. 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…

co2

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
  1. Camera On every detection send Presence_Home.sendCommand(ON) Only way to detect that guest are at your place.

Usage:

  1. 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.

  2. 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 :slight_smile: )

  1. 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…)

  2. 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…

  3. 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

14 Likes

Unless something has changed, Fitbits are one of the few BT devices that do not spoof and rotate their advertised MAC. As a result, they are very well suited for use with reelyActive which can be a nice complement or alternative to FIND.

You can set a static IP on the phone itself though. It’s probably not a best practice but I’ve done that in a pinch in the past. On Android you can do it from the Advanced settings for the wifi AP config (i.e. long press on the ssid and press “Modify” and then you will have an “Advanced” option which will open up the fields where you can enter your IP/NetMask, etc.).

Is this able to distinguish between speaking to your local Alexa/Google Home in the house verses the apps running on your phone?

Probably wouldn’t work for us dog owners. :dog:

Probably wouldn’t work for large breed dog owners. :smiley:

Great writeup! Thanks for contributing!

1 Like

Never checked that, I never uses alexa on my phone for other things then lists :slight_smile:

Do you have the dog in the bedroom? Also maybe you can set the trigger level higher then 500 to eliminate your dog…

Thanks for the nice tutorials, I would like to ask a non-presence-related question for your CO2 sensor
why your co2 sensor goes that high?(I can see it’s higher than 1250ppm), do you use some products to detect human breathing? and may I ask you what product do you use? This is because I have a co2 sensor and it always around 60-180 reading, I never get that high reading(>250) except someone is smoking:) in the room. and why dectect “human-breathing”? I mean, isn’t this type of sensor is always used to detect smoke(like in the kitchen)?

Are you sure you use CO2 sensor and not CO sensor, I use Netatmo sensors, but I know iteead have CO2 sensors as well.

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

The dog has the full run of the house except the room where the cat’s food and litter box lives. We only have a welsh corgi who is around 30 lbs (13.6 Kg) so I doubt that she would would raise it much. But I have many friends and aquaintances with quite large dogs and I would expect them to trigger the CO2 level as many are the same weight as an adult human.

I’ve also two cats who combined might be enough to trigger the CO2.

But my main point is that everyone needs to look at their unique situation and choose sensors that make sense for their family. 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 PIRs are too sensitive.

2 Likes

I have some ideas here, I will think about it over the weekend, but can you lighten me up on the benefit of reely active vs the find/bluetooth/networks bindings?

Face detection of the welcome camera avoids pets!! So far I have had no false detection, but then my goldfishes doesn’t trigger the pir’s…

reelyActive is passive. So rather than turning the phone into a sensor and reporting to some central server like FIND does or requiring a priori knowledge (e.g. network address or BT MAC), you have BT sensors about the space that report the nearness of the devices to the sensor. It is a good choice over FIND if you have iPhones instead of Android (unless Apple will let FIND work on iPhones finally).

It has the advantage over the BT Binding in that you can put the sensors anywhere in your house, not just the one connected to your OH server. And since it will work with Raspberry Pi 0W without extra hardware you can fairly cheaply put the device in all of your rooms and get nearly as accurate intra-home location.

Also, it can work with guests with BT devices because you don’t have to know ahead of time the address of the device. Put another way, you can detect that there is a device in the house without needing to know anything about the device ahead of time. The only requirement on your guests is that they keep their BT turned on.

It does require more devices as sensors in the house and you will need to do a little extra work to process the sensor readings to tell the difference between someone actually in the space versus someone walking their dog past the house but that shouldn’t be too hard. It also cannot uniquely identify specific phones these days because they use random and rapidly changing BT MACs in their BTLE broadcasts. But since FitBit doesn’t do this MAC rotation you can with those devices. It should work with BTLE tiles and the like too.

Do you have any details on the facial recognition stuff? I am a big fan of computer vision and it requires you to not have to have another device on you :slight_smile:

Does all this depend on people actually taking these devices with them? I suppose what I am getting at is that if I left a BT or WiFi device at home (which I often do), the system would assume I’m still home. I believe there is some good write up on using Bayesian Probability across a set of devices to make a final determination.

BTW - it would be good to get it (reely-active) to run on the cheaper esp32 micro-controller or use this:

reelyActive is written Node.js and uses fairly standard messages so it should be possible to port or rewrite that part to run on an ESP32. However, there are a lot of things it depends upon from the OS that may not be available on a microcontroller like the ESP32.

However, at least from Adafruit there is only a $1.05 difference in cost between the ESP32 and RPi Zero W with some of the ESP32s being up to twice as expensive as the RPi Zero W so the cost savings is not that significant as far as I can tell, at least here in the US. I’m sure there are sources that are cheaper but I couldn’t find them in a short search.

Though, the same person has a video that uses an ESP8266 to sniff phone presence based on smart phone’s wifi. Though I suspect the iPhone and newer Android’s going to sleep problem would probably be a problem here as well.

FWIW, FIND3 was released and now can make use of BT, too, in addition to WiFi, of course.
Can’t share any experiences yet, though.

1 Like

The only issue here is placing orders for RPi Zero W, most places limit it to a single one and by the time you factor in the shipping for that one, it is expensive.

Can you gave us an update of your settup? Thsi is really insteresting

Dear mstormi,

imho FIND3 is great! Unfortunately I am not able to use the service in a robust way - lots of times we got 502 Bad Gateway errors on the server https://cloud.internalpositioning.com](https://cloud.internalpositioning.com/ . Does anyone got a solution for that issue?

Best regards,
Jochen

250-350ppm of CO2 can be only in your dreams)))))
Global annual mean CO2 concentration has increased by more than 45% since the start of the Industrial Revolution from 280 ppm during the 10,000 years up to the mid-18th century to 415 ppm as of May 2019.

Moved to new topic

Given the length and the fact that this is describing an alternative approach, this post would be better as the first post in a new thread. You can reference this one. Otherwise I think this good information will get lost and be very hard to find via search.