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.
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 ?
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.
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:
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) }}'
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
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?
It should be, are there errors in your logs?
it seem that every time i do a restore the db gets corrupt. i tried it with several backups and get the same error.
“The system will rename the corrupt database file //config/home-assistant_v2.db to //config/home-assistant_v2.db.corrupt.2022-01-28T14:25:15.717211+00:00 in order to allow startup to proceed”
The best advice I can give is to exclude your database from backups or switch to the official maria db addon database.
If you want to properly backup the built in database, your best course of action is to shut down home assistant when backing up that database file (copy/paste). Otherwise there’s always a chance it can get corrupted if a write is occurring during the backup process. From what I can tell, the maria db addon database does not have this issue.
Basically the best method to avoid data corruption is using mysqldump utility. Especially with InnoDB engine in MariaDB.
Hey @WolfsW3lp3!
I had the same crappy thing happening to me. I spent freaking ages trying to sort it out. In the end I found a post somewhere that helped…though I can’t remember where. There may be better andf more elegant ways to do it, but after so many days (probably weeks) of fiddling now that it is working I do not want to touch it!
Here’s my set up:
I have my raw data from the Shelly 3EM which measure three phases. Let’s look at just one of them: sensor.white_phase_energy.
First I filter it to make sure I am not getting garbage from the Shelly. This can happen when the Shelly is momentarily not available or updating, or busy, or whatever…when that happens you don’t want it going spastic:
- unique_id: energy_white_filtered
name: "Energy_White_Filtered"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: >
{% set value = states('sensor.white_phase_energy') | float(default=0) %}
{{ value if value else states('energy_white_filtered') }}
As I recall from the post where I stole this yaml, the state: basically says “take the value of white_phase_energy unless it’s bad in which case stick with what you have”… At this point I will only work with my new sensor sensor.energy_white_filtered.
Next I create another template to establish an energy dashboard sensor:
- unique_id: white_phase
name: "White Phase"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: "{{ states('sensor.energy_white_filtered') | float(default=0) | round(2) }}"
availability: "{{ states('sensor.energy_white_filtered') | int(default=-100000) > -100000 }}"
This block will reject any non integer and ensures that the count can only go up. This might not resolve your drop outs and other weirdness…but it will likely help you ride through it without it making a mess of your consumption stats…
The last step was to edit the Energy Dashboard configuration to use the final entity I created (sensor.white_phase) as the source of your energy consumption data.
In your case I see you also want to do some math on your data - I would do this with the second template sensor (or insert a new sensor in the middle of the two above to make it a three-step process). Definitely don’t do anything until you’ve generate some clean inputs to work with…
Hope this helps!
CP.