Detect showering with trend binary sensor

Hi all,

I’m trying to detect if the shower is running using a trend binary sensor. I have a temperature sensor attached to the hot water pipe going the shower.

My shower detection logic would consist of the initial rise of the temperature and then when it’s above 40°C I mark it as showering.
So I need to detect the first incline until 40°C. But I’m having some trouble understanding how I should configure the trend binary sensor.

Here I have plotted an example of the rising temperature after turning on the shower:


As you can see the temperature rises quite rapidly, around 2°C every 10 seconds.

What value would I need for the min_gradient? And do I need to use sample_duration and max_samples?

1 Like

So your graph has a gradient of 0.2 (2/10) initially. Set your min gradient to 0.1. Anything above that will turn on the sensor.

Note that it will turn off when the temperature stabilises.

The default value for max samples (2) should work for you.

Hi Tom,

Thanks for replying. So this should do the trick?

binary_sensor:
  - platform: trend
    sensors:
      showering_start:
        entity_id: sensor.showerpipe_temperature_mqtt
        min_gradient: 0.12

How did you exported the graph please?

I’ve exported data from the recorder. I use MySQL for the database and used phpmyadmin to export the usefull data.

2 degrees over 10 seconds and min_gradient is rate of change over 1 second. So 0.2. But you might want to go lower, like 0.15 which is 1.5 over 10 seconds.

EDIT: Uh, this post showed up as new for me for some reason… disregard.

Hi guys,

However it has been working quite well, I do have some false positives. I’m not quite sure why tho. If you look at the image at 9:00, there was a detection, but the temperature graph shows no spikes?

My config:

binary_sensor:
#----------------------------------------------------------------
  - platform: trend
    sensors:
      showering_start:
        entity_id: sensor.showerpipe_temperature_mqtt
        friendly_name: Start douchen
        # In our case:
        #       2 degrees increase in 10 seconds
        #       2°C / 10 seconds = 0.2
        #       Min gradient set to 0.12 to be sure we can get above
        min_gradient: 0.12

Any ideas to eliminate the false positives?

Another example from last night. Temperature was around 16.88°C to 17.0°C, and the trend sensor turned on with a gradient of 0.353.

{
"entity_id": "sensor.showerpipe_temperature_mqtt",
"friendly_name": "Start douchen",
"gradient": 0.3534604774311847,
"invert": false,
"min_gradient": 0.12,
"sample_count": 2,
"sample_duration": 0
}

Did you sorted this out? I am having the exact same problem

if your max samples is set to 2, then it will take 2 samples. If the time change between the 2 samples has a large gradient, it will turn on. In @DavidW’s case, we can’t tell because he did not include the microseconds for his state change when it turned on. The math is simple for 2 points. It’s

Vn - Vn-1 / tn - tn-1

So if your time difference is small but V is large, you get a false trigger. Play around with the setup values until you remove the false triggers.

Just so you know how the math works, it fits a 2d line to your dataset, i.e. the number of saved data points. If the line’s first coefficient is greater than the max gradient, it’s on. So, more data points the better, especially if you’re getting a ton of data.

Could help me setting the data?
I would like to detect normal heating and water heating. How do I set this trend?