Logical question

Hi All,

{% set value = (states('sensor.master_bathroom_humidity_average_linear_24h') | int(default=0) | round(1) - states('sensor.bathroom_humidity') | int(default=0) | round(1) ) > states('input_select.helpers_master_bath_humidity_threshold') | int(default=0) %}
 value }}

Does this literal mean the sensor for average is at the end greater then the input?
Or does this mean the output of the calculation average-humidity is greater then input?

Im struggle a bit with this logical thing.

Because when i switch them i get other output

{% set value = (states('sensor.master_bathroom_humidity_average_linear_24h') | int(default=0) | round(1) - states('sensor.bathroom_humidity') | int(default=0) | round(1) ) > states('input_select.helpers_master_bath_humidity_threshold') | int(default=0) %}
{{value }}

Output: True

{% set value = (states('sensor.bathroom_humidity') | int(default=0) | round(1) - states('sensor.master_bathroom_humidity_average_linear_24h') | int(default=0) | round(1) ) > states('input_select.helpers_master_bath_humidity_threshold') | int(default=0) %}
{{value }}

Output: False

try

{% set value = ((states('sensor.master_bathroom_humidity_average_linear_24h') | int(default=0) | round(1)) - (states('sensor.bathroom_humidity') | int(default=0) | round(1) )) > states('input_select.helpers_master_bath_humidity_threshold') | int(default=0) %}
{{ value }}

I want to know this:

{% set avg = 70 %}
{% set hum = 65 %}
{% set input = 2 %}
{% set value = (avg - hum) > input %}
{{ value }}

output: true
{% set value = (hum - avg) > input %}
{{ value }}

output: false

When i read it this mean literal = AVG - HUM greater then. Second one is literal = HUM - AVG greater then.

I thought it was just value A - value B then is output greater or smaller then value C

Is 70-65 > 2 , yes that’s true ( because it’s +5 )
65-70 = -5, thats not greater than 2, therefore false

{% set value = (states('sensor.temp_laundry') | int(default=0) | round(1) - states('sensor.temp_bath') | int(default=0) | round(1) )  %}
{{value }}
{% set value = (states('sensor.temp_bath') | int(default=0) | round(1) - states('sensor.temp_laundry') | int(default=0) | round(1) )  %}
{{value }}
{% set value = (states('sensor.temp_laundry') | int(default=0) | round(1) - states('sensor.temp_bath') | int(default=0) | round(1) )  > ('5') | int(default=0) %}
{{value }}
{% set value = (states('sensor.temp_bath') | int(default=0) | round(1) - states('sensor.temp_laundry') | int(default=0) | round(1) ) > ('5') | int(default=0) %}
{{value }}

==
-7
7
false
true

PS: Maybe you want to look for the “span/difference” between the 2 values ?

I need to know if the humidity (realtime sensor) is higher then the average sensor.
When we go shower the humidity rise so the fan turned on. Then i wait 5 minutes with a delay in automation then a wait template. The wait template is waiting when humidty is lower again then the average with a trashold

- id: f7c7ba33-5a72-4bd2-8ba1-ca9dfd1583bf
  alias: "Control - Bathroom humidity v2"
  mode: restart
  trigger:
    - platform: state
      entity_id: binary_sensor.fan_hum_lower_then_avg
      from: "off"
      to: "on"

  variables:
    avg: "{{ state_attr('binary_sensor.fan_hum_lower_then_avg','avg')}}"
    hum: "{{ state_attr('binary_sensor.fan_hum_lower_then_avg','hum')}}"

  condition:
    - "{{ states('sensor.fan_speed') in ['low', 'off'] }}"
    - "{{ is_state('binary_sensor.group_family_manual', 'on') }}"
    - "{{ is_state('input_boolean.function_vacation', 'off') }}"

    - condition: time
      after: "05:30:00"
      before: "22:30:00"

  action:
    - service: switch.turn_on
      target:  
        entity_id: switch.fan_hig
   
    - delay: "00:05:00"

    - wait_template: "{{ is_state('binary_sensor.fan_hum_lower_then_avg', 'off') }}"

    - if:
        - "{{ is_state('sensor.fan_remote', 'Home Assistant') }}"

      then:
        - service: switch.turn_on
          target:  
            entity_id: switch.fan_standby
                

Try this

{% set value = states('sensor.rel-time-humid') | int(default=0) | round(1) > states('sensor.avg')| int(default=0) + 2 | round(1)%}
{{value }}
{% set value = states('sensor.rel-time-humid') | int(default=0) | round(1) < states('sensor.avg')| int(default=0) + 2 | round(1)%}
{{value }}

EDIT

PS: i do think your automation, looks a bit " to complicated "
And you might wanna rethink the use of an “average value-sensor” as a trigger , After a short while in a hot shower, your average-sensor will go sky high, and move the “trigger-point” along ( unless that is a fixed state )

1 Like

Yes but it will never go higher right as the real time humidity when we shower.
When we are done the humidty will go lower then the average sensor.

(thats the idea behind)

- platform: statistics
  name: "Master Bathroom Humidity Average Linear 24h"
  unique_id: "14036730-f69a-43e4-8870-65957b2fabaf"
  entity_id: sensor.bathroom_humidity
  state_characteristic: average_linear
  sampling_size: 50

I don’t know how the average_linear and sampling size works actually, maybe you are right, that that solution takes “normal” variations into account.

But i don’t see any point in starting my fan in the bathroom, if the humidity, raise above an “average” of i.e 40 to 42, Or 60, to 62. So i would add a “lower” fixed tress-hold
( Currently i only have “above 75 = evacuate” , beside another fan, switch(w. timer) when someone needs to “reduce the impact of their short visit” :laughing:

Right, the current humidity-sensor will drop fast, from i.e 82% to i.e 74%, while the average might still be at 78 ( Don’t stop the Fan ! ) Well again i haven’t seen the “pattern” of your average sensor, in fact i have no average sensors(in use), not for humid, nor temp, nor electricity prices etc., not for “fun/interesting to look at” either

Lets say i drink an average of 20 beers in a month, do i get drunk ?, Indeed because i drank them all within 5 hours :laughing: , well meaning i still haven’t found any valid use for average values
If i have a average electricity-cost of 0.10Euro/kwh , is that High or Low ? , If i Mainly used electricity during high-cost hours, it’s high , if i mainly used electricity during low-cost hours it’s low, which make an average of electricity cost somehow pointless

1 Like

Haha :slight_smile: the automation is working again.

Shower is on, humidity rise and average rise also but slower.
Delay of 10 minutes
Wait template: wait until humidity - average is greater then threshold 2

When showers is off the humidity will go lower because of the fan.
Average goed also lower and when this is within the 2 then fan stop

I can change the threshold because in winter is better to have 2 and summer to have 3. Warm weather outside can make humidity rise also.

1 Like

In specific if you live in a wooden house , as i do.
Today humid is 41% in the bathroom(temp 20.3), summer it’s normally around 60%, and as i find higher humidity more “comfortable” for my health, i prefer the latest, best with 65-70