Bathroom occupancy sensor

hello,

I apologize for my English as it’s not my native language.

I am trying to create a bathroom occupancy sensor, so I know when someone of us is having a shower.
Currently I was using a humidity sensor and a lights switch.

I created a template with statistics platform

  - platform: statistics
    name: Bathroom Humidity Stats
    entity_id: sensor.humidity_158d00048684ab
    sampling_size: 40
    max_age:
      hours: 1

and changing occupancy state using the following template:

{{ states('sensor.humidity_158d00048684ab') | int > states.sensor.bathroom_humidity_stats.state | int and states.sensor.bathroom_humidity_stats.state != 'unknown' and states.group.attic_wc.state == 'on' }}

I am having two problems
First of all, if my wife have a shower in the morning the sensor won’t change state as she might not turn on the lights.

However the most important is that I had false sensor states, as we live on an island and the humidity changes very often nearly the whole day. So the above implementation was giving me that someone is having a shower even though nobody in the shower.

I tried to re-write the template using the following logic:

        {% if states.sun.sun.state == 'below_horizon' %}
            {{ states.sensor.bathroom_humidity_stats.state | int - states('sensor.humidity_158d00048684ab') | int > 10 and states.sensor.bathroom_humidity_stats.state != 'unknown' and states.group.attic_wc.state == 'on'  }}
        {% else %}
            {{ states.sensor.bathroom_humidity_stats.state | int - states('sensor.humidity_158d00048684ab') | int > 10 and states.sensor.bathroom_humidity_stats.state != 'unknown' }}
        {% endif %}

However the above is also not working :frowning:
Here is the graph from sensor the time I was having a shower.

and here is the graph from bathroom statistics sensor

As far as I see the humidity difference was >10
So why it didn’t change state ?? Any ideas please?

As this community’s forum is voluntary I don’t see many volunteers lately :frowning:
Where are you guys? Nobody wit some spare time to help a newbie ??

Hi, I use a trend binary sensor to determine when the shower is occupied and turn on a dehumidifer. The following is the code which you may be able to adapt for your application:

- platform: trend
  sensors:
    ensuite_shower_occupancy:
      entity_id: sensor.ensuite_humidity
      device_class: moisture
      max_samples: 10
      sample_duration: 300
      min_gradient: 0.01667

This works by detecting a sudden rise in humidity and the following graph shows that it correctly detected me having my shower this morning:

image

This is the corresponding humidity graph:

image

I use a standard Passive Infrared Detector (a Philips Hue motion sensor).

I have a 10 minute timeout and that is plenty in most cases.

What I recommend is

  • make the lights off as a slow transition like 30 seconds. When you sit on the throne with the mobile and time flies, you see the lights dim and can wave your hand to reset the 10 minute timer. There is nothing worse than suddenly be in the dark with no warning
  • try and position the sensor so it also covers the shower
1 Like

hello,
thank you for the reply

Could you please clarify what the min_gradient is for ?
I am using a Xiaomi sensor which creates the following graph.

Can’t figure out how do I use the min_gradient…

Sure … it’s the minimum rate that the humidity must change by for the sensor to switch on in %/sec as per the docs.

Mine is set 0.01667 %/sec or 1%/min and you probably need to play around with this to get the best result. My sample duration is 300sec so I am only monitoring over the last 5 mins.

Thank you!
Has anyone working values for Xiaomi Sensor ?

Reading the FAQ it says:

> If the temperature humidity and atmospheric pressure varies a bit only, data will be reported once an hour. If the temperature variation exceeds 0.5℃, the humidity variation exceeds 6% and the atmospheric pressure is no less than 25Pa, data will be reported instantly.

So I’m wondering if someone has test already and got working values?

That’s actually the Aqara Zigbee sensor that I have however the way the humidity changes will probably be influenced by a number of factors like the temperature, size of the room, the type of shower (i.e. the force of the spray and its spray pattern etc.).

I just just set some default settings for the Trend binary sensor and tweaked these a little until it worked reliably for my bathroom which is quite small. I would say that the reliability of my setup is about 95% or better.

Am getting close…
Tonight me and my wife had a shower.

When wife was in shower the trend sensor was triggered properly.

After about two hours I had a shower too.
This time the sensor didn’t triggered.

I can’t explain why as looking the graphs it should had triggered.

And here is the graph from the humidity sensor

Any suggestions ??

You could also try a DIY raindrop sensor if you want to try an alternative approach.

I could also imagine a slimmer version (perhaps even just using two wires) attached to the showerhead somehow.

Or you could do something similar to what I did to check if the tap is turned on.

in my home, the bathroom door is closed when someone is using the bathroom and open when no one is using it. so it is very simple to determine whether the bathroom is occupied or not by using a door sensor.