Quick Bathroom Fan Humidity Switch Control

Any ideas what’s wrong with my config for this stuff?

you shouldn’t post screen shots of code. Post text and be sure it’s properly formatted using ``` before and after the code block.

but from looking at the code you need to use lower case letters for the various domain keys. And no spaces:

binary_sensor:
.
.
statistics_sensor:
.
.
etc

Agree that posting actual code using 3 `s is far better than a screenshot.

I do see that your binary sensor indentation is off - first line should not be same ‘depth’ as the 2nd and 3rd. Also depends on how / where you’re configuring these - w/in configuration.yaml or if you’re using (as I am) separate files referenced via includes within configuration.yaml:

automation: !include automations.yaml
binary_sensor: !include sensor_binary.yaml
input_number: !include input_number.yaml
sensor: !include sensors.yaml

Certainly realize some of this configuration can be foreign when first starting - but worth learning the building blocks - will help tremendously as you become more addicted :slight_smile:

i have some trouble with the average value over the past 24h, my sensor isn’t reporting every 1 or 2 minutes it’s a zigbee device, so my avg value rises rapedly when there is moister. such vast that the treshold value never occured.

How could i solve this, i would like to test it to a value from let’s say 1 or 2 hours ago.

1 Like

is it a typo that you put sensor.sensor in the attributes section of your code?

attributes:
Hall: >
{{ states(‘sensor.main_hall_relative_humidity’) }}
Bath: >
{{ states(‘sensor.sensor.master_bath_humidity’) }}

No, but it’s optional.

The attributes expose the underlying values for easy view when drilling down on the Net sensor and easy access for automations in the trigger from_state and to_state properties.

Thanks, but I was specifically meaning how the last part of the code snipped says:

sensor.sensor.master_bath_humidity

Shouldn’t it be

sensor.master_bath_humidity ?

Sorry, you’re correct. I usually try and cut/paste working code. Something went sideways.

EDIT: Original post corrected, and updated with an availability clause.

Controlling fan based on bathroom humidity (regardless you use smart fan, smart relay or something like Switchbot Bot) is a good idea. However, I’d set the target humidity in a different way. I see no reason to set it by history. There are several objectives:

  1. Healthy humidity in space where you usually are (usually recommended: 40% – 60%; some recommend just 55% for summer).
  2. Reducing mold risk – the ranges can be somewhat higher, but if you have something like 23°C or more, the threshold is something like 65%. When your sensor is not directly above bath, maybe you will want to lower the threshold, even to something like 60 % or less. (I’ve written something about desired humidity at How do you care about humidity - #2 by v6ak .)

So, when you have something like 30% humidity on average, it doesn’t make much sense to achieve this low value after bathing.

Thanks for posting this, managed to get it created in HA but I’m not sure if there is an issue as it seems to be showing as always on, is that normal behaviour?

It didn’t trigger a change when the shower was on this morning

average linear sensor did pick up the spike though

image

I am sure you understand that you are not supposed to just copy and paste the codes, but will have to tweak the parameters based on how those readings are reported, how you calculate the average, and even where you are.

Tips to troubleshoot: double check your config, plot 3 things together: your humidity and average humidity and your binary sensor, and if you are using any automation, trace your automation.

Thanks for replying!

I’m trying to track the issue and have tried playing about with the sample size both number of hours
and sample size but whatever I do it seems to be working properly in that respect,. in that comparing the actual humidity sensor and the average linear everything seems to be working correctly its smoothing out the graph and I’m seeing the spike definitively earlier on the actual sensor vs my statistic sensor.

So my understanding is I should be getting the binary motion sensor only triggering as on when the actual rises over 5% more than the average linear? I copied your code exactly for the binary sensor as based on the figures I get 5% seems the right point to trigger based on either 1 or 3 hour sampling I tried.

But the issue is no matter what the difference between the 2 weather its above or below 5% the binary always shows as detecting motion, and without the state change in the binary I cant actually use the sensor. My understanding is if anything the binary should be showing if anything as not detecting motion but guess I must be missing something pretty obvious?

This is what I currently have in the configuration.yaml but also tried different hours and sampling size with the same result

sensor:
  - platform: statistics
    name: En Suite Humidity Average Linear 3h
    entity_id: sensor.en_suite_th_humidity
    state_characteristic: average_linear
    max_age:
      hours: 3
    sampling_size: 180

template:
  - binary_sensor:
      - name: "Showering en suite"
        unique_id: showering_ensuite
        device_class: motion
        state: > 
          {{( states('sensor.en_suite_th_humidity') | float(0) ) > 
            ( states('sensor.en_suite_humidity_average_liner_3h') | float(0) + 5 )  }}

Quite puzzling… I couldn’t see anything out of ordinary either.

Maybe… try playing with (those components of) the last 2 lines in the developer tool?

Was such a dumb issue :rofl: got someone else to look at it and they spotted I had a typo in the statistic sensor when I typed it into the binary spent hours looking at it myself and never noticed. Thanks for your help though only got to this stage reading your posts

1 Like

Hello, I am also trying to start the bath saddle fan when the humidity exceeds the desired %. Can you show me the complete code so that I can create my automation with my values?

Posted in message #1 at top of thread…

Below code gives: “Property value_template is not allowed”.

When I replace “value_template” by “state” it doesn’t give an error anymore. Why can’t I use the value_template anyone an idea?

- binary_sensor:
    - name: bath_humidity_change
      value_template: >-
          {% set humid = states('sensor.badkamer_1_humidity')|int(default=0) %}
          {% set avg = states('sensor.badkamer1_humidity_change')|int(default=0) %}
          {% set thresh = 5 %}
          {{ (humid - avg) > thresh }}