home assistant - Putting sensors in separate YAML file leads to errors - Stack Overflow
I recently moved my sensors from configuration.yaml
to a separate sensors.yaml
because my config was getting crowded. I import sensors.yaml
into my configuration.yaml
.
Here's an example of my old sensor configuration (converting m³ to liters):
- platform: template
sensors:
wasserverbrauch_haus_tag_in_liter:
friendly_name: "Wasserverbrauch Haus Tag in Liter"
unit_of_measurement: 'L'
value_template: "{{ states('sensor.wasserverbrauch_haus_tag') | float * 1000 | round(0) }}"
wasserverbrauch_haus_monat_in_liter:
friendly_name: "Wasserverbrauch Haus Monat in Liter"
unit_of_measurement: 'L'
value_template: "{{ states('sensor.wasserverbrauch_haus_monat') | float * 1000 | round(0) }}"
# Similar definitions for other sensors...
After establishing my sensors.yaml
I received the error that my entities (water) don't have a state class anymore. So I added device_class
and state_class
accordingly:
device_class: water
state_class: measurement
However, that led to another error saying my config was invalid. I was advised to change the structure like this:
template:
- sensor:
- name: "Wasserverbrauch Haus Tag in Liter"
unit_of_measurement: 'L'
device_class: water
state_class: measurement
state: "{{ states('sensor.wasserverbrauch_haus_tag') | float * 1000 | round(0) }}"
But I still receive an error, likely due to the template structure.
How can I properly configure my water sensors and retain the historical data?
I recently moved my sensors from configuration.yaml
to a separate sensors.yaml
because my config was getting crowded. I import sensors.yaml
into my configuration.yaml
.
Here's an example of my old sensor configuration (converting m³ to liters):
- platform: template
sensors:
wasserverbrauch_haus_tag_in_liter:
friendly_name: "Wasserverbrauch Haus Tag in Liter"
unit_of_measurement: 'L'
value_template: "{{ states('sensor.wasserverbrauch_haus_tag') | float * 1000 | round(0) }}"
wasserverbrauch_haus_monat_in_liter:
friendly_name: "Wasserverbrauch Haus Monat in Liter"
unit_of_measurement: 'L'
value_template: "{{ states('sensor.wasserverbrauch_haus_monat') | float * 1000 | round(0) }}"
# Similar definitions for other sensors...
After establishing my sensors.yaml
I received the error that my entities (water) don't have a state class anymore. So I added device_class
and state_class
accordingly:
device_class: water
state_class: measurement
However, that led to another error saying my config was invalid. I was advised to change the structure like this:
template:
- sensor:
- name: "Wasserverbrauch Haus Tag in Liter"
unit_of_measurement: 'L'
device_class: water
state_class: measurement
state: "{{ states('sensor.wasserverbrauch_haus_tag') | float * 1000 | round(0) }}"
But I still receive an error, likely due to the template structure.
How can I properly configure my water sensors and retain the historical data?
Share Improve this question edited 20 hours ago jonrsharpe 122k30 gold badges263 silver badges469 bronze badges asked 20 hours ago JulianJulian 1051 gold badge4 silver badges8 bronze badges 5 |1 Answer
Reset to default 0I think you are mixing the legacy and the modern template sensor configuration.
For the legacy configuration (quote from the docs: "This format still works but is no longer recommended") to work with a separate sensors.yaml
, your configuration.yaml
should contain the following line
# configuration.yaml
sensor: !include path/to/sensors.yaml # adjust path as needed
and sensors.yaml
should contain the template sensor configured like this
- platform: template
sensors:
test_sensor:
friendly_name: "Test Sensor in sensors.yaml"
value_template: "{{ True }}" # required
# ...
For the modern template sensor configuration to work, your configuration.yaml
should look like this
template: !include path/to/templates.yaml # adjust path as needed
and templates.yaml
should follow the following format
- sensor:
- name: "Test Sensor in templates.yaml" # NOTE 'name' instead of 'friendly_name'
state: "{{ True }}" # required # NOTE 'state' instead of 'value_template'
Additional sensor variables for both configurations are described in the documentation linked above.
Notes:
- The filename used in
configuration.yaml
does not matter. What's important is that the key (sensor: !include ...
,template: !include ...
, ...) matches the format/structure of the content included in that file.
Last tested on Home Assistant 2024.12
- 2013年科技行业推出的失败产品(组图)
- powershell - Windows AutoPilot - Set Auto Login - Stack Overflow
- Why does this typecheck in Lean? - Stack Overflow
- Unable to create a azure synapse workspace? - Stack Overflow
- electron - Windows task scheduler triggers the task but it is not invoking the app which I want to open on system login - Stack
- reactjs - When i run the build command on my project, the dist files aren't being created in the correct format - Stack
- gdal - Using gdal_translate to compress multiple TIFF files - Stack Overflow
- dart - Flutter - dyld: lazy symbol binding failed: Symbol not found: _os_log_create - Stack Overflow
- installation - Upgrading to Inno Setup v6 - SignTool=sha1 no longer works - Stack Overflow
- azure - .Net Core C# IMAP integration for outlook - Stack Overflow
- c++ - How to create a class setup where two classes each holds an instance of the other? - Stack Overflow
- reactjs - NextAuth cookie not being sent when I use the development server, but being sent when I use HoppscotchBrowser to send
- java - Reproduce NullPointerException on Stream.toList() method - Stack Overflow
- Compare two lists, one of them JSON, in SQLite - Stack Overflow
- React native - OCR of price tag - Stack Overflow
- javascript - Turning a horizontal scroll image gallery for desktop (using vertical scroll gesture) into a vertical scroll galler
- amazon web services - Python boto3: download files from s3 to local only if there are differences between s3 files and local one
sensors.yaml
intoconfiguration.yaml
? Like so:sensor: !include path/to/sensor.yaml
? – coreuter Commented 5 hours ago- platform: template sensors: test_sensor: ...
is working fine insensors.yaml
for me (just created that sensor). That's why I asked for additional information. – coreuter Commented 4 hours ago