Aggregating sensor stats into a single (virtual) device

Does anyone know if there is a homey app that would allow me to aggregate data over time from multiple sensors (throughout my home)? This would allow me to determine whether someone is home or not, in addition to presence detection using mobile devices.

For example I would like to be able to define a single virtual device that is the logical OR of sensor values over the last x minutes where x is a configuration parameter.

Ideas are welcome.

Group on (v2) would allow you to do that, but only for one sensor type at a time.

Ie turn on “motion” if there is motion in the hallway or kitchen. Turn on contact sensor if AnY contact sensors trigger, turn on if most of the doors are open.

Depending on the capability it handles most logical conditions - and,or,not,xor,mean ave, mode ave, median ave, min,max, etc.

Will this do exactly what you want? Perhaps, but I you would then need to create a virtual device with a flow that it turns on if any of the groups capabilities turn on …

I remember @anne about writing an app which would give values based up criteria so you could determine whether someone is home.

@Jamie what you are describing is not really what I am looking for…if you only aggregate over the same moment of time, ie you sample multiple sensors at one moment in time, it will be useable to switch lights etc but will not be useable as presence detection. Think for example of a situation in which multiple people in the house would sit still for 10 mins or so. No motion sensor would be switched on so the aggregated value would also be false or 0.

Therefore I would like to be able to aggregate sensors over time. For example if any of my motion sensors were on in the last 60 mins (or other time interval) then the aggregated sensor should be true.

Do you recall which thread was referring to presence detection using motion sensors?

It was a slack discussion about using Bayesian probability to determine whether or not there was someone ‘home’ and ensuring that users (us) don’t make the critical mistake of confusing presence for a known entity’s presence in regards to home automation security.

ie. Just because there is someone in the house - doesn’t mean that you want to turn off the alarm, sometime it will mean that the alarm should be triggered.

It was on slack, but It is not possible to read the history due to time limitations.


If I wasnt clear, I know of an app which will allow “aggerating sensor stats into a single (virtual) device”. As requested.

This would allow you to determine wheter someone is home by :

Assign values in flows when these are triggered and then remove said values after a delay.

It would be up to you to then use those stats in a flow to determin if someone is home.

I personally would do something like the folllowing, but you could do a much simplier version with simple boolean conditionals.

For example : IF ‘any’ door was opened {Bayesian = + 1} (delay 20 min - Bayesian = - 1} AND all doors open {Bayesian = +3} delay 45 min { Bayesian = -3} ; if motion down stairs { Bayesian = +7} delay 40 min - Bayesian=-7; etc etc etc

And then just a flow - when Bayesian changed and Bayesian > 10 then {someone is home}

I don’t think you will ever get good presence (or occupance) detection based on motion detection alone, integrating more sources of information will probably give better results.

I have started developing an app based on bayesian statistics (https://en.wikipedia.org/wiki/Bayes’_theorem). I am using a node js library which you can ‘train’ with ‘good’ and ‘bad’ datasets (‘good’ and ‘bad’ can be mapped to ‘someone is present’ and ‘no-one is present’). If you then present the library with an actual dataset, it will give you the probability of someone being present or not.

The initial concept is based on a data set containing selected ‘better logic’ variables and the on/off state of devices with onoff capability. The dataset can be expanded to include any binary state. The selection of the variables is important, you do not want any use any devices that are also used for your alarm for instance, or in general variables that can be influenced/manipulated by others (ie. non-family members :wink: ).

Useful BL variables can be ‘high’ or ‘low’ power usage, or things like if your TV or audio system is on (preferably based on the power usage as well, so you know they are being used) which are strong indications someone is at home. I have Homey switch on the mechanical ventilation in the bathroom, which only happens when someone is showering or taking a bath, so that’s a good one as well, and you could perhaps use things like the temperature in the living room and get creative with things like that. And of course sockets being switched on or off, and the presence states as indicated by various apps (Homey presence, Unifi, Tado, smart presence, what have you).

I expect that combining all those variables and training the library on the two states (‘someone present’/‘no-one present’) in various conditions will give good results.

I have a working concept app, it has a button in the mobile interface so you can train the app with different scenario’s. I stopped developing it a while ago as the app requires an elaborate settings page which is quite different on Homey V2 compared to V1. I plan to rewrite one other app before I switch to V2 myself, after that I will probably pick it up. The groups app @Jamie made looks like it may be a good starting point for the settings :slight_smile:

1 Like

@anne @Jamie thanks for the feedback.

@anne interesting subject. Have been thinking about that myself as well. Would be eager to see how your implementation performs. Will keep an eye out for your app…once released for v2.

hi @pim555

I have had this discussion with a few users in the old forum around this.

here is my solution:

I have a couple of motion sensors around the house. they are in major rooms/spots that I frequent in the house. Using a better logic variable, I add a number (+2) to this variable.

This variable has a max of 6 and a min of 0.

Every hour (peak and off peak differs), i deduct (-1 to -2) from this variable.

When my phone or my wife’s phone is connected to the network (using presence app), +1, when we are disconnected, -1

When the variable is below 3, no one is at home. when the variable is above 3, some one is at home.

this variable is then the premise to a lot of things i check or control within the house - to know if someone is at home or not

this is the big picture, i do many other checks and keep fine tuning this variable as we live in the house.

this has worked pretty well for us. I can safely say right now, homey is able to know that no one is at home by the hour mark, so within 60 mins. If 2 of us leave the house together (-4), much shorter.

you get the point

hope this helps.

How about using SETS app. I have a SET for all my sensors and use the ACTIVATE State for X time to activate the sensor STATE in the set and if the conditions of the sets are met, an action happens…
After the preset duration (each sensor has a different countdown time) it with deactivate the state in the set.
Each state change will activate a flow to check the SETs to see which state is active to guess where I am and therefore execute another flow.

Im not using this for presence but rather for my lighting scene. If specific lights and devices are on, it will predict what Im doing and activate the relevant scenes I’ve preset for my place.

Thanks @viix. That is almost what I am looking for. Would be nice if it could calc a diferential over time…

Looking forward to the Bayersian app

All (or at least a lot) of values are available in Insights now. I found this App Aggregate Insights, but seems not to work on Homey 2.1.1

https://apps.athom.com/app/com.insights.aggregate

I am looking for average power (in W) from the past 5 minuts to smother the value, before I switch something on or off.

The app you supplied is for the aggregation of devices (possible now using the group app), not the ‘average’ over time as you seem to require for your solar panels.

The mentioned app is for Homey 1.5, there is non available in Homey 2.0.

Is averaging possible with the group app?

Sorry I don’t know of any app which will average the values of a device over a time period.

Using motion and door sensors for pressence (home/away), its that it? In that case just use flow n logic? its doable

Just place some of the sensors in a correct maner around your entrence so the evaluation ends up correct even if somebody aint moving for some time.

An app for averaging has to have first the condition that the current collected (cloud based) Insights are available for Apps, if these numbers are not available then the App has no use :slight_smile:

Further I tested with the <> app, If I make a group from several Energy sensors, I only get a Total of all Energy sensors. To get an average the choice of period is important, because you don’t want an average of the last year, but probably a choosable period like 1 hour, 12 hours, 30 days, etc. (to make it a general solution and not only for Energy).

Go to more - settings - group. Click on the group you created and change the value from “sum” to average.

I only have the sum, for energy the max, min and averege cannot be choisen.

Screenshot_20190428-095016

Odd, when was the last time you updated the app?

Oh, perhaps you using the Power Meter rather than power measure.

Power meter capability is used by apps to show the total amount of power used by a device - since the beginning of time.

As this value itself is the sum of the kW⋅h returning anything other then the sum is rather pointless to the vast majority of use cases.