World News

This one change made my Home Assistant automations far more accurate

https://www.profitableratecpm.com/f4ffsdxe?key=39b1ebce72f3758345b2155c98e6709c

Do you find that you’re getting false positives for your smart home automations? It can be frustrating when automations trigger when they shouldn’t. If this is happening to you, setting up a Bayesian sensor may help.

What is a Bayesian sensor in Home Assistant?

A Bayesian sensor in Home Assistant is a virtual binary sensor that generates its state based on the states of other sensors. It uses Bayesian probability to determine whether its state should be on or off.

Bayesian probability is based on Bayes’ Theorem, named after Thomas Bayes, the 18th-century English statistician who developed it. In very simple terms, Bayesian probability looks at an initial belief called a “prior,” such as the likelihood that a person is at home. It then uses a calculation to update the likelihood of that belief based on additional observations.

Everything Presence Lite mmWave presence sensor on a work surface. Credit: Adam Davidson / How-To Geek

For example, if you’re at home for 16 hours a day on a typical weekday, the initial belief might be that there’s a 2/3 probability that you’re home at any given time, since 16 out of 24 hours is equivalent to 2/3. However, if motion is detected by a motion sensor in your home, this will increase the likelihood that you’re at home, but it won’t make it a certainty, because the cat could have set off the motion sensor. You then need to factor in the probability that the motion sensor has detected the cat and include that in the calculations.

If this all sounds complicated, it’s because it is. Thankfully, the Bayesian sensor in Home Assistant does the calculations for you; you just need to provide the relevant probabilities for it to work with.

Why Bayesian sensors make your automations smarter

The beauty of Bayesian sensors is that they can make your Home Assistant automations much more accurate. If your cat does sometimes set off your motion sensor, for example, you can’t rely on the absolute state of that sensor to determine if you’re home or not. Just because motion is detected, it doesn’t mean you’re at home.

An Aqara Light and Motion Sensor P2 sitting on a countertop. Credit: Chris Hachey / How-To Geek

Bayesian sensors can combine multiple pieces of evidence to give you the probability that you really are at home. Your Bayesian sensor will only turn on when that probability is above a certain threshold. You can use the probability that the detected motion is caused by your cat, for example, combined with the prior probability that you’re at home, to calculate the likelihood that you really are at home.

By tweaking the numbers accordingly, you end up with a Bayesian sensor that’s far more accurate than simply relying on the absolute state of your sensors. With the right values, you should end up with fewer false positives.

How to set up a Bayesian sensor

Before you set up your first Bayesian sensor, it’s a good idea to figure out which entities you’re going to add to it, and what probabilities you’re going to use. This is the most daunting part. Thankfully, there are a couple of useful spreadsheets that can help.

This spreadsheet was created by the person who wrote the official Home Assistant documentation for the Bayesian sensor. You can use it to estimate the probabilities that a sensor is on, or any other entity is in a specific state. When you’ve got all your probabilities, you can test the outcome by checking boxes to mimic the sensors being activated. You can then tweak the probabilities or threshold to get the desired performance.

A spreadsheet for calculating probabilities to use in a Bayesian sensor in Home Assistant.

There’s also another spreadsheet created by a statistics professor and Home Assistant user, which does a similar job. Using one of these spreadsheets, you should be able to work out reasonable values for your Bayesian sensor.

Once you’re ready to set it up, you’ll need to add the Bayesian integration in Home Assistant. Go to Settings > Devices & services > Integrations in Home Assistant and click the “Add integration” button. Search for “Bayesian,” and select the Bayesian integration. Enter your probability threshold and prior that you calculated using the spreadsheets.

On the next screen, add observations for an entity’s state, numeric range, or from a template. You can continue to add further observations until you have everything in place. Once you’re done, click the “Finish” option, and your Bayesian sensor is created.

Ways to use Bayesian sensors in your smart home

One of the most common uses for Bayesian sensors in Home Assistant is for presence detection. You can combine multiple signals into a single sensor and get an impressively accurate indication of when someone is home or not. This is far from the only way to use them, however.

You can use Bayesian sensors to determine if you’re in bed, for example, with observations such as if your phone is on charge, if the TV is on, if your bedroom light is on, and so on. You can make a more accurate sensor for knowing when your washing machine is done by combining an observation of the power draw, which may drop in the middle of a cycle, with observations from a vibration sensor.

Elevated Sensors Bed Occupancy sensor. Credit: Elevated Sensors

If there are situations in your smart home where you’re getting too many false positives, it may be possible to use a Bayesian sensor to make things more accurate. They’re not suitable for every situation, of course. If you’re just looking at the state of a single entity, a Bayesian sensor may not be much use.


If you’ve avoided setting up Bayesian sensors because they sound too complicated, it’s worth giving them a second look. Using the spreadsheets linked above, you can calculate reasonable probabilities for your observations, and set up Bayesian sensors that work surprisingly well.

Related Articles

Leave a Reply

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

Back to top button