Was trying to work through implementing the following to my existing sensors.yaml
There were many fits and starts, modifying the file and then checking on the Developer YAML tab. Have not yet managed to get it right but finally, on my latest effort, I think that I bumped the laptop touchpad on the developer page at the same time I selected Check and restart. Now the function is apparently stuck in a loop with a mostly completed blue circle spinning in the center. Nothing I have tried has made it stop. Re-loading sensors.yaml with a modification, closing the app, etc.
platform: template
sensors:
rainfall_today:
friendly_name: “Rainfall today”
unit_of_measurement: “inches”
state_class: total_increasing
state: >-
{% set count = states(‘sensor.rainsensor_flips’) | int(0) %}
{% set inch = count * 0.01193 %}
{% if count >= 0 %}
{{ inch|round(1, ‘floor’) }}
{% endif %}
# If you have issues with the history sensor doubling after restarting HA, add the line below (@BigG)
availability: “{{ (states(‘sensor.rainsensor_flips’) not in (‘unknown’, ‘unavailable’)) }}”
Three are configured using legacy format (a deprecated but still supported style of defining a Template Sensor).
The fourth one, sensor.rainfall_today, is configured using modern format.
The Template Sensor defined using modern format should not be placed in your sensors.yaml file. It belongs in configuration.yaml under the template: key or in a separate file, such as templates.yaml if your configuration.yaml file contains something like this:
template: !include templates.yaml
In other words, you probably already have the following in your configuration.yaml so that’s why you are putting sensor configurations in sensors.yaml.
sensor: !include sensors.yaml
The same thinking applies to template entities configured in modern format; they go wherever the template: key says they should (directly under the key or in the file it points to).
Hi, Thank you very much for responding.
I created a templates.yaml file and cut/pasted it’s contents from the sensors.file. I spent a lot of time yesterday playing with syntax, spacing, etc to find success. I’ll review the contents of the file and compare it to the original model I’m following.
- platform: template
sensors:
rainfall_today:
friendly_name: "Rainfall today"
unit_of_measurement: "inches"
state_class: total_increasing
state: >-
{% set count = states('sensor.rainsensor_flips') | int(0) %}
{% set inch = count * 0.01193 %}
{% if count >= 0 %}
{{ inch|round(1, 'floor') }}
{% endif %}
# If you have issues with the history sensor doubling after restarting HA, add the line below (@BigG)
availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"
Here is the latest output when I ran Check Configuration on the Yaml Developer page.
Configuration errors
Unexpected error calling config validator: argument of type 'NoneType' is not iterable
Its contents are incorrect. You created a Template Sensor that combines legacy and modern styles resulting in an invalid hybrid. It should be in modern style exclusively (refer to the documentation).
- sensor:
- name: "Rainfall today"
unit_of_measurement: "inches"
state_class: total_increasing
state: >-
{% set count = states('sensor.rainsensor_flips') | int(0) %}
{% set inch = count * 0.01193 %}
{% if count >= 0 %}
{{ inch|round(1, 'floor') }}
{% else %}
{{ this.state | default (0) }}
{% endif %}
availability: "{{ states('sensor.rainsensor_flips') not in ('unknown', 'unavailable') }}"
Thank you.
I corrected it and got no objections upon Check Configuration.
Here’s the current templates.yaml
template:
- sensor:
- name: Rainfall_today
unit_of_measurement: inch
state_class: total_increasing
unique_id: rainfall_today
state: >-
{% set count = states('sensor.rainsensor_flips') | int(0) %}
{% set inch = count * 0.01193 %}
{% if count >= 0 %}
{{ inch|round(1, 'floor') }}
{% endif %}
# If you have issues with the history sensor doubling after restarting HA, add the line below (@BigG)
#availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"
I did however have a log notification.
Logger: homeassistant.config
Source: config.py:623
First occurred: 4:26:29 PM (4 occurrences)
Last logged: 4:35:32 PM
Invalid config for 'template' at templates.yaml, line 1: 'template' is an invalid option for 'template', check: template