Detect if somebody is taking a shower

I'm trying to make my xiaomi temperature sensor detect if I'm taking a shower or not. It's this one: https://gloimg.gbtcdn.com/soa/gb/pdm-product-pic/Electronic/2018/10/24/goods_img_big-v5/20181024111421_98590.jpg

I'm using this with zigbee2mqtt. I also use this with a xiaomi motion detector, but that part already works.

Now when I take a shower, it will report that the humidity increased. After taking taking the shower, it will detect that the humidity has dropped.
So my plan would be, to detect when the humidity makes a steep increase. And this will make the bathroom occupied. And when it drops a certain amount it will make the the bathroom unoccupied.
I tried the RBE node, but this will detect increased and decreased values at the same time. Also tried the edge trigger node, but that only works with fixed values.

Here's my flow so far. It detects when someone has occupied the bathroom, but when the humidity drops, it says occupied and unoccupied at the same time.

[{"id":"89e3d052.09eec","type":"mqtt in","z":"d11dfeaa.8b609","name":"","topic":"zigbee2mqtt/Temperatuur_badkamer","qos":"2","datatype":"json","broker":"7a291092.162ac","x":1860,"y":480,"wires":[["47b9e919.17f118","5a111ba0.403ec4","19cbe94e.c0bf17"]]},{"id":"47b9e919.17f118","type":"switch","z":"d11dfeaa.8b609","name":"Badkamer NIET bezet","property":"badkamer","propertyType":"global","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":2240,"y":460,"wires":[["c7f62777.eee2c8","13a5a2af.2095fd"]]},{"id":"5a111ba0.403ec4","type":"switch","z":"d11dfeaa.8b609","name":"Badkamer WEL bezet","property":"badkamer","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":2240,"y":500,"wires":[["f8edeff9.3865b","d7b28c61.dea8c"]]},{"id":"c7f62777.eee2c8","type":"rbe","z":"d11dfeaa.8b609","name":"Humidity is omhoog gegaan?","func":"deadband","gap":"4","start":"","inout":"out","property":"payload.humidity","x":2480,"y":460,"wires":[["6d83af79.a6d9c","897f0b9c.f47608","2ecb53be.996d7c"]]},{"id":"f8edeff9.3865b","type":"switch","z":"d11dfeaa.8b609","name":"Humidity is omlaag gegaan?","property":"payload.humidity","propertyType":"msg","rules":[{"t":"lt","v":"humidity","vt":"global"}],"checkall":"true","repair":false,"outputs":1,"x":2480,"y":500,"wires":[["3bd82e6.8dfabd2","a3a28ecd.85ba5"]]},{"id":"3bd82e6.8dfabd2","type":"change","z":"d11dfeaa.8b609","name":"Set global.badkamer FALSE","rules":[{"t":"set","p":"badkamer","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2740,"y":500,"wires":[["902e076a.2282d8"]]},{"id":"ad4d8e45.e3381","type":"inject","z":"d11dfeaa.8b609","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":2530,"y":540,"wires":[["3bd82e6.8dfabd2"]]},{"id":"897f0b9c.f47608","type":"change","z":"d11dfeaa.8b609","name":"Set global.badkamer TRUE","rules":[{"t":"set","p":"badkamer","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2740,"y":460,"wires":[["fd019e56.66633"]]},{"id":"2ecb53be.996d7c","type":"change","z":"d11dfeaa.8b609","name":"","rules":[{"t":"move","p":"payload.humidity","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3060,"y":360,"wires":[["eb7a0d27.f408d","16e2cb00.86cdf5"]]},{"id":"eb7a0d27.f408d","type":"change","z":"d11dfeaa.8b609","name":"","rules":[{"t":"set","p":"humidity","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3290,"y":380,"wires":[["c13d658c.45f8a8"]]},{"id":"7a291092.162ac","type":"mqtt-broker","z":"","name":"MQTT","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

First of all, I don't think that by following the curve of humidity change the presence detection will be accurate. Humidity change is too slow process for that.

But it is smart thing to do experiments anyway.
I struggled with edge trigger nodes once and fixed values didn't work for me so I decided to develop a bit smarter node for that. The node is dedicated to manage wet room humidity. I'm not sure if it is suitable for your use case but you can try. node-red-contrib-self-adjusting-threshold

If I understand correctly, this node calculates the average humidity over 1 hour. Which is too slow for a bathroom.
What I want is this. Say, the humidity is 50. When I take a shower, the humidity climbs to 60, the 70, maybe 80. The first climb to 60 should be detectable. When the shower ends, the humidity drops quite quickly. So from 80 to 75 to 65 etc. It would be my goal to detect that drop from 80 to 75.
But the thing is, that the humidity can be different. Sometimes it starts wth 40 and goes up to max 60. So different values. And that is the part where I'm stuck. I which the RBE node could detect if the value increases or decreases. It can now only see a change, be it either up or down.

This is probably most trickiest part where your expectations may or may not fit into desired limits.
It is not rare that with perfect conditions, the relative humidity may stay at 100% for quite long period before it starts to drop.

But anyway. Looking only the humidity value change does not do the trick. You should look at value change over the time period to make decision of falling or rising considered. And that keeps decision making slow. Also the change of humidity depends on much more than just forced ventilation and stopped or started hot shower. Or is the shower always hot? And the time under the shower :upside_down_face: Sometimes the door left open or something and for last and not for least, the overall conditions vary all the time.

So there will be quite many false positives to get rid before you can rely on calculated status.

Mathematically the solution might be like this;
Collect values over time period.
Calculate trend over that period
Trend slope tells if change of data is rapid enough to make decision of room status.

With every new incoming value get rid of old values which does not fit into time period
Start over the calculation

No clue what you're trying to say. I only need to detect when the humidity drops or rises significantly.

What people are saying is that watching humidity will probably not work, but it is a good experiment to try.

So build the sensor and put it in the bathroom. Have it take readings every 5 minutes and store them in a database. Then record when you take a shower and when you finish. (maybe have a button you can press to send a timestamp)

After a week, you should be able to look at a graph of the data and see what it shows. You might find a rapid change of the humidity before and after or a very small change but you will have a better base line to see if this experiment will work because you will have actual data.

1 Like

I already installed the sensor. And I know it could work. I only have trouble processing the data. If I can process this I'm good. So I need to detect when the humidity goes up by more then 4. So for example if it goes from 50 to 57, or from 62 to 67. I know the bathroom is occupied.
But I also need to detect if the value goes down with more then 4. Then I know it is not occupied. So for example it goes from 74 to 69,or maybe it goes from 62 to 57.
So how can I process a number and detect if it increases or decreases, according to the previous payload. And if it was more then 4 (or maybe 3 or 2)?

You also have to take into consideration that normal outdoor changes in weather conditions will quickly affect the indoor relative humidity readings, at least that is the situation in our house. So, as an idea, maybe you need two sensors, one in the bathroom shower and one in a "normal" dry room on the same floor, then detecting the delta between those could be a quicker indication when the shower is on or off

I keep repeating myself, but the data is not the issue, but processing it. How can I detect if a value increases, and how when it decreases. I see it in the humidity graph inside Home assistant, I don't know how to detect increased/decreased values.

Have a look in the docs at the section on writing functions, it shows you how to use node context to save a value inside a function node. So if you have a function that saves the passed in value (and possibly the current time) then the next time round you can compare the new value with the old one and see how much and at what rate it is increasing or decreasing and pass on a message if appropriate.

Why not put a temperature sensor on the outside of the shower wall? You would get a faster response. Also you "Know" when you are taking a shower! :slight_smile:

I'm a total noob with function nodes.

It's already there. It reads temperature, humidity and pressure.

Well start by reading the docs. Then ask for help if you can't make it work.

I am saying just use the temperature to detect when the shower is in use, it will be much more reliable than measuring the humidity. To be clear - put a temperature sensor directly on the outside of the shower wall.

The temperature doesn't change that much, so that wont work in my case. Humidity has much better data. Goes up much quicker and drops much quicker then the temperature.

Writing javascript in function nodes is necessary when no nodes are available solving the use case right out of the box.

Since you now mentioned you already have a similar (or the same type is best for accurate reference) outside the bathroom, I repeat myself; go for the delta! No need for databases, just use variables and context inside the function node to save the readings and do the processing. I think the needed javascript code actually should be rather simple. Eventually you should use a smooth node for each sensor input to create a mean value, all depending on how frequent you receive the readings from the sensors

I am talking about measuring the temperature of the shower wall itself, not the ambient temperature!!!!

Ok ok I get it /s :slight_smile:
But that wont work because the wall is thick. Humidity should be fine.

At the moment I'm already storing the humidity within global.humidity when it rises. But when it drops, my flow processes rise and fall at the same time. I'll look into the function node, but programming is difficult.

That's what I'm saying

I guess you need an example to get the picture :wink: