# ATAN curve for probabilities

In many home automation scenarios we have an observed value, maybe a sensor reading, maybe a time interval since something happened. We want to convert that value to a probability, e.g. what's the probability that someone left the room given how long it's been since any activity there.

Typically we might start using conditions:

``````    time < 5 ? 0.2 :
time < 10 : 0.5 :
0.7
``````

And we might throw in an `abs` function somewhere to deal with negative values. This piece-wise approximation is a a good way to start and it's easy to think about but there is a better way.

What we want is a function that maps any input value to the range 0.0 - 1.0. We want it to be smooth. We want to be able to adjust how quickly it rises (or falls) and how much of a 'dead zone' there is around zero. For example, for 2 minutes we want to assume nobody has left a room, after two minutes we want the probability to rise slowly and by five minutes we want it to rise quickly as we are fairly sure they have now departed.

## The ATAN function

The ATAN function is an ideal function to achieve this. If we only have positive values we can use `p = atan(x/k)/pi*2` and for any positive `x` we will get a value from 0.0 to 1.0. We can adjust how quickly it rises by adjusting k. And if we want a falling probability we can just do `(1 - p)`.

If we want a 'dead zone' at the start we can just offset the graph and divide by `pi` without a multiplier, but we need to add back the new zero point to get the start point back to zero. e.g.

``````    float p_gone_away =
-atan(-5) / PI +
atan(t/90 - 5) / PI;
``````

This produces the nice curve shown at the top and works well for converting positive values to probabilities.

One other probability trick you should know for home automation is how to combine two probabilities (a, b) in an either-or situation. Adding them would result in a value greater than 1.0 because there's also the chance that both a and b are true, and we'd be double counting. But if we subtract `(a * b)` which is the probability that both are true we fix that problem:

``````    float combined = a + b - a * b;
``````

This ensures that the combined probability never goes above 1.0. It comes from the inclusion–exclusion principle which holds when the events are independent.

P(A∪B)=P(A)+P(B)−P(A∩B)

## Logistic Function

See also the logistic function as another way to map values to probabilities.

## Related Stories

### Time Series Data Compression

This new technique to compress the time series data collected by my home automation system seems to be working really well.

Ian Mercer

### Home Automation

I've been working on home automation for over 15 years and I'm close to achieving my goal which is a house that understands where everyone is at all times, can predict where you are going next and can control lighting, heating and other systems without you having to do or say anything. That's a true "smart home".

Ian Mercer

### Bluetooth Tracking Project

My year long Bluetooth project that won the \$20,000 HCI and Microsoft competition during lockdown has continued to grow and now reliably tracks how many people are in the house and outside and can locate any device down to room level.

Ian Mercer

### Digital Twins are never identical

Digital Twin are an online representation of a real world object, a copy of its properties in the digital world and a way to send updated and commands to it. In effect I've been making them for years but now they have a trendy name.

Ian Mercer

### Home Automation Sensors

An overview of the many sensors I've experimented with for home automation including my favorite under-floor strain gauge, through all the usual PIR, beam and contact sensors to some more esoteric devices like an 8x8 thermal camera.

Ian Mercer

### Why smarthomes are hard

Why automated learning is hard for a smart home. The perils of over-fitting, under-fitting and how the general unpredictable nature of life makes it hard to build a system that learns your behavior.

Ian Mercer

### Collinearity test for sensor data compression

One way to reduce the volume of sensor data is to remove redundant points. In a system with timestamped data recorded on an irregular interval we can achieve this by removing co-linear points.

Ian Mercer

### 3d Printed ESP32 Brick

ESP32 provides a great platform for sensors around the house but by the time you've added a USB power brick, cable and enclosure it's quite messy. I wanted a device that I could just plug in with no exposed wires and no mounting needed so I designed one in OpenSCAD.

Ian Mercer

### Bluetooth Sensing for Home Automation

Bluetooth sensing for home automation is a great proxy for people counting as it can detect and locate each cellphone in the house. iBeacons attached to tools, cars and pets can provide a 'find my anything' feature too.

Ian Mercer

### Microwave Doppler Sensors (RCWL-0516)

Microwave doppler sensors can be found in some alarm sensors but there are also available very cheaply as a separate component. They offer exceptional range but suffer from false triggers requiring a probailistic approach to people sensing.

Ian Mercer

### Optical-beam sensors

Optical-beam sensors are reliable and can cover a long-distance such as across a garage or aisle-way. When they include multiple-beams they have good false-trigger rejection.

Ian Mercer

### PIR Sensors for Home Automation

PIR sensors are cheap and easy to use but they suffer from slow response times and low repeat rates.

Ian Mercer

### Strain-gauges

Strain-gauges are my top-rated sensor for home automation because they are invisible, reliable and can be tuned to detect people and ignore pets.

Ian Mercer

### Event blocks

Home automation systems need to respond to events in the real world. Sometimes it's an analog value, sometimes it's binary, rarely is it clean and not susceptible to problems. Let's discuss some of the ways to convert these inputs into actions.

Ian Mercer

### Logistic function - convert values to probabilities

Another super useful function for handling sensor data and converting to probabilities is the logistic function 1/(1+e^-x). Using this you can easily map values onto a 0.0-1.0 probability range.

Ian Mercer

Several years ago we did a major remodel. I did all of the finish electrical myself and supervised all of the rough-in electrical. I also put in all of the electrical system and water in our barn. I have opinions ...

Ian Mercer

### T-Mobile home internet

I'm testing a T-Mobile Home Internet device as a backup to XFinity and a way to offload half our monthly traffic to avoid the XFinity 1.2TB cap

Ian Mercer

### Bluetooth

One of my inventions recently won a \$20k global competition for applications that could help in a pandemic. It uses Bluetooth to count people.

Ian Mercer

### Probabilistic Home Automation

A probabilistic approach to home automation models the probability that each room is occupied and how many people are in that room.

Ian Mercer

### Multiple hypothesis tracking

A statistical approach to understanding which rooms are occupied in a smart house

Ian Mercer

### A state machine for lighting control

An if-this-then-that style rules machine is insufficient for lighting control. This state machine accomplishes 90% of the correct behavior for a light that is controlled automatically and manually in a home automation system.

Ian Mercer

### Home Automation States

Understanding the many different 'states' a house can have is critical to creating great home automation

Ian Mercer

### Graphing gigabytes of home automation data with tableau

Some interesting charts from the gigabytes of data my home automation system produces

Ian Mercer

### iBeacons for Home Automation

My investigations into using iBeacons for home automation

Ian Mercer

### iBeacon meetup in Seattle - January 2015

My notes on the iBeacon meetup in Seattle held in January 2015

Ian Mercer

### Home Automation Systems as a Graph

Using nodes and links to represent a home and all the devices in it

Ian Mercer

### N-Gram Analysis of Sensor Events in Home Automation

Using n-gram analysis to spot patterns in sensor activations

Ian Mercer

### Xamarin Forms Application For Home Automation

Building a Xamarin Forms application to control my home automation system

Ian Mercer

### The Internet of Hubs (and things)

Maybe it should be called the Internet of Hubs instead

Ian Mercer

### Showing home status with just a single RGB LED

Multicolored LEDs can convey a lot of information in a small space

Ian Mercer

### A wireless sensor network using Moteino boards

The diminutive Arduino boards include a powerful transmitter/receiver

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

### A RESTful API for sensor data

POSTing data to a home automation system from Arduino devices

Ian Mercer

### The Internet of Boilers

An experiment to measure every aspect of an HVAC / boiler system

Ian Mercer

### VariableWithHistory - making persistence invisible, making history visible

A novel approach to adding history to variables in a programming language

Ian Mercer

### A Quantified House - My Talk to the Seattle Quantified Self Meetup

My talk to the Seattle Quantified Self meetup

Ian Mercer

### Integrating an Android phone into my home automation system

Some new features for my home automation using an Android phone

Ian Mercer

### Before there was the web there was BeebTel

Just thought I should mention that I built a web-like system before the web existed

Ian Mercer

### My first programme [sic]

At the risk of looking seriously old, here's something found on a paper tape

Ian Mercer

### The Internet of Dogs

Connecting our dog into the home automation

Ian Mercer

### GreenGoose Review

A review of the now defunct GreenGoose sensor system

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

### What does a Smart House do at Halloween?

My favorite home automation features for Halloween

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

### Looking forward to the new year and our new datacenter

Historical note about moving my servers into a datacenter

Ian Mercer

Ian Mercer

### Future proof your home with a new conduit system?

Running conduit can be expensive but maybe you don't need one to every room

Ian Mercer

Ian Mercer

### Shortened URLs should be treated like a Codec ...

Expanding URLs would help users decide whether or not to click a link

Ian Mercer

### Tagging File Systems

Isn't it time we stopped knowing which drive our file is on?

Ian Mercer

### WMPnetwk.exe started using 50% of my CPU

Uninstalling Windows Media Player - the end of an era

Ian Mercer

Ian Mercer

Ian Mercer

### Amazon Instance vs Dedicated Server comparison

Some benchmark performance for Amazon vs a dedicated server

Ian Mercer

### Agile Software Development is Like Sailing

You cannot tack too often when sailing or you get nowhere. Agile is a bit like that.

Ian Mercer

### AntiVirus Software is the Worst Software!

When your anti-virus software starts stealing your personal data, it's time to remove it!

Ian Mercer

### Second Drobo Update

At this point things were looking up for my Drobo

Ian Mercer

### It's all about disk speed

Why disk speed is the most critical aspect for most modern PCs and servers

Ian Mercer

### Comcast woes and a new monitoring utility

Monitoring a cable modem using its HTML management interface

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

Ian Mercer

### World's Smartest House

Over 15 years of experimentation with home automation

Ian Mercer

### HX711 Strain Gauge Pulsor Sensors

Using Pulsor sensors with an HX711 for homeautomation.

Ian Mercer

### Preparing for death

A friend died last year, it wasn't unexpected. He left a lot for his friends to cleanup. Maybe these notes can help someone else prepare better.

Ian Mercer

### World's Smartest House Videos

A collection of videos about my smart home efforts

Ian Mercer

### Pressure Sensors for Home Automation

Pressure sensors can detect HVAC system operation and could potentially detect clogged filters.

Ian Mercer