ageurtse
(Arnold)
November 23, 2022, 4:01pm
1
I’m trying to add a template sensor, but when checking i get an error Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]
Why is this happening, and how to solve this.
this is what i have in a sepparate file, which is loading as a sensor
- platform: template
sensors:
s0energie:
unit_of_measurement: kWh
value_template: "{{ (states('counter.energieopgewekt')|float / 2000 ) | round(1) }}"
device_class: energy
state_class: total_increasing
energieopgewekt, is a helper which is added through the GUI.
i made an automation, that on every puls the counter is incereased with 1
ageurtse
(Arnold)
November 23, 2022, 4:27pm
3
When leaving the state_class the sensor is accepted. So it’s not the brackets
ageurtse:
s0energie:
Try without the 0 (zero), I cannot test this
parautenbach
(Pieter Rautenbach)
November 23, 2022, 4:54pm
5
You’re using the legacy format which doesn’t support a state class.
Either convert it to a modern template sensor or put the state class in your customize.yaml
.
ageurtse
(Arnold)
November 23, 2022, 6:25pm
6
Is it possible to load legacy files en modern tenplate files at ones.
Now i think i have them all as legacy files.
parautenbach
(Pieter Rautenbach)
November 23, 2022, 7:51pm
7
Yes, you can have both. They’re configured under different sections.
ageurtse
(Arnold)
November 23, 2022, 8:00pm
8
Then i have to look in the documentation where to put these new modern sensor templates.
I post the solution as a follow up as solution
[edit]
I tryed this, the config check says no error, all good to go.
But after restarting, the sensor isn’t visible.
i loaded as a sensor file.
template:
- sensor:
- name: "so1energie"
unit_of_measurement: kWh
state: "{{ (states('counter.energieopgewekt')|float / 2000 ) | round(1) }}"
device_class: energy
state_class: total_increasing
parautenbach
(Pieter Rautenbach)
November 24, 2022, 6:00am
9
ageurtse:
counter.energieopgewekt
Did this have a value when you checked the value of the new template sensor after reload/startup?
If you have that configuration in a separate file, is your main configuration.yaml
referencing it?
ageurtse
(Arnold)
November 24, 2022, 6:44am
10
Yes it has a value and should be loaded, all files in the directory are loaded
ageurtse
(Arnold)
November 24, 2022, 5:17pm
11
found the solution, a template in the modern style, should be loaded from within template, not from sensor.
here is a part of the config file
group: !include groups.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include_dir_merge_list entities/sensors
binary_sensor: !include_dir_merge_list entities/binary
utility_meter: !include_dir_merge_named entities/utility_meters
automation: !include automations.yaml
template: !include_dir_merge_list entities/template
and the final template file
- sensor:
- name: "so1energie"
unit_of_measurement: "kWh"
state: "{{ (states('counter.energieopgewekt')|float / 2000 ) | round(1) }}"
device_class: energy
state_class: total_increasing
so this could now be closed
4 Likes
robb1
(Robert Brown)
February 25, 2023, 4:36am
13
I have a different result. Here is my configuration.yaml
sensor:
- platform: template
sensors:
energy_to_grid:
friendly_name: "Energy To Grid"
value_template: "{{ states.sensor.solaxmine.attributes['data'][0]['dataDict'][10].value }}"
device_class: energy
unit_of_measurement: 'kWh'
I have the following in customize.yaml
sensor.energy_to_grid:
unit_of_measurement: kWh
friendly_name: Energy To Grid
device_class: energy
state_class: total_increasing
but the energy dashboard expects a state_class.
What am I missing please?
Am I not calling the customize.yaml correctly somewhere?
robb1
(Robert Brown)
February 25, 2023, 4:55am
14
Answering myself. I needed
homeassistant:
customize: !include customize.yaml
It had been deleted from an earlier edit of config.yaml.