bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
1.02k stars 262 forks source link

value warnings (skipping, not increasing, ...) #2664

Open emufan opened 2 days ago

emufan commented 2 days ago

System Health details

System Information

version core-2024.11.1
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.6.54-haos
arch aarch64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 4999 Installed Version | 2.0.1 Stage | running Available Repositories | 1471 Downloaded Repositories | 50
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | 30. August 2025 um 02:00 relayer_connected | true relayer_region | eu-central-1 remote_enabled | false remote_connected | false alexa_enabled | true google_enabled | false cloud_ice_servers_enabled | true remote_server | eu-central-1-5.ui.nabu.casa certificate_status | ready instance_id | b8cb37779da4460485728e3fe9669c94 can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 13.2 -- | -- update_channel | stable supervisor_version | supervisor-2024.11.2 agent_version | 1.6.0 docker_version | 27.2.0 disk_total | 113.9 GB disk_used | 17.0 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | odroid-n2 supervisor_api | ok version_api | ok installed_addons | Samba share (12.3.2), File editor (5.8.0), Samba Backup (5.2.0), Studio Code Server (5.17.3), Advanced SSH & Web Terminal (19.0.0), Mosquitto broker (6.4.1), SQLite Web (4.2.2), eufy-security-ws (1.9.1), Matter Server (6.6.0)
Dashboards dashboards | 8 -- | -- resources | 29 views | 34 mode | storage
Recorder oldest_recorder_run | 6. November 2024 um 12:19 -- | -- current_recorder_run | 11. November 2024 um 17:33 estimated_db_size | 2716.09 MiB database_engine | sqlite database_version | 3.45.3

Checklist

Describe the issue

Yesterday I updated to 2024.11.1 and newerst powercalc. Coming from older version 2024.6 (because of AMP problems until .11).

Until then, the powercalc sensors never had any issues. But after the updates I now get tons of waring messages. Over and over again.

Reproduction steps

1. 2. 3. ...

Debug logs

Entity sensor.flur_energy_counter from integration powercalc has state class total_increasing, but its state is not strictly increasing. Triggered by state 102437.0115 (102.43701159999999) with last_updated set to 2024-11-11T17:34:15.827418+00:00. Please create a bug report at https://github.com/bramstroker/homeassistant-powercalc/issues
Entity sensor.wohnzimmerschrank_energy_counter from integration powercalc has state class total_increasing, but its state is not strictly increasing. Triggered by state 60295.8292 (60.295829299999994) with last_updated set to 2024-11-11T18:39:15.890206+00:00. Please create a bug report at https://github.com/bramstroker/homeassistant-powercalc/issues
Entity sensor.rollladen_energy_counter from integration powercalc has state class total_increasing, but its state is not strictly increasing. Triggered by state 113682.0750 (113.6820751) with last_updated set to 2024-11-11T23:19:16.000900+00:00. Please create a bug report at https://github.com/bramstroker/homeassistant-powercalc/issues
Entity sensor.kaffeemaschine_energy_counter from integration powercalc has state class total_increasing, but its state is not strictly increasing. Triggered by state 165053.6017 (165.0536018) with last_updated set to 2024-11-12T07:14:18.034208+00:00. Please create a bug report at https://github.com/bramstroker/homeassistant-powercalc/issues

or

skipping state for sensor.badezimmer_hinten_rechts_energy_counter, probably erroneous value or sensor was reset
skipping state for sensor.roomba_energy_counter, probably erroneous value or sensor was reset
skipping state for sensor.nachttischschrank_links_energy_counter, probably erroneous value or sensor was reset

Diagnostics dump or YAML config

No response

bramstroker commented 1 day ago

Sorry you are experiencing issues after HA and integration upgrades.

Unfortunately I'm not sure, never seen this error before.

Looking at the code where this error is raised in HA it logs an error when the state of the sensor is decreasing. Triggered by state 113682.0750 (113.6820751) 113682.0750 is the newly received state, 113.6820751 latest recorded.

Seems to be some decimal issue going on where decimals have shifted 3 positions, but I assume the first value is the in Wh and the second one in kWh. It's only an issue in the logging. So that would mean 113.6820750 is the new value and 113.6820751 the old value, thus the energy sensor is decreasing.

That must be some bug in the rieman integral sensor code, as that's what powercalc is using under the hood for the energy sensor.

Very hard one to debug as I don't have this issue and never heard about is before, and it's only happening on your system.

Few ideas from the top of my head to debug:

  1. Are you using mariaDB of mysqlite as DB engine? Would be nice if you can check out the states table where HA records all the states, to see what is exactly going on.

  2. Might also be an idea to enable debug logging for integration integration (this is the rieman sum heloer)

logger:
  logs:
    homeassistant.components.integration: debug
  1. Create an energy sensor using the core HA helper (Rieman sum), for one of the problematic sensors. for example sensor.flur_energy_counter. Let it run for a bit, and see if it gives the same error.

Could you also share how you configured sensor.flur_energy_counter in Powercalc? And also if you have any additional global configuration defined?

emufan commented 1 day ago

Thanks for the quick reply.

ad 1. mysqlite. I will try to finde the values.

ad 2. Will do it.

ad 3. Will try as well.

ad 3. Defined this way

    - name: Flur
      entity_id: light.flur
      standby_power: 0.3
      fixed:
        power: 175

Here some debug log for the second kind of errors above

2024-11-12 17:34:51.990 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] delta for entity sensor.kinderzimmer_mitte_hinten_energy_counter: -0.0001, prev=8698.0752, cur=8698.0751
2024-11-12 17:34:51.991 WARNING (MainThread) [custom_components.powercalc.sensors.group.custom] skipping state for sensor.kinderzimmer_mitte_hinten_energy_counter, probably erroneous value or sensor was reset

defined this way

    - create_group: Kinderzimmerdecke
      unique_id: unique_id_powercalc_kinderzimmerdecke
      entities:
        - entity_id: light.kinderzimmer_vorn
        - entity_id: light.kinderzimmer_mitte_vorn
        - entity_id: light.kinderzimmer_mitte_hinten
        - entity_id: light.kinderzimmer_hinten

where the devices are hue lights.

bramstroker commented 1 day ago

Second one is related to powercalc group sensors. Log lines with custom_components.powercalc.sensors.group.custom That's calculation routine which is part of powercalc.

Might be a one time issue. as there were some changes few months ago as how the group sensors calculate. I suggest to monitor this a few days and after several reboots. If this issue persists please let me know, than I'll dig further.

emufan commented 1 day ago

Somehow curious.

Here one example

Entity sensor.sonos_schlafzimmer_energy_counter from integration powercalc has state class total_increasing, but its state is not strictly increasing. Triggered by state 54477.3155 (54.477315600000004) with last_updated set to 2024-11-13T00:49:50.415118+00:00. Please create a bug report at https://github.com/bramstroker/homeassistant-powercalc/issues

defined this way

    - entity_id: media_player.sonos_schlafzimmer
      standby_power: 4.2
      fixed:
        power: 4.2
        states_power:
          playing: 5.7

with this settings

powercalc:
  enable_autodiscovery: false

  #  force_update_frequency: 00:10:00 #Default
  force_update_frequency: 00:05:00

  power_sensor_naming: "{} power"
  power_sensor_friendly_naming: "{} POWER"

  create_energy_sensors: true
  energy_sensor_unit_prefix: none
  energy_integration_method: left
  energy_sensor_naming: "{} energy_counter"
  energy_sensor_friendly_naming: "{} ENERGY_COUNTER"

  create_utility_meters: true
  utility_meter_types:
    - daily
    - weekly
    - monthly
    - yearly

Powercalc created sensor sensor.sonos_schlafzimmer_power is stable:

247712208 | NULL | 4.20| NULL | NULL | NULL | 0 | AZL1vbR3UsmJkIUHW3n5vA== | NULL | NULL | 48
247713276 | NULL | 4.20| NULL | NULL | NULL | 0 | AZL1wkiABVY5akkRKqZx+Q== | NULL | NULL | 48

but here we go

250642590 | NULL | 54478.3656 | NULL | NULL | NULL | NULL | 1731459890.4247851 | NULL | 1731459890.4247851 | 250641590 | 41137989 | NULL | NULL | NULL | 0 | AZMjDTz437Bh6m91iumTVA== | NULL | NULL | 209
250641590 | NULL | 54478.0156 | NULL | NULL | NULL | NULL | 1731459590.4237404 | NULL | 1731459590.4221025 | 250640659 | 41137989 | NULL | NULL | NULL | 0 | AZMjCKkWzKoft+rsTPpFGw== | NULL | NULL | 209
250640659 | NULL | 54477.6655 | NULL | NULL | NULL | NULL | 1731459290.4148781 | NULL | 1731459290.4148781 | 250639802 | 41137989 | NULL | NULL | NULL | 0 | AZMjBBUunB1Rh8CY6ckAfg== | NULL | NULL | 209
250639802 | NULL | 54477.3155 | NULL | NULL | NULL | NULL | 1731458990.415118 | NULL | 1731458990.415118 | 250639698 | 41137989 | NULL | NULL | NULL | 0 | AZMi/4FPS6afXGlkWlB2Cg== | NULL | NULL | 209
250639698 | NULL | 54477.3156 | NULL | NULL | NULL | NULL | 1731458990.414866 | NULL | 1731458990.414866 | 250638769 | 41137989 | NULL | NULL | NULL | 0 | AZMi/4FOYgJJ2wf6QFSjvw== | NULL | NULL | 209
250638769 | NULL | 54476.9655 | NULL | NULL | NULL | NULL | 1731458690.4140928 | NULL | 1731458690.4140928 | 250637894 | 41137989 | NULL | NULL | NULL | 0 | AZMi+u1uh2KvJlt2OYpHlQ== | NULL | NULL | 209

Converted timestamps from the last 4 entries

Mittwoch, 13. November 2024 01:54:50.414 GMT+01:00
Mittwoch, 13. November 2024 01:49:50.415 GMT+01:00
Mittwoch, 13. November 2024 01:49:50.414 GMT+01:00
Mittwoch, 13. November 2024 01:44:50.414 GMT+01:00

So:

bramstroker commented 1 day ago

Seems integration is calculated twice at the same time, which you already noticed. That would probably be the cause of the issue. Calculating new integration should be triggered each time the power sensor changes state. Could you have a look into state changes of the power sensor?

emufan commented 1 day ago

SELECT * FROM "states" where metadata_id = 48 and last_reported_ts >= 1731457800 and last_reported_ts <= 1731459890.4247851

250639697 | NULL | 4.20 | NULL | NULL | NULL | NULL | 1731458990.4145453 | NULL | 1731458990.4145453 | 250638768 | 52591169 | NULL | NULL | NULL | 0 | AZMi/4FOHNLYIlnHSmykhg== | NULL | NULL | 48
250640658 | NULL | 4.20 | NULL | NULL | NULL | NULL | 1731459290.414584 | NULL | 1731459290.414584 | 250639697 | 52591169 | NULL | NULL | NULL | 0 | AZMjBBUufHwrQbwFfdtqag== | NULL | NULL | 48
250641589 | NULL | 4.20 | NULL | NULL | NULL | NULL | 1731459590.4219007 | NULL | 1731459590.4219007 | 250640658 | 52591169 | NULL | NULL | NULL | 0 | AZMjCKkVlfu2lhP516GyRQ== | NULL | NULL | 48
250642589 | NULL | 4.20 | NULL | NULL | NULL | NULL | 1731459890.4239852 | NULL | 1731459890.4239852 | 250641589 | 52591169 | NULL | NULL | NULL | 0 | AZMjDTz3cyst3z2fge+Y8A== | NULL | NULL | 48
250640658 | NULL | 4.20 | NULL | NULL | NULL | NULL | 1731459290.414584 | NULL | 1731459290.414584 | 250639697 | 52591169 | NULL | NULL | NULL | 0 | AZMjBBUufHwrQbwFfdtqag== | NULL | NULL | 48

converted (and sorted)

Mittwoch, 13. November 2024 02:04:50.423 [GMT+01:00]
Mittwoch, 13. November 2024 01:59:50.421 [GMT+01:00]
Mittwoch, 13. November 2024 01:54:50.414 [GMT+01:00]
Mittwoch, 13. November 2024 01:49:50.414 [GMT+01:00}
Mittwoch, 13. November 2024 01:44:50.413 [GMT+01:00]

So no multiple updates.

bramstroker commented 1 day ago

Could you try to create energy sensor using Riemann sum helper using HA helpers and see how that one goes?