hif2k1 / battery_sim

Home assistant home battery simulator - allows you to model how much energy you would save with a home battery
106 stars 13 forks source link

HA restarts cause huge energy spikes #45

Closed DutchessNicole closed 1 year ago

DutchessNicole commented 1 year ago

I've noticed in the last few days that whenever I restart HA either for an update of HAOS or for a HACS module, the battery sim integration gets reloaded with invalid data. This results in the battery suddenly having charged an obscene amount, and in the same time having discharged that same amount into the house.

Screenshot from 2022-09-10 13-06-10

Judging from the amount it adds on a restart there seems to be an issue with it adding sensor.battery_sim_6_0_kwh_battery_total_energy_saved to the daily counter. Total energy saved should of course not be added on a utility counter, I expect it's just there to keep track of the lifetime energy savings.

DutchessNicole commented 1 year ago

This is entirely repeatable, by the way. If I restart again, another spike appears. Screenshot from 2022-09-11 09-03-12

hif2k1 commented 1 year ago

I am looking into this. Initially I thought it the battery must be giving 0 readings immediately after restart, but it's not. I'm trying to reproduce the error now.

hif2k1 commented 1 year ago

I've tried to reproduce this error, but I haven't been able to. What versions of HA and battery_sim are you using?

mpepping commented 1 year ago

Just removed the batterysim sensors from the energy dashboard because of this annoyance, but it was definitely an issue with HA 2022.9.6 (on hassos) /w v1.03 of batterysim. I believe even since version v1.03.

mpepping commented 1 year ago

Just re-enabled the integration to see is it's still an issue with battery_sim_1.061. It still is. Restarting Home Assistant adds a spike to the Energy dashboard graph.

battery_sim_1.061 with Home Assistant 2022.9.7 (Supervisor 2022.09.1 Operating System 9.0 Frontend-versie: 20220907.2)

image

Config used for the integration:

---
# https://github.com/hif2k1/battery_sim
battery_sim:
  5kwh-test:
    name: 5kWh Test
    import_sensor: sensor.dsmr_day_consumption_electricity_merged
    export_sensor: sensor.dsmr_day_consumption_electricity_returned_merged
    size_kwh: 5.0
    max_discharge_rate_kw: 2.0
    max_charge_rate_kw: 2.0
    efficiency: 0.9
    # energy_tariff: 0.35
hif2k1 commented 1 year ago

Thanks for flagging this up. It must be giving 0 readings before the true reading is reloaded making it look like a big increase. I'll try and fix it when I can.

On Sun, 11 Sep 2022, 08:04 Nicole, @.***> wrote:

This is entirely repeatable, by the way. If I restart again, another spike appears. [image: Screenshot from 2022-09-11 09-03-12] https://user-images.githubusercontent.com/1487918/189516217-b096417f-f2f0-4830-8273-8dbeb970f709.png

— Reply to this email directly, view it on GitHub https://github.com/hif2k1/battery_sim/issues/45#issuecomment-1242901700, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAIZGJ4AZ65FWIXEXSDPALV5V76TANCNFSM6AAAAAAQJJJFMU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

hif2k1 commented 1 year ago

I think I have found a solution for this which is in the latest release. The sensors are now marked unavailable until they have a value and hopefully this will prevent the spikes.

DutchessNicole commented 1 year ago

Unfortunately this does not seem to fix the issue. battery sim version 1.07 still exhibits this behaviour during restarts, as I noticed today when performing an update to HAOS 2022.10.5.

Would it help to post some debug logs for the integration?

hif2k1 commented 1 year ago

Yes debug would be helpful. It doesn't happen every restart so it's difficult to track down. It hasn't happened to me yet with the latest version despite a few restarts, but I'll keep looking into it.

There's quite a few similar bug reports with other energy metres and extensions e.g. https://community.home-assistant.io/t/data-spikes-in-the-energy-dashboard/469843 so it's not just battery sim.

On Sat, 22 Oct 2022, 14:50 Nicole, @.***> wrote:

Unfortunately this does not seem to fix the issue. battery sim version 1.07 still exhibits this behaviour during restarts, as I noticed today when performing an update to HAOS 2022.10.5.

Would it help to post some debug logs for the integration?

— Reply to this email directly, view it on GitHub https://github.com/hif2k1/battery_sim/issues/45#issuecomment-1287798871, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAIZGL3IYCAIQW2UZ5O6YLWEPWJNANCNFSM6AAAAAAQJJJFMU . You are receiving this because you modified the open/close state.Message ID: @.***>

DutchessNicole commented 1 year ago

Interesting that you'd say that it doesn't always happen. For me it happens every time HA restarts.

2022-10-24 16:33:56.005 DEBUG (MainThread) [custom_components.battery_sim] Battery update event (battery_sim: 6.0_kWh_battery). Import: 0.004, Export: 0.0
2022-10-24 16:33:56.006 DEBUG (MainThread) [custom_components.battery_sim] Battery (battery_sim: 6.0_kWh_battery) normal mode.
2022-10-24 16:33:56.007 DEBUG (MainThread) [custom_components.battery_sim] Battery update complete (battery_sim: 6.0_kWh_battery). Sensors: {'total energy saved': 105.29, 'battery_energy_out': 105.29, 'battery_energy_in': 105.29, 'current charging rate': 0.0, 'current discharging rate': 0.0, 'simulated grid export after battery charging': 0.016, 'simulated grid import after battery discharging': 224.8289999999999, 'total_money_saved': 45.27, 'Battery_mode_now': 'Empty'}

This is what I see when I simply restart HA. Not a lot is happening but I do notice that both the battery_energy_out and battery_energy_in properties are set to what I assume is the value of total energy saved. Unfortunately debugging doesn't give any more info than this.

Keeping in mind that indeed the linked report does sound very similar, so there could be an underlying issue in HAOS itself that causes this weirdness. Does this log match up with what you see when HA starts up?

for completeness: my logger.yaml

default: error
logs:
  custom_components.battery_sim: debug
hif2k1 commented 1 year ago

I think I might have managed to fix this now with the latest release.

GentleJan commented 1 year ago

looks like it is solved! great

hif2k1 commented 1 year ago

Great, thanks!

On Wed, 7 Dec 2022 at 20:26, GentleJan @.***> wrote:

looks like it is solved! great

— Reply to this email directly, view it on GitHub https://github.com/hif2k1/battery_sim/issues/45#issuecomment-1341548212, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAIZGIEZ7IGESSKTIE4DI3WMDXI5ANCNFSM6AAAAAAQJJJFMU . You are receiving this because you modified the open/close state.Message ID: @.***>

DutchessNicole commented 1 year ago

Very nice! This works a treat. Thanks!