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?