Hi Thom. Do you mind to share your automation:
- Turn the fan on when humidity exceeds 70%
Fiddling around with it for some time now based on your “Switch fan to OFF” but can not find a sweet spot.
Thank you in advance.
Hi Thom. Do you mind to share your automation:
Fiddling around with it for some time now based on your “Switch fan to OFF” but can not find a sweet spot.
Thank you in advance.
Hey there, not sure what you are struggling with as this automation is rather simple. Should be something like this:
- trigger:
- platform: numeric_state
entity_id: sensor.bad_raumsensor_bme280_humidity
above: 70
action:
- service: switch.turn_on
entity_id: switch.bad_luftung
Thank you for your reply.
I am using a similar automation. However, the bathroom exhaust fans seem to switch ON/OFF kind of uncontrolled.
Since I live in a tropical country with a fast changing average humidity between 72% - 79% I may have to work on the sensor (max_age & sampling_size) to get this working correctly.
I just use % humidity above 57%, if that happens I want the fan to start. At least where I live that works well. I have 2 bathrooms, both with the same ventilation fan (house fan) so I check the triggering sensor to set the fan back to medium speed. If the sensor does not come down to below 53% after 1h 30m then set to medium speed anyway (that never happens).
alias: House Ventilation Fan Automasjon
description: Turn on ventilation fan to max when someone is in the shower
trigger:
- type: humidity
platform: device
device_id: 3d2eb894b7e477272c3ba089e22c8348
entity_id: b363171b2d3789ea19c6df9990153ebb
domain: sensor
above: 57
id: moist-1
- type: humidity
platform: device
device_id: ee22b3674c83e100c9f03ef1be8b6f1d
entity_id: 34e6631b03658e2e75091a730d80f5b2
domain: sensor
above: 57
id: moist-u
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- moist-1
sequence:
- service: fan.set_percentage
metadata: {}
data:
percentage: 100
target:
entity_id: fan.house_vent_fan
- wait_for_trigger:
- type: humidity
platform: device
device_id: 3d2eb894b7e477272c3ba089e22c8348
entity_id: b363171b2d3789ea19c6df9990153ebb
domain: sensor
below: 53
continue_on_timeout: true
timeout:
hours: 1
minutes: 30
seconds: 0
milliseconds: 0
- service: fan.set_percentage
metadata: {}
data:
percentage: 66
target:
entity_id: fan.house_vent_fan
- conditions:
- condition: trigger
id:
- moist-u
sequence:
- service: fan.set_percentage
metadata: {}
data:
percentage: 100
target:
entity_id: fan.house_vent_fan
- wait_for_trigger:
- type: humidity
platform: device
device_id: ee22b3674c83e100c9f03ef1be8b6f1d
entity_id: 34e6631b03658e2e75091a730d80f5b2
domain: sensor
below: 53
continue_on_timeout: true
timeout:
hours: 1
minutes: 30
seconds: 0
milliseconds: 0
- service: fan.set_percentage
metadata: {}
data:
percentage: 66
target:
entity_id: fan.house_vent_fan
mode: single
Hey corvy,
that you can always do. It’s the easy approach which should be good enough for most use cases.
What I found is that your relative humidity change via a fan depends on the outside humidity (air intake). Therefore, a simple trigger by relative humidity % will switch the ventilation on too early or off too late.
My approach using humidity change automation from above worked pretty well in an apartment bathroom.
In another use case of mine to ventilate a basement room, I went with something that is commonly refered to as “dew point ventilation”.
Yeah I see that and I guess this could also be done in my use case. I can see that the sensor moves at least 5% when someone showers, unless many shower in a row.
I will give this a closer look into my use-case.
thank you very much for this code. i added 4 sensors using this code (i have 2 bathrooms ;-)) :
## Badkamer showering
sensor:
- platform: statistics
name: Badkamer Humidity Stats
entity_id: sensor.badkamer_humtemp_badkamer_humtemp_humidity_air
state_characteristic: mean
sampling_size: 40
max_age:
hours: 1
- platform: statistics
name: Badkamer Boven Humidity Stats
entity_id: sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air
state_characteristic: mean
sampling_size: 40
max_age:
hours: 1
binary_sensor:
- platform: template
sensors:
badkamer_showering:
value_template: '{{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}'
friendly_name: Badkamer Showering
device_class: occupancy
- platform: template
sensors:
badkamer_boven_showering:
value_template: '{{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}'
friendly_name: Badkamer Boven Showering
device_class: occupancy
Unfortunately i get now errors in the logs:
2024-10-26 12:25:03.150 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: 'None' has no attribute 'state'') while processing template 'Template<template=({{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}) renders=8>' for attribute '_state' in entity 'binary_sensor.badkamer_showering'
2024-10-26 12:25:25.028 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}) renders=2>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 632, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2729, in _render_with_context
return template.render(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2367, in forgiving_int_filter
raise_no_default("int", value)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1905, in raise_no_default
raise ValueError(
ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}' but no default was specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 749, in async_render_to_info
render_info._result = self.async_render( # noqa: SLF001
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 634, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}' but no default was specified
2024-10-26 12:25:25.036 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}' but no default was specified') while processing template 'Template<template=({{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}) renders=4>' for attribute '_state' in entity 'binary_sensor.badkamer_showering'
2024-10-26 12:25:25.041 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}) renders=2>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 632, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2729, in _render_with_context
return template.render(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2367, in forgiving_int_filter
raise_no_default("int", value)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1905, in raise_no_default
raise ValueError(
ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}' but no default was specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 749, in async_render_to_info
render_info._result = self.async_render( # noqa: SLF001
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 634, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}' but no default was specified
2024-10-26 12:25:25.047 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}' but no default was specified') while processing template 'Template<template=({{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}) renders=4>' for attribute '_state' in entity 'binary_sensor.badkamer_boven_showering'
2024-10-26 12:25:29.874 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: 'None' has no attribute 'state'') while processing template 'Template<template=({{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}) renders=8>' for attribute '_state' in entity 'binary_sensor.badkamer_showering'
2024-10-26 12:25:29.875 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: 'None' has no attribute 'state'') while processing template 'Template<template=({{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}) renders=8>' for attribute '_state' in entity 'binary_sensor.badkamer_boven_showering'
2024-10-26 12:25:29.942 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}) renders=2>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 632, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2729, in _render_with_context
return template.render(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2367, in forgiving_int_filter
raise_no_default("int", value)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1905, in raise_no_default
raise ValueError(
ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}' but no default was specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 749, in async_render_to_info
render_info._result = self.async_render( # noqa: SLF001
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 634, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}' but no default was specified
2024-10-26 12:25:29.946 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}' but no default was specified') while processing template 'Template<template=({{ states.sensor.badkamer_humtemp_badkamer_humtemp_humidity_air.state | int > states.sensor.badkamer_humidity_stats.state | int and states.sensor.badkamer_humidity_stats.state != "unknown" }}) renders=4>' for attribute '_state' in entity 'binary_sensor.badkamer_showering'
2024-10-26 12:25:29.948 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}) renders=2>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 632, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2729, in _render_with_context
return template.render(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2367, in forgiving_int_filter
raise_no_default("int", value)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1905, in raise_no_default
raise ValueError(
ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}' but no default was specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 749, in async_render_to_info
render_info._result = self.async_render( # noqa: SLF001
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 634, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}' but no default was specified
2024-10-26 12:25:29.952 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: int got invalid input 'unavailable' when rendering template '{{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}' but no default was specified') while processing template 'Template<template=({{ states.sensor.badkamer_boven_humptemp_badkamer_boven_humptemp_humidity_air.state | int > states.sensor.badkamer_boven_humidity_stats.state | int and states.sensor.badkamer_boven_humidity_stats.state != "unknown" }}) renders=4>' for attribute '_state' in entity 'binary_sensor.badkamer_boven_showering'
The general error (which is repeated in different variants) seems to be: got input ‘unvailable’ but no default was specified…
I am new to home assistant, so i have no clue how to troubleshoot this. Can anyone help?