You could try using a template sensor, and if the difference between the outdoor and bathroom humidity is over/under (say) 5, then trigger the action. Something like this:
trigger:
- platform: template
value_template: >-
{% set h1 = states('sensor.melbourne_humidity') | int %}
{% set h2 = states('sensor.temp_1_hum') | int %}
{% if h1 - h2 > 5 %}true{% endif %}
I don’t understand how updating every 5 minutes is going to address the issue you have .
It seems to me that the problem is that you need a reference point…
Do you have a second humidity sensor outside the bathroom or one from a weather integration?
With one of those you can create a template sensor that gives you an ordinal value for the bathroom humidity as it relates to your reference.
template:
- sensor:
- name: "Bathroom Humidity Ordinal"
state: >
{% set ref = states('sensor.bathroom_humidity_1hr_mean') | float(0) %}
{% set low = ( ref * (11/12) + 19/3 ) | round(1, 0) %}
{% set high = ( ref * (23/24) + 20/3 ) | round(1, 0) %}
{% set humid = states("sensor.bathroom_humidity") | float(0) %}
{% if humid > high %} Above
{% elif humid < low %} Below
{% else %} Between
{% endif %}
availability: >
{% set ref = states('sensor.bathroom_humidity_1hr_mean') | float('unavailable') %}
{% set humid = states("sensor.bathroom_humidity") | float('unavailable') %}
{{ ref is number and humid is number }}
As you can see sometimes its around 58, 50, less then that, sometimes higher
The sensor is updating when there is a difference of 0,5
So my idea was create a second sensor that kept this value and update every 2 minutes
Then a automation that calculate the current sensor with the second new one.
If difference is more then 5 then basically someone is taking a shower.
new sensor / sensor
58 / 59 = false
58 / 65 = true
50 / 45 = false (but will used for turning off fan that if sensor is lower then new sensor = true)
Its not easy for me to explain in English …
If the 2 minutes update is done then the difference is less, but as you can see on image. When someone is taking shower the humidity is going fast up (updates les then 1 minute)
If you don’t have a second physical sensor and using a weather integration isn’t appropriate for your situation, why not take advantage of some of Home Assistant’s built-in statistics and utility sensors?
For example, you could use a Statistics sensor set to capture the mean humidity over the last hour and then use that as the reference value for the template sensor and automation I posted above.
You could use a shorter max_age, but if you make it too short, I think you will likely have the fan speed bouncing back and forth between low and high.
You really need a second sensor, because you need a baseline for your problem and as you state yourself the one sensor you have is not a good baseline.
Trying to base it on one sensor will create problems like the sensor only increase 4.9 steps in a timeslot and your setup only goes of at 5, but then when the sensor increase 0.1, so does your baseline, so you will never have it trigger then.
Trying to lower the value makes it trigger all to often when it is not wanted.
yes. I will try things and see what happen.
im not that into coding. When I figure it out then its in my memory and gives me more options also into other automations.
I have a bathroom humidity sensor and I do the following:
I create an averaged sensor that gives me the average over the last 12 hours. This handles seasonal and (most) weather related humidity changes just fine.
I then create a binary sensor that triggers to true if the current humidity is >10% above the average.
This works really well for me.
- platform: filter
name: "Bathroom Humidity Average"
entity_id: sensor.bathroom_humidity
filters:
- filter: time_simple_moving_average
window_size: "12:00:00"
- sensor:
- name: "Bathroom Shower Active"
unique_id: bathroom_shower_active
# Default to 100 humidity on the average if unknown to avoid triggering if data is missing
state: >-
{{ (states('sensor.bathroom_humidity')|float(0)-states('sensor.bathroom_humidity_average')|float(100)) > 10.0 }}
icon: >-
{% if (states('sensor.bathroom_humidity')|float(0)-states('sensor.bathroom_humidity_average')|float(100)) > 10.0 %}
mdi:circle-off-outline
{% else %}
mdi:weather-sunny
{% endif %}
I think you need to decide what overall method you want to use.
Your first 2 posts made it seem like it was important that you have dynamic thresholds. Now you are just looking for a difference of 5…
You have not supplied the configuration for sensor.bathroom_humidity_change_over_5_minutes, so it is difficult to guess how your trigger will behave. If you are using the sample from the Statistics sensor docs page, this will not work for a few reasons:
That example is using the change statistic. Using change, your automation above will trigger whenever the current humidity + 5 is above the 5 minute difference. So if the humidity doesn’t change for 5 min the equation will resolve to: {{ humidity + 5 > 0 }} which is true. Every time your humidity is stable for 5 minutes, the fan will turn on high.
float filters require defaults. In your template all of the float() should be float(0)
I would not use that short an interval. The shorter the interval, the more likely it is that the fan speed will bounce between low/high/off because the current humidity has an out-sized effect on the baseline/reference.
David has posted a working example above where he uses a 12 hour average.
Here the 2 sensors. The purple one is actual sensor and the blue one is the statistics one.
From 47 it goes to above 60. The statistics one also go very fast to new value.
Have you actually tried either solution that has been provided?
The graph looks as expected to me. The reason the two sensors show less separation than you might have expected is likely a combination of the max_age and the way your sensor updates its state. While a 1 hour max_age could be sufficient with a sensor that takes x samples/hour, in an earlier post you wrote:
If your humidity is relatively stable in the time period before someone takes a shower (or if your statistics sensor wasn’t given at least an hour to gather samples before the test) there will be a small number of samples contributing to the mean. When someone starts the shower the humidity changes rapidly, creating a lot of sample values. This skews the mean value of the statistics sensor towards the higher values. This is why a longer max_age might be needed for your application. Also, make sure you set a reasonable sampling_size, the default is 20. If your sensor updates every 0.5%, any change in humidity over +10%/hour will exceed your allotted samples.
Hi added the solution this evening. The action is a message only for now. To prevent the fan to go on and off all the time if there is some miscalculation or something else.
Thanks for all the help. im trying to see the logical idea behind the solution you gave me. Try to understand it also. Now its added as I say earlier.
That statistic sensor can really not be used.
You are not measuring the difference in one room compared to another room,but instead hwo fast it changes.
Implemented and the turn on part is working. The off part is to early.
My idea now is to do:
Idea 1:
create a sensor that stores the sensor.bathroom_humidity value, update every 10 min
use the statistics sensor to compare if the sensor.bathroom_humidity is above the statistic one.
TO turn fan off check if sensor.bathroom_humidity is below the new sensor that is update every 10 min.
Idea 2:
create a sensor that stores the sensor.bathroom_humidity value, update every 10 min
when sensor.bathroom_humidity is above the new sensor then turn on fan
directly create a sort of variable to store the new sensor value.
(because when shower longer then 10 min the new sensor have the new value)
Then to turn off the fan, compare the sensor.bathroom_humidity with the stored variable value.
(of same or below then turn off fan)
I think idea 2 is most accurate to try but:
i don’t know if i can create a sensor that update every 10 min.
i can create inside a automation a stored variable that wont update until the compare has been done to turn of fan. When start automation the stored variable will get the new sensor value (start point) to compare again.
I getting more exited to create a solution. I only have 1 sensor in bathroom. So have to find a way to solve this. All ideas are good ideas and its a start
Thanks to everyone to help and find a creative way to solve this