Quick Bathroom Fan Humidity Switch Control

im no coder but this looks like something i need :slight_smile: , but i cant put in the code can you show were to put the codes i have the different files i think

i have automations , statistics and the binary sensor in but were to put the Additional Options: ?? and how i don`t get it can some on please show

master_bath_humidity_threshold:
 name: Master Bath Humidity Threshold
 min: 0
 max: 20
 initial: 5
 mode: box
 step: 1

and also, in the binary sensor above, replace

{% set thresh = 5 %}

with

{% set thresh = states('input_number.master_bath_humidity_threshold')|int(default=0) 

can you show full code and were to put it ,i love to compare whit others humidity sensors but i have no ideer were to put what you show here

i wood love to compare whit others humidity sensors but i have no ideer were to put the code you show

@Markus99 The only change I made to Mark’s code above is:

sensor:

  - platform: statistics
    name: Bill Bathroom Average Linear 24h
    entity_id: sensor.bill_br_govee5075_humidity
    state_characteristic: average_linear
    max_age:
      hours: 24
    sampling_size: 2880

I did this as I was seeing big spikes in the average when the shower was on.

This eliminated the spikes I was seeing ( graph above). Still not sure why it does not trigger on the 5% threshold on the on condition. The off is working correctly.

I am graphing the delta (Current humidity - Ave) and I am seeing spikes that can’t be true.

I found this is caused by my humidity sensor giving a wrong reading. I am trying figure out what is causing it and hopefully I can then get it to trigger correctly.

I looked at both the humidity and average sensor and neither has any spikes. Not sure how one minus the other could get these spikes?

I just ran the shower and for some reason it doesn’t turn the fan on until 80 % (reading was 48 %). Turned off at 53 which seems correct.

What I did to smooth out the delta sensor was change the hours to 3 and the samples to 360. Before this was was getting triggers with the :shower: off of humid days.

In configuration.yaml under a “template:” section.

Template - Home Assistant (home-assistant.io)

I was able to smooth out my “delta senor” by changing the template to:

platform: template
sensors:

  bill_bath_delta_humidity:
    friendly_name: "bill_bath_delta_humidity"
    unit_of_measurement: '%'
    value_template: >
          {{(states('sensor.bill_br_govee5075_humidity') | float - 
          states('sensor.bill_bathroom_average_linear_3h') | float) |round (1)}}
    availability_template: "{{states('sensor.bill_br_govee5075_humidity') | is_number and states('sensor.bill_bathroom_average_linear_3h') | is_number}}"

I must have been getting some unavailable data points.

2 Likes

hi. first thank you for the templates. decided to attempt to fix my broken sensors after a long overdue update to home assistant.

im having issues with the automation side of things. when debugging, i get the error-

Error: Error rendering service name template: UndefinedError: 'dict object' has no attribute 'to_state'


this is my automation

alias: bathroom fan auto on
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.bathroom_humid
    for:
      hours: 0
      minutes: 0
      seconds: 30
condition: []
action:
  - data:
      entity_id: switch.bathroom_fan
    service_template: switch.turn_{{trigger.to_state.state}}
mode: single

am i missing some thing here?

Define “when debugging”

If you mean running the automation manually then the error is expected as triggers are bypassed and the action relies on a trigger attribute in this case (which does not exist).

N00b-question: in what configfile do I put the ‘Binary Sensor’-part?

If you are a N00b, then in configuration.yaml with binary_sensor: above it.
Alternatively if you have a binary_sensors.yaml or similar it can go in there.

Once you get the hang of configuration splitting the truth is you can put it in any yaml file that is appropriately included or part of a package.

Thanks! The check config keeps pointing out I need to add a platform:. So I’ve tried: running, sensor, bath_room etc. But it keep saying: Platform error binary_sensor.Fan - Integration ‘Fan’ not found.
I can’t figure out how to move on…

Post your whole code snippet

sensor:
  - platform: statistics
    name: Bathroom Humidity Average Linear 24h
    entity_id: sensor.badkamer_ventilator_am2301_humidity
    state_characteristic: average_linear
    max_age:
      hours: 24

binary_sensor:
  - platform: running
    bath_fan_sb:
      friendly_name: Bathroom Fan S/B Status
      value_template: >-
        {% set humid = states('sensor.badkamer_ventilator_am2301_humidity')|int(default=0) %}
        {% set avg = states('sensor.bathroom_humidity_average_linear_24h')|int(default=0) %}
        {% set thresh = 5 %}
        {{ (humid - avg) > thresh }}

This platform does not exist. So HA does not know what to do.

Looks like this binary sensor is a template? If so please follow the template document, and I cite jerrm in post #25:

Okay, completely lost you. If it’s supposed to be a template, why does the original author didn’t mention this? Don’t know how to convert from original setup to template. :disappointed_relieved:

I happened to post my codes the other day.

Thank you very much! I implement it in my configuration.yaml now without any errors. Hopefully it works. Much appreciated!

I’m having issues with this portion of the automation. Can you clear this up for me? Saying “String does not match pattern of deprecated.” Thanks!

Can you post your code for this? Just checked my automation and it’s showing the same as you’ve quoted above.

When I trace the last execution of the automation, here’s part of the ‘changed variables’ section that is being leveraged between the {{ }}

image