Energy Management in Home Assistant

Hi all
I just set up my Energy dashboard and noticed that, every now and then, the systems returns rogue values (possibly because my sensor monitor power instead of energy.

My question is: is there a way to access to the SQL database where the historical data is stored and change the values manually?
I use Smappee that measures power and calculate energy but there is no easy way to import the energy values from its servers. My idea iskeep an eye on Smappee and, if required, amend the values in Home assistant.

Hope it makes sense
Thanks in advance

Please read up this thread there are heaps of these questions.

True but frankly the means to correct erroneous data are hardly user friendly.

You can set up a template sensor that blocks the drops.

sensor:
  - platform: template
    sensors: 
      my_new_sensor_sanitized:
        value_template: "{{ max( states('sensor.sma_sensor_with_drops')|float , states('sensor.my_new_sensor_sanitized')|float) }}"
        unit_of_measurement: kWh

then kick the “raw” sma sensor out of your dashboard and add the new sensor instead.

To make it selectable for the energy dashboard you will have to add customizations to it like:

        state_class: total_increasing #or measurement
        device_class: energy
        last_reset: '2000-01-01T00:00:00'

Hey thanks very much for your reply.
I created a sensor now which looks like this:

- sensor:
    - unique_id: total_solar_producing
      name: 'total_solar_producing'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: "kWh"
      state: "{{ max( (states('sensor.pv_gen_meter')|float + states('sensor.pv_gen_meter_2')|float) , states('sensor.total_solar_producing')|float) }}"
      availability: >-
        {{ states('sensor.pv_gen_meter') not in ['unknown', 'unavailable', 'none', '0'] and 
           states('sensor.pv_gen_meter_2') not in ['unknown', 'unavailable', 'none', '0'] }}

I have two solar seperate Inverters for two solar different solar areas, thats why pv_gen_meter and pv_gen_meter_2.

Is this correct like I did it?

Seems good. Is it a template sensor? The test will be if it produces a smooth line without drops and if you can add it to the energy dashboard.

1 Like

Hi, I’ve been using the Energy Management for a while and it’s all been working well. However the other day I had a power failure and the data feed from the inverter to HA was lost for a few days. I have reset the data feed and although it is now working again, HA is now missing the data for the down period.
I have the missing data in csv format from the inverter, so I was wondering if anyone knows how to load the missing data into HA ?

My solaredge import and export entity states are unknown. What’s happening here?

I think I finally fixed my Energy Management in Home Assistant - #1067 by e-raser misconfiguration from 2021-11-14.

I updated the solution post Energy Management in Home Assistant - #1127 by e-raser and added some learnings from that especially in section 1.

Heyho,

sadly it didn’t help.
Happened again the day before yesterday :frowning:

Any ideas?

1 Like

Norwegian user (and soon swedish) might find this custom integration useful: AMSHAN

The integration can parse data from all norwegian meters. You need a cheap M-BUS USB slave device or another adapter supporting MQTT (like Tibber Pulse) to use the integration.

Is it possible to use 1 entity for consumption as well as back to grid? I have 1 Shelly EM ct clamp installed, is shows negative values when power is going back to the grid and positive values when i consume power. See pictures below:


Screenshot_20220124-160231_Home Assistant

In docs i see net_consumption how do i use this?

You could have some template sensors that calculate the incoming and outgoing by using the max(0) and min(0) functions.

Can you help me out with that? I searched the community, but couldn’t find that kind of template as an example.

I think this should do it. I guessed what your entity_id for the shelley is so just substitute that as needed. Then you need to use the integration sensor for each to create the energy sensors.

template:
   - sensor:
      - name: "Power Import"
        unit_of_measurement: "W"
        state_class: "measurement"
        device_class: "power"
        unique_id: power_imported
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        state: '{{ states.sensor.shelley_power.state | float(0) | max(0) }}'

      - name: "Power Export"
        unit_of_measurement: "W"
        state_class: "measurement"
        device_class: "power"
        unique_id: power_exported
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        state: '{{ states.sensor.shelley_power.state | float(0) | min(0) | multiply(-1) }}'
2 Likes

Thank You, you are the best!

My god i wish i saw this 2 nights ago… Or had SQL-fu

missing stats!
hi i had to do a restore on my system, i only went back one day and im now seeing that all the energy stats are missing not only today i mean all of them :frowning:
anyone else seen this?
//:Erik

they come from your database, if you removed the database then the stats are removed.

i did a full restore! is that not the same database? what am i missing?