Home Energy Management in 2021.8

You ask too much for a v1.0 version of an integration. But you can open a Feature Request on github.

Remember that an official integration can never cover all use-cases, but it has to be structured in a flexible way, so that everybody can use data as they prefer. And I think they’re on the right track.

Since data is in the statistics long-term db, I’m sure you will be able to do many things by yourself, with grafana and other tools.

Hi all.
I have few question about this integration that I can’t find answers in documentation.

  1. According to documentation one of the possible state_class values should be “total_increasing” which would be perfect as I assume most energy measuring devices (at least the ones I encountered) provide only cumulative reading for kWh. But I can’t get it to work. Anyone had any luck wit it?
  2. What data does HA expect when state_class i set to “measurement”? I would assume that given that kWh is time related value it would just sum all the measurements over the hour as they come in to get a total for an hour. But I’ve seen people here talking about converting real time W readout to kWh which is not really possible without taking time between measurements into account.

Never tried it. I use lifetime sensors, they always increase, and I use state_class: measurement and total_reset attribute set to UNIX epoch time 0.

Read this: Sensor Entity | Home Assistant Developer Docs


In my opinion, the definition of messurement and total_increasing is ambiguous: for the former they write “accumulated energy consumption” and for the latter “amount of consumed energy”, which practically is the same thing.

I never tried total_increasing, but I think it’d be more appropriate for a lifetime sensor, and probably it would also imply that last_reset is not needed. But if you say it doesn’t work, I’ll stick to measurement+last_reset combo.

They are probably referring to the Riemann sum integral integration to calculate that.

1 Like

Thanks for the answer. I’ll try the measurement class with the settings you suggested.

total_increasing only works on the dev versions right now and is scheduled for release with 2021.9, so you’ll need to make sure you are running a dev version for it to work

2 Likes

Thanks for the info!

I think I misunderstood the documentation. I thought that the way Energy integration accumulates data depends on the state_class value. But I just got my first stat in the Energy panel and it looks like it just registered the increase over the time and not the accumulated sensor value.
That is what I would expect from integration like this but the documentation threw me off the track and made me overthink things. :slight_smile:

If you know pvoutput.org, it works the same way: when you configure the sensor you specify what kind of sensor it is through those attributes so the integration knows how to interpret and manage the values.

it’s more simple than it seems at first glance. :slight_smile:

1 Like

good to know, when it’ll be official, it will also be documented so I will switch to total_increasing. thanks.

1 Like

I’m not familiar with pvoutput.org yet but probably will in the near future - we just got our PV system installed and now we are waiting for the grid operator to accept the paperwork and install a new meter so we can get it online. It’s why I started playing with the energy integration (I was initially planing to set up something using template sensors but since it’s there why not use it :slight_smile: )

Thanks for the help again, it works like expected :slight_smile:

1 Like

Great to know it’s working now. I’ve had a PV system for 10y, If you need any help feel free to ping me. :slight_smile:

1 Like

How do i disable this?

Remove the default config and specify the bits you want.

I am having trouble in HA to let me select the entities to monitor.

It only shows some of them.
The big issue is that the KwH sensor is made by the sum of two sensors, and that sensor is not displaying.

  - platform: template
    sensors:
      # Energia TOTAL
      shelly_total_consumption:
        friendly_name: Energía Total
        icon_template: mdi:counter
        device_class: energy
        unit_of_measurement: "KWh"
        value_template: "{{(states('sensor.shelly_shem_c5d7_1_total_consumption') | float + states('sensor.shelly_shem_4b4a_1_total_consumption') | float) | round(2)}}"
        availability_template: >
          {% if is_state("sensor.shelly_shem_c5d7_1_total_consumption", "unavailable") %}
            false
          {% elif is_state("sensor.shelly_shem_4b4a_1_total_consumption", "unavailable") %}
            false
          {% else %}
            true
          {%- endif %}
      # Consumo actual TOTAL
      shelly_current_consumption:
        friendly_name: Consumo Total
        icon_template: mdi:flash-outline
        device_class: energy
        unit_of_measurement: "W"
        value_template: "{{(states('sensor.shelly_shem_c5d7_1_current_consumption') | float + states('sensor.shelly_shem_4b4a_1_current_consumption') | float) | round(0)}}"
        availability_template: >
          {% if is_state("sensor.shelly_shem_c5d7_1_current_consumption", "unavailable") %}
            false
          {% elif is_state("sensor.shelly_shem_4b4a_1_current_consumption", "unavailable") %}
            false
          {% else %}
            true
          {%- endif %}

I have added the line:

        device_class: energy

But in the system tools I get:

unit_of_measurement: KWh
friendly_name: Energía Total
icon: mdi:counter
device_class: energy

What do I need to do in order to get it to be able to be selected on the energy settings panel.

device_class is not enough, you also need state_class. Read this, a few posts above yours: Home Energy Management in 2021.8 - #105 by alexdelprete

The unit of measurement is wrong: if device_class is energy, unit must be Wh or kWh.

Make sure all power/energy sensors have the correct unit of measurement, the correct device_class, the correct state_class.

Hi to all,
i’ve just configured my energy panel on Home Assistant.
Like the image below i think there is an issue in solar energy consumed.
I don’t know why but it’s impossibile that i’ve consumed a few watts of solar energy.

I’ve three template sensors:

  • grid_import in kwh
  • grid_export in kwh
  • solar prodution

Any ideas?
Thank you so much for any help.
Regards,

Alessandro

I can’t see the values on the image, too small. You should show the Sources table of the energy card, below that one you showed, to see the overall values.

What are the values of the 3 sensors? Are they different vs the card? If the values of the sensors are what you see on the card, the problem is in the sensors.

Thanks for reply Alessandro!
This is my sources part:

…and all my sensor templates:

grid_export_khw:

- platform : template
    sensors:
      grid_export:
        friendly_name: "Grid Export"
        icon_template: mdi:flash
        unit_of_measurement: "W"
        value_template: >
          {% if (states('sensor.shelly_shem_b9e60b_1_current_consumption') | int - states('sensor.power_ac_fronius_inverter_1_http_192_168_1_102') | int) > 0 %}
            0
          {% else -%}
            {{ (states('sensor.shelly_shem_b9e60b_1_current_consumption') | int - states('sensor.power_ac_fronius_inverter_1_http_192_168_1_102') | int) | abs }}
          {% endif %}

grid_import:

- platform: template
    sensors:
      grid_import:
        friendly_name: "Grid Import"
        icon_template: mdi:flash
        unit_of_measurement: "W"
        value_template: >
          {% if (states('sensor.shelly_shem_b9e60b_1_current_consumption') | int - states('sensor.power_ac_fronius_inverter_1_http_192_168_1_102') | int) > 0 %}
            {{ (states('sensor.shelly_shem_b9e60b_1_current_consumption') | int - states('sensor.power_ac_fronius_inverter_1_http_192_168_1_102') | int) }}
          {% else -%}
            0
          {% endif %}

solar_production:

- platform: template
    sensors:
      solar_production:
        friendly_name: "Produzione Fotovoltaico"
        icon_template: mdi:flash
        unit_of_measurement: "W"
        value_template: >
          {% if (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_102') | float(default=0) | round(2, default=0)) > 0 %}
            {{ (states('sensor.power_ac_fronius_inverter_1_http_192_168_1_102') | float(default=0) | round(2, default=0)) }}
          {% else -%}
            0.00
          {% endif %}

That’s all.
Thanks for your support.
Regards,

Alessandro

If production is 12,27kw, you can’t have exported 18,39kw. Your sensors are not calculated correctly.

Can you show me the values of those sensors (grid_import, grid_export, solar_production) and their attributes, from dev tools?

Show me also sensor.shelly_shem_b9e60b_1_current_consumption, what does that Shelly EM sensor measure? Is it a total counter that always increases or instantaneous value? Is it power or energy? The name consumption in the sensor leads me too think you chose the wrong sensors.

Shelly EM has two values: energy and energy returned, and it’s in kWh, not in W.

image

Those template sensors don’t measure energy but power, as you’re using the power_ac from Fronius.

It’s total chaos. :slight_smile:

The Energy Integration needs ENERGY sensors, in kWh, for production, import, and export.

Sorry Alessandro,
i’ve posted incorrect images :see_no_evil:
All my sensors in energy panel is in kwh and all sensors are energy not power:

grid_import:

grid_export:

solar_production:

shelly_contatore:

Thanks again!

Alessandro

Which images are wrong?

This sensor is measuring instantaneous power, not energy.

This template is doing calculations among two power sensors, and it’s in W, not kWh, because it’s measuring power. But you’re using it for energy.

- platform : template
    sensors:
      grid_export:
        friendly_name: "Grid Export"
        icon_template: mdi:flash
        unit_of_measurement: "W"
        value_template: >
          {% if (states('sensor.shelly_shem_b9e60b_1_current_consumption') | int - states('sensor.power_ac_fronius_inverter_1_http_192_168_1_102') | int) > 0 %}
            0
          {% else -%}
            {{ (states('sensor.shelly_shem_b9e60b_1_current_consumption') | int - states('sensor.power_ac_fronius_inverter_1_http_192_168_1_102') | int) | abs }}
          {% endif %}

Show me all entities available for that shelly EM device, you need to pick the energy entities, not the power entities. Shelly EM provides both power and energy values, also energy returned.

The Fronius integration should provide energy produced as a total increasing counter, in W normally, but we can see it from the attributes of the sensor. You picked a Power entity from Fronius, not the energy entity.