Home Energy Management in 2021.8

I simply loved this announcement: 2021.8.0 beta: Feel the energy - Home Assistant (home-assistant.io)

Tried to configure it right away, but unfortunately it won’t let me choose the sensors of my energy meter (Elios4You) that I integrated and used for 1 year (through node-red, that creates all the sensors). It only shows me the utility_meter sensors and the Shelly EM sensors.

This is the sensor for real-time consumption:

image

But it doesn’t appear in the list of sensors to choose:

I thought there was some attributes missing from sensors I created through node-red, and the only one missing was state_class: measurement, so I added it to all NR sensors, but it still doesn’t pick them up. :frowning:

I don’t know what is the filter of that list…and I found no additional info/doc about it.

Thanks for any help solving this, I’d be happy to test and use this new feature.

Alessandro

1 Like

I’d highly recommend you join the Discord and the #beta channel there.

You are right, it’s time to Discord, I never did 'til now. :slight_smile:

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

6 Likes

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

2 Likes

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

1 Like

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?

1 Like

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.

1 Like

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. :slight_smile:

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
2 Likes

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.