On the balcony, named Balcony humidity
id: sensor.viking_0203502038_87_00_humidity
In the shower, simply named Shower humidity
id: sensor.viking_0203502038_87_00_humidity
What I want to accomplish is to determine if someone is taking a shower (in which case the light time out will be longer and the blinds will be closed in the bedroom). I have done this with a helper that turns on when Shower Humidity is over a specific value, but since the outdoor humidity changes over the seasons a low value for Shower humidity will give a lot of false positives half the year, and a high value will take too long for the helper to switch on.
I would like to try something like this:
[pseudo code]
IF (shower humidity) > ( (shower humidity) + ( 100 - (balcony humidity) ) )
THEN (shower switch) = 1
IF (shower humidity) =< ( (shower humidity) + ( 100 - (balcony humidity) ) )
THEN (shower switch) = 0
100 is for the maximum humidity
But I don’t know how the proper code would look like or where to put it.
I have looked in to templates under Developer tools, and googled, but I can’t get a grip of how to do it.
Is there a templates for dummies that I’ve missed?
Or maybe some one whips this into a couple of lines…
If you’re convinced about that latest logic (I’m not…), put the correct sensor IDs in here and drop it into the template binary sensor helper state template as in the screenshot above:
{% set sh = states('sensor.shower_humidity')|float(0) %}
{% set bh = states('sensor.balcony_humidity')|float(0) %}
{{ sh > bh + (100 - bh / 10) }}
Note arithmetic rules of order (I learned them as BODMAS: brackets, order (powers), division, multiplication, addition, subtraction) — that’s “bh plus 100 minus one-tenth of bh”. You may want to move some brackets around, as the test value for comparison with sh ranges from 100% to 190%…
I’m open for suggestions for another logic or another method (that doesn’t involve significant costs…)
Thanks for the short and simple code.
Precedence of mathematical operators is a pita when it comes do computers and phones… I tend to sprinkle with brackets. I’m not familiar with the BODMAS acronym (being a non native english speaker) but the way you wrote it would not be correct as I learned in school, as for what I want.
I bracketed it like this, and so far the template sensor shows of, which is the same as reality.
{% set sh = states('sensor.viking_0203502038_d7_00_humidity')|float(0) %}
{% set bh = states('sensor.viking_0203502038_87_00_humidity')|float(0) %}
{{ sh > (bh + ((100 - bh) / 10)) }}
I am using derivative helper for humidity as condition in one of my automations. So if water flow is constantly above XY, I check if derivative is below 0 - meaning someone is likely taking shower.