I have a utility meter, which reports the positive and negative values based on the usage. (Emporia Vue)
I’m trying to make two sensors using this - Positive sensor and Negative sensor (To use it on Energy Dashboard)
Below are the template sensors:
- platform: template
sensors:
gridpowerin:
friendly_name: Grid Power In
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
value_template: >
{% if states('sensor.utility_meter_123_1d') | float(0) >= 0 %}
{% set gridin = states('sensor.utility_meter_123_1d') | float(0) %}
{% else %}
{% set gridin = 0 %}
{% endif %}
{{ gridin }}
- platform: template
sensors:
gridpowerout:
friendly_name: Grid Power Out
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
value_template: >
{% if states('sensor.utility_meter_123_1d') | float(0) <= 0 %}
{% set gridout = states('sensor.utility_meter_123_1d') |float | abs %}
{% else %}
{% set gridout = 0 %}
{% endif %}
{{ gridout }}
Configuration error:
Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->gridpowerin->state_class. (See ?, line ?).
Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->gridpowerout->state_class. (See ?, line ?).
If I remove the state_class, it works perfectly and reports the numbers perfectly as well. But im unable to use these new sensors in Energy dashboard as state_class is blank.
The legacy template sensor format does not support state_class. You should be using the new format for template sensors as the legacy template sensor format is no longer receiving new features.
Sorry if it’s basic, but am I supposed to change all my template sensors to a modern configuration?
Because I just copy pasted your code and my configuration is failing stating my old template sensors have issue
Error:
Error loading /config/configuration.yaml: while parsing a block collection
in “/config/sensor.yaml”, line 2, column 1
expected , but found ‘?’
in “/config/sensor.yaml”, line 132, column 1
Initial code of my sensor.yaml
#Number of lights on template
- platform: template
sensors:
lights_on_counter:
friendly_name: Lights on counter
value_template: >-
{{ states.light
|rejectattr('attributes.entity_id', 'defined')
|selectattr('state', 'eq', 'on')
|list
|count
}}
icon_template: mdi:lightbulb-group
#Number of lights on template