You are right, it’s time to Discord, I never did 'til now.
Thank you.
You are right, it’s time to Discord, I never did 'til now.
Thank you.
In case someone else stumbles on this and wonders about the answer…
The sensors shown on the list have to have these attributes:
@balloob: “Meter entities have device class “energy”, have a state_class “measurement” and a last_reset value”
Source: Discord
And @Mariusthvdb added this helpful comment:
@Mariusthvdb: if not set by any other integration, simply customize your kWh sensors with:
homeassistant:
customize_glob:
sensor.*_energy:
last_reset: '1970-01-01T00:00:00+00:00'
device_class: energy
state_class: measurement
Source: Discord
Please don’t use that. It is incorrect. last_reset
is not a string, but a datetime object. This is incorrect and will cause issues.
EDIT: Ok, I stand corrected, it is smashed to a string in the state engine, so indeed. That will work
thanks Franck, I put it in my NR as a string. I’ll put it as a datetime.
Is there a recommended value to use for a lifetime sensor?
If the time of initialization is unknown and the meter will never reset, set to UNIX epoch 0:
homeassistant.util.dt.utc_from_timestamp(0)
{{ 0 | timestamp_utc }} is 1970-01-01 00:00:00, this should work too.
I stand corrected: as @balloob said, customize comes after internal conversion to ISO8601 has already been made, so this works: {{ as_datetime(0|timestamp_utc).isoformat() }}
→ 1970-01-01T00:00:00
UPDATE: the above works for the scope of last_reset, but in order to be offset-aware, timezone has to be included, so in case you need it:
{{ as_datetime(as_datetime(0|timestamp_utc)|string+‘Z’).isoformat() }}
Output: 1970-01-01T00:00:00+00:00
Although I will wait until 2021.8 is released, I started updating my mqtt and template sensors to include device_class
and state_class
where appropriate. I came across a quirk (2021.7.4) where my template sensor configured in “Legacy” mode (i.e. sensor: platform: template: sensors) does not allow me to add state_class
. Will state_class be added in 2021.8 to “Legacy” mode, or do I have to convert my “Legacy” mode to “Modern” mode (template: -sensor:) in order to add the state_class
?
I would advice to use the “modern” syntax. It’s future-proof, and state_class is probably the first example of why it’s better to switch to the new style.
But you could also use this:
homeassistant:
customize_glob:
sensor.*_energy:
last_reset: '1970-01-01T00:00:00+00:00'
device_class: energy
state_class: measurement
Hi,
Thanks @alexdelprete for sharing from Discord.
I have an ESPHome based telemetry kit for my electrical counter.
I already have implemented the measurement and energy class and plan to customize the entities with last_reset
on Home-Assistant side as it is not something to do on ESPHome side if I understood correctly.
My sensors are in WH. Should I convert values in my ESPHome config file to KwH to use them?
I don’t know ESPhome unfortunately, so can’t advice how to do it with it, but I prefer to modify it where the sensors are created, if possible. I try to avoid using customize, even if it works. In my case, I use NR to read my home energy meter, and sensors are created in a flow, so it was really easy customizing them adding the needed attributes. If you can’t modify the sensors in ESPhome, then you can use customize global entries.
They have settled on kWh, reading the discussions on discord, so the answer is yes.
Would it be possible to let ESPhome add these attributes automatically to “total daily energy” sensors? Total Daily Energy Sensor — ESPHome
Now, none of my smart plugs (on ESPhome) is listed in the HA Energy module, because the required sensor attributes are missing.
Read the post above yours. And a couple of posts before, there’s the customize configuration that should work in your case.
I have indeed read the previous posts, but wanted to add if there would be a way to avoid these customizations. If we specify a total daily energy sensor in ESPhome, the required attributes for HA energy could be added automatically?
In the post before yours I said I don’t know esphome and I avoid using customize if possible.
You could open an issue on esphome integration.
Nice option! But i don’t see the animated picture with the flow from solar panels and the grid when i have entered my entities.
since 2021.8b9 you can have the energy card in lovelace: Energy Cards - Home Assistant (home-assistant.io)
Here’s the code to replicate the “official” card:
- title: Home Energy
path: home-energy
icon: mdi:solar-power
badges: []
cards:
- type: energy-date-selection
view_layout:
position: sidebar
- title: Energy usage
type: energy-usage-graph
- title: Solar production
type: energy-solar-graph
- title: Energy distribution
type: energy-distribution
view_layout:
position: sidebar
- title: Sources
type: energy-sources-table
- type: energy-solar-consumed-gauge
view_layout:
position: sidebar
- type: energy-grid-neutrality-gauge
view_layout:
position: sidebar
- type: energy-carbon-consumed-gauge
view_layout:
position: sidebar
- title: Monitor individual devices
type: energy-devices-graph
type: sidebar
you need to be sure the sensors have the appropriate attributes, read the posts above.
I’ve done all customisations with my energy sensors - i have 3 sensors for each tariff zone.
All of them (t1, t2, t3) have similar attributes and states different data in kWh
unit_of_measurement: kWh
friendly_name: T1
last_reset: '1970-01-01T00:00:00+00:00'
device_class: energy
state_class: measurement
I’ve added all of them to Energy section, but still have no data on graph.
What’s wrong ?
Upd. In few hours it started to show some data. But it’s unclear how it works, and also is there any way to calibrate this data - to put my starting values.