I’m using Shelly 3em for analyzing the whole energy flow and Shelly em for analyzing the solar panel supply. So far so good. After installation and configuration of a script everything is running fine, except the sensor “Energy export daily” cannot be chosen at adjustments/dashboards because it simply not available. At the overview screen its available but without any unit like Wh or kWh.
Even restart, or simply waiting (recommendation from script writer) did not help . Any idea? Bug from HA?
thx for help
Rudi
You need to define the correct device and state classes for your template sensors. The state_class can only be defined in the new template integration (unless you want to use a customize hack). You are using the legacy template sensor platform.
e.g. delete the template sensors above (leave the Riemann Sum sensors) and replace them with this in your configuration.yaml file
There is also an issue with your “Power Consumption” template sensor. See the comments in it below.
template:
sensor:
# Template sensor for values of power import (active_power > 0)
- name: "Power Import"
unit_of_measurement: 'W'
state_class: measurement
device_class: power
state: >
{% if states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) > 0 %}
{{ states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) }}
{% else %}
0
{% endif %}
availability: >
{{
[ states('sensor.shelly_em3_channel_a_power'),
states('sensor.shelly_em3_channel_b_power'),
states('sensor.shelly_em3_channel_c_power')
] | map('is_number') | min
}}
# Template sensor for values of power export (active_power < 0)
- name: "Power Export"
unit_of_measurement: 'W'
state_class: measurement
device_class: power
state: >
{% if states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) < 0 %}
{{ (states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0))|abs }}
{% else %}
0
{% endif %}
availability: >
{{
[ states('sensor.shelly_em3_channel_a_power'),
states('sensor.shelly_em3_channel_b_power'),
states('sensor.shelly_em3_channel_c_power')
] | map('is_number') | min
}}
# Template sensor for values of power consumption
- name: "Power Consumption"
unit_of_measurement: 'W'
state_class: measurement
device_class: power
state: >
{% if states('sensor.power_export')|float(0) > 0 and states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0) < 0 %}
{# You are missing a print statement here. #}
{# if you want to keep the previous state use this: #}
{{ this.state }}
{% elif states('sensor.power_export')|float(0) > 0 and states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0) > 0 %}
{{ states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0) }}
{% else %}
{{ states('sensor.power_import')|float(0) + states('sensor.power_solargen')|float(0) }}
{% endif %}
availability: >
{{
[ states('sensor.power_export'),
states('sensor.power_solargen'),
states('sensor.power_import')
] | map('is_number') | min
}}
My HA shows exactly the same result and “Invalid config” message when I use the template above:
Blockquote
Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’].
Got [{‘name’: ‘Power Import’, ‘unit_of_measurement’: ‘W’, ‘state_class’: ‘measurement’, ‘device_class’: ‘power’, ‘state’: "{% if states(‘sensor.shelly_em3_channel_a_power’)|float(0) + states(‘sensor.shelly_em3_channel_b_power’)|float(0) + states(‘sensor.shelly_em3_channel_c_power’)|float(0) > 0 %}\n {{ states(‘sensor.shelly_em3_channel_a_power’)|float(0) + states(‘sensor.shelly_em3_channel_b_power’)|float(0) + states(‘sensor.shelly_em3_channel_c_power’)|float(0) }}\n{% else %}\n 0\n{% endif %}.… (See ?, line ?).
So I switched back to the configuration I found somewhere else, which is working fine except the “energy daily sensor” which for unknown reasons under developer tools > statistics does not show the measurement “kWh”. See attached screengrab. Neverless it records the daily export as expected.
Since the measurement “kWh” is available for the “energy monthly sensor” which was created with exactly the same configuration, I also think, that in HA something is not working as expected.
Finally it seems that the missing measurement “kWh” for the daily export sensor is the reason, that it cannot be selected in the energy dashboard.
Thx for your reply. Unfortunately it still throws an error.
Blockquote
Invalid config for [template]: [value_template] is an invalid option for [template]. Check: template->sensor->2->value_template. (See /config/configuration.yaml, line 45).
Alright, sorry, after 1000 tries I did not see that.
I have cleaned up everything, reentered the (now hopefully correct) configuration, but still it does not work.
Latest Configuration:
sensor:
# Sensor for Riemann sum of energy import (W -> Wh)
- platform: integration
source: sensor.power_import
name: energy_import_sum
unit_prefix: k
round: 2
method: left
# Sensor for Riemann sum of energy export (W -> Wh)
- platform: integration
source: sensor.power_export
name: energy_export_sum
unit_prefix: k
round: 2
method: left
# Sensor for Riemann sum of energy consumption (W -> Wh)
- platform: integration
source: sensor.power_consumption
name: energy_consumption_sum
unit_prefix: k
round: 2
method: left
template:
- sensor:
# Template sensor for values of power import (active_power > 0)
- name: "Power Import"
unit_of_measurement: 'W'
state_class: measurement
device_class: power
state: >
{% if states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) > 0 %}
{{ states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) }}
{% else %}
0
{% endif %}
availability: >
{{
[ states('sensor.shelly_em3_channel_a_power'),
states('sensor.shelly_em3_channel_b_power'),
states('sensor.shelly_em3_channel_c_power')
] | map('is_number') | min
}}
# Template sensor for values of power export (active_power < 0)
- name: "Power Export"
unit_of_measurement: 'W'
state_class: measurement
device_class: power
state: >
{% if states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) < 0 %}
{{ (states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0))|abs }}
{% else %}
0
{% endif %}
availability: >
{{
[ states('sensor.shelly_em3_channel_a_power'),
states('sensor.shelly_em3_channel_b_power'),
states('sensor.shelly_em3_channel_c_power')
] | map('is_number') | min
}}
# Template sensor for values of power consumption
- name: "Power Consumption"
unit_of_measurement: 'W'
value_template: >-
{% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) < 0 %}
{% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
{{ (states('sensor.power_solargen')|float(0)) - states('sensor.power_export')|float(0) }}
{% else %}
{{ states('sensor.power_import')|float(0) + states('sensor.power_solargen')|float(0) }}
{% endif %}
utility_meter:
energy_import_daily:
source: sensor.energy_import_sum
name: Energy Import Daily
cycle: daily
energy_import_monthly:
source: sensor.energy_import_sum
name: Energy Import Monthly
cycle: monthly
energy_export_daily:
source: sensor.energy_export_sum
name: Energy Export Daily
cycle: daily
energy_export_monthly:
source: sensor.energy_export_sum
name: Energy Export Monthly
cycle: monthly
energy_consumption_daily:
source: sensor.energy_consumption_sum
name: Energy Consumption Daily
cycle: daily
energy_consumption_monthly:
source: sensor.energy_consumption_sum
name: Energy Consumption Monthly
cycle: monthly
Error in log instantly after checking DevTools > Check Configuration
Logger: homeassistant.config
Source: config.py:982
First occurred: 6:03:48 PM (1 occurrences)
Last logged: 6:03:48 PM
Invalid config for [template]: [value_template] is an invalid option for [template]. Check: template->sensor->2->value_template. (See /config/configuration.yaml, line 41).
Unfortunately due to limitations I am not allowed to add further replies - will reuse this post for further information
First of all: Thx for your patience, now I got it …
The problem was already in that post #7. I have fixed it and configuration loads as expected.
Finally this is the configuration I used, the result is below
sensor:
# Sensor for Riemann sum of energy import (W -> Wh)
- platform: integration
source: sensor.power_import
name: energy_import_sum
unit_prefix: k
round: 2
method: left
# Sensor for Riemann sum of energy export (W -> Wh)
- platform: integration
source: sensor.power_export
name: energy_export_sum
unit_prefix: k
round: 2
method: left
# Sensor for Riemann sum of energy consumption (W -> Wh)
- platform: integration
source: sensor.power_consumption
name: energy_consumption_sum
unit_prefix: k
round: 2
method: left
template:
- sensor:
# Template sensor for values of power import (active_power > 0)
- name: "Power Import"
unit_of_measurement: 'W'
state_class: measurement
device_class: power
state: >
{% if states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) > 0 %}
{{ states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) }}
{% else %}
0
{% endif %}
availability: >
{{
[ states('sensor.shelly_em3_channel_a_power'),
states('sensor.shelly_em3_channel_b_power'),
states('sensor.shelly_em3_channel_c_power')
] | map('is_number') | min
}}
# Template sensor for values of power export (active_power < 0)
- name: "Power Export"
unit_of_measurement: 'W'
state_class: measurement
device_class: power
state: >
{% if states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0) < 0 %}
{{ (states('sensor.shelly_em3_channel_a_power')|float(0) + states('sensor.shelly_em3_channel_b_power')|float(0) + states('sensor.shelly_em3_channel_c_power')|float(0))|abs }}
{% else %}
0
{% endif %}
availability: >
{{
[ states('sensor.shelly_em3_channel_a_power'),
states('sensor.shelly_em3_channel_b_power'),
states('sensor.shelly_em3_channel_c_power')
] | map('is_number') | min
}}
# Template sensor for values of power consumption
- name: "Power Consumption"
unit_of_measurement: 'W'
state_class: measurement
device_class: power
state: >
{% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) < 0 %}
{% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
{{ (states('sensor.power_solargen')|float(0)) - states('sensor.power_export')|float(0) }}
{% else %}
{{ states('sensor.power_import')|float(0) + states('sensor.power_solargen')|float(0) }}
{% endif %}
utility_meter:
energy_import_daily:
source: sensor.energy_import_sum
name: Energy Import Daily
cycle: daily
energy_import_monthly:
source: sensor.energy_import_sum
name: Energy Import Monthly
cycle: monthly
energy_export_daily:
source: sensor.energy_export_sum
name: Energy Export Daily
cycle: daily
energy_export_monthly:
source: sensor.energy_export_sum
name: Energy Export Monthly
cycle: monthly
energy_consumption_daily:
source: sensor.energy_consumption_sum
name: Energy Consumption Daily
cycle: daily
energy_consumption_monthly:
source: sensor.energy_consumption_sum
name: Energy Consumption Monthly
cycle: monthly
Unfortunately the sensor “Energy export daily” still has no unit “kWh”, while the sensor “Energy export monthly”, which was recreated at the very same time, has the unit “kWh”. The sensor “Energy export daily” is working and collecting data, but still it cannot be selected for the Energy dashboard.
Update, 2023-05-26
Since I cannot add further replies (I am rated as beginner), I’ll add the reply to your latest post here:
Yes, I have exported energy to the net.
DevTools > Statistics checked: There is no Fix Issue Button. It shows “no issue”
DevTools > Stats checked: Energy Export Daily does not show attributes “unit_of_measurement” and “device_class”. Even after removing and recreating the attributes have not changed as shown in the next screengrab.