https://www.home-assistant.io/integrations/template/#state-based-template-sensors
Have found it:
(from 123)
The documentation doesn’t show the
state_class
option for legacy Template Sensor. My understanding is that the energy integration includes entities containing that option (and set tomeasurement
). Without that option, the entity is excluded.Easy way to find out is to convert one or more of your Template Sensors from legacy to the new format and add
state_class: measurement
.
https://community.home-assistant.io/t/2021-8-0-feel-the-energy/326853/83
It is not working anyway.
I’ve created this new sensor:
template:
- sensor:
- name: "power_all_new"
unit_of_measurement: "Вт"
state_class: measurement
state: >
{% set room = states('sensor.load_04cf8cdf3c867ea8') | float %}
{% set fridge = states('sensor.load_00158d00039c0362') | float %}
{{ (room + fridge) | round(1) }}
Also I’ve customized it like this (see Energy: Not showing the expected entities for consumption - #12 by francisp):
sensor.power_all_new:
last_reset: '1970-01-01T00:00:00+00:00'
device_class: energy
state_class: measurement
But this new sensor power_all_new
still is not showing on the new energy consumption page.
New sensor indeed has the measurement
option:
Maybe you habe to wait:
After setting up a new device, it can take up to 2 hours for new data to arrive in your energy dashboard.
It seems that the sensor with unit kWh is needed. Not the ordinary Watts! It works now.
Of course, a sensor that shows Watts measures power, but you need an energy sensor (power over time).
My energy integration stopped updating the graph? No errors anywhere I can see. Any suggestions on how to fix or what to check?
Thanks all for your info in this post, it’s been helping me to progress this. Unfortunately I’ve not be able to get it working and I’ve tried both old and new template sensors.
I’m using a Shelly EM which works great and sends its data using MQTT. Here’s a simple card with the data items:
Here is the sensor defintion (shame the new method cant use friendly_name):
template:
- sensor:
- name: "house_energy_kwh"
# friendly_name_template: "House Energy (Total)"
unit_of_measurement: "kWh"
state_class: measurement
device_class: energy
state: >
{% set phase1 = states('sensor.shellyem3_8caab561f4aa_channel_a_energy') | float %}
{% set phase2 = states('sensor.shellyem3_8caab561f4aa_channel_b_energy') | float %}
{% set phase3 = states('sensor.shellyem3_8caab561f4aa_channel_c_energy') | float %}
{{ float(phase1) + float(phase2) + float(phase3) }}
Here is the active sensor definition:
For some reason the new “Energy” configuration UI will not allow me select the “sensor.house_energy_kwh” entity as the “Grid Consumption” sensor:
Ive got the point where after 4 hours of trial and error i’m giving up for a while in the hope that HA will recognise the entity in the “Energy” UI once its populated with some more data…
Any and all ideas are welcome. Thx
The ‘some’ reason is : there is no last_reset attribute.
template:
- sensor:
- name: "house_energy_kwh"
# friendly_name_template: "House Energy (Total)"
unit_of_measurement: "kWh"
state_class: measurement
device_class: energy
state: >
{% set phase1 = states('sensor.shellyem3_8caab561f4aa_channel_a_energy') | float %}
{% set phase2 = states('sensor.shellyem3_8caab561f4aa_channel_b_energy') | float %}
{% set phase3 = states('sensor.shellyem3_8caab561f4aa_channel_c_energy') | float %}
{{ float(phase1) + float(phase2) + float(phase3) }}
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
Thanks @fancisp, that worked a treat and now I just need to wait for the values to populate. Thanks again and I hope this helps others
I have a problem too.
The “cost” is not recalculated to me.
But in the interface, the data is displayed.
My localization is “RU”
What am I doing wrong. Thanks
sensor:
- platform: integration
source: sensor.charger_volt_power
name: energy_spent
round: 2
I’m fighting with this, but no success, maybe someone can help?
Got you! I have changed W to Wh, however, nothing show up again, do I need to restert HA?
UPDATE:
Ok so what you need to do in order for the thing to work: make sure you have Energy kWh measurement in your system, I have it in configuration file.
If you have Power, which is instant measurements, you can change it to kWh, which mend that if you use instant data 1 hr and devide it to 1000 you will have kWh:
- name: Pgrid
address: 25214
scan_interval: 10
slave: 4
input_type: holding
scale: 0.001
offset: 0
unit_of_measurement: "kWh"
precision: 1
device_class: energy
Then you should go to Configuration tab → Customization and find your device there and add state class: measurement:
Hit SAVE, check again your configuration files and restart HA!
And you still get nothing )))
Below two devices, one is MQTT and it works, other MODBUS and it doesn’t!
unit_of_measurement: kWh
friendly_name: Pgrid
device_class: energy
state_class: measurement
state_class: measurement
unit_of_measurement: kWh
friendly_name: Washing_Machine ENERGY Total
device_class: energy
You still need a last_reset
Where to add this?
You can’t do that.Use the integration integration
And use the left method.
Thanks, will try!
No success, I have added the following into sensor.yaml as you proposed:
- platform: integration
source: sensor.power
name: solar_energy
unit_prefix: k
round: 2
method: left
, restarted HA and still nothing:
UPDATE:
I have checked STATES and here what I get, I think problem is with unit of measurements, will fix and report back!
Just wait a little. The integration produces results once an hour. And that kwhh I just saw