homeassistant-powercalc icon indicating copy to clipboard operation
homeassistant-powercalc copied to clipboard

A sensor grouping power sensors went crazy

Open michalk-k opened this issue 1 year ago • 5 comments

System Health details

System Information

version core-2024.6.4
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 5.10.17-v8
arch aarch64
timezone Europe/Prague
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 5000
Installed Version 1.34.0
Stage running
Available Repositories 1390
Downloaded Repositories 35
Home Assistant Cloud
logged_in true
subscription_expiration August 14, 2024 at 02:00
relayer_connected true
relayer_region eu-central-1
remote_enabled true
remote_connected true
alexa_enabled false
google_enabled false
remote_server eu-central-1-4.ui.nabu.casa
certificate_status ready
instance_id 3cb0d3fbab1e44f98797c10448afb4d1
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 6.6
update_channel stable
supervisor_version supervisor-2024.06.2
agent_version 1.2.1
docker_version 20.10.8
disk_total 109.3 GB
disk_used 19.9 GB
healthy true
supported failed to load: Unsupported
host_connectivity true
supervisor_connectivity true
ntp_synchronized true
virtualization
board rpi4-64
supervisor_api ok
version_api ok
installed_addons Advanced SSH & Web Terminal (18.0.0), Studio Code Server (5.15.0), Mosquitto broker (6.4.1), File editor (5.8.0), Glances (0.21.1), Node-RED (18.0.2), Home Assistant Google Drive Backup (0.112.1), Log Viewer (0.17.0), UniFi Network Application (3.1.0), Zigbee2MQTT (1.39.0-1)
Dashboards
dashboards 10
resources 26
views 63
mode storage
Recorder
oldest_recorder_run August 4, 2024 at 13:27
current_recorder_run August 4, 2024 at 23:01
estimated_db_size 2003.11 MiB
database_engine sqlite
database_version 3.44.2

Checklist

  • [X] I have read the FAQ to see if there is a known solution to my problem.
  • [X] I have enabled debug logging for my installation.
  • [X] I have filled out the issue template to the best of my ability.
  • [X] This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • [X] This issue is not a duplicate issue of currently previous issues..

Describe the issue

Recently one of PowerCalc started to generate impossible values.

Here are involved entities:

  1. Bedroom socket (energy) - PowerCalc sensor generated from the power sensor below
    • pg_socket_bedroom_power - PowerCalc sensor groups 2 sensors being a source for one above
      • Bedroom Wall Lights Negative Power
      • plug_bedroom Socket 3 Power.

image

It seems that it's caused by the interruption of power measurement of Bedroom Walllights Negative Power entity Having both images one below another, the correlation seems obvious.

image

Have no exact times, but this day I did multiple restarts of HA. Those holes in measurement may be related to that. Potentially, bad data might have been triggered by HA restart.

Since this started to happening, Bedroom socket energy PowerCalc sensor reports skipping state ... probably erroneous value or sensor was reset flooding HA logs, so I lost the moment the situation started to happening.

image

image

I'm not expecting any instant fix or so. I can imagine it might be near impossible. Just wanted to notify it happens the. Currently I disabled this entity, have to clean statistics data of 2 recent days for entities handling light energy. (several). But don't know what to do with this power PowerCalc entity. HOw to reset it, or have I drop it and create again

Reproduction steps

...

Debug logs

No logs for something that has already happened

Diagnostics dump or YAML config

No response

michalk-k avatar Aug 06 '24 08:08 michalk-k

Powercalc groups does not support negative figures for an energy sensor. It expects it to only ever increase in value. So that would probably be the reason for this issue. Not sure how a wall switch in your bedroom is generating power?

I might have a look into supporting negative energy for powercalc groups in the future. For now I will make sure to put a note in the docs.

If you want to clean up history data of the power entity I think you'll need to alter data in statistics and statistics_short_term tables in the DB.

bramstroker avatar Aug 09 '24 06:08 bramstroker

Good catch with this negative values sensor

I have a template sensor representing the negative power of lights because those lights share the same source with other non-lights devices. So to measure the power of the latter, I have to reduce the consumption of the whole string by light power.

It worked this way for a really long time. Interestingly, you are saying it might be the culprit of the issue. If it's sensitive to that, I had to workaround it a different way.

Thank you

michalk-k avatar Aug 10 '24 06:08 michalk-k

@bramstroker I have real troubles to fix those data. Every time I update bad data to proper values, the subsequently created record into statistics and short term ones includes the unwanted value. Ie I reduced selected historical records by about 200kWh, but then the next created record gets again 200kWh over expected value.

I was supposing the recorder, so turned it off for the time needed for this operation, then restarted HA, but it didn't help. Tried to stop whole HA, but then I had no access to sqllite editor (yes, I can copy the db to PC, update data and upload fixed db back)

Do you know the easier method? Maybe disabling sensors created by PowerCalc and then enabling them afterward? ... Something less invasive than moving db file out of HA.

michalk-k avatar Aug 10 '24 14:08 michalk-k

@michalk-k I suspect restore data data, which powercalc and other HA entities uses to restore the sensor to latest known value after startup. These are stored in config/.storage/core.restore_state. Also powercalc stores last know state of individual energy entities in config/.storage/powercalc_group. You could have a look into both files and correct the data there. Next restart. Hope this solves the issue.

bramstroker avatar Aug 10 '24 17:08 bramstroker

Btw, today I worked on a subtracting group sensor. Just finished that development, will be in next release. Might also be useful for your use case:

https://docs.powercalc.nl/sensor-types/group/subtract/

bramstroker avatar Aug 10 '24 18:08 bramstroker

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 10 '24 01:09 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Sep 15 '24 02:09 github-actions[bot]