home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.76k stars 30.47k forks source link

Rieman sum bug: Integration not updating correctly #102057

Closed AleXSR700 closed 7 months ago

AleXSR700 commented 1 year ago

The problem

The rieman sum integration only updates on changes of the source sensors' value, which may seemed like the correct approach, but leads to an incorrect and illogical value.

The Rieman sum usually creates a total energy value in Wh or kWh, i.e. an hour based value.

When the source sensor remains at a constant value, then the integrattion never updates and reports 0 Wh of consumption, even if the source sensor were to consume e.g. 1 kWh.

Here is an example where a sensor constantly consumes 33.5 W which leads to a 0 Wh consumption according to the Rieman sum and hence according to all Energy readings in HA (e.g. Energy dashboard). image

image

A much better approach would be to update at least once per hour (as it is an hourly integration) e.g. at 1 sec past the hour, or let the user define a minimum update interval. Alternative of coure being the default 1 min update period which updates the value but does not write to the database unless the value changes.

What version of Home Assistant Core has the issue?

2023-10.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Integration - Riemann sum integral

Link to integration documentation on our website

https://www.home-assistant.io/integrations/integration/

Diagnostics information

No response

Example YAML snippet

template:
  - sensor:
    - name: "Fixed Value Consumers ENERGY Power"
      unique_id: fixed_value_consumers_energy_power
      state: 
            "{{
              states                      
                | selectattr('entity_id', 'in', integration_entities('tasmota'))
                | map(attribute='entity_id') 
                | select('has_value')
                | map('device_attr', 'name')
                | unique
                | list
                | count
                +13.5
            }}" # updates every minute without needing trigger because it is state related. +13 for Router
      unit_of_measurement: "W"
      state_class: measurement
      device_class: power # needed for the rieman sum to automatically register as device_class: energy
    trigger:
      - platform: time_pattern
        minutes: /30

sensor:
  - platform: integration   # rieman sum
    source: sensor.fixed_value_consumers_energy_power
    name: "Fixed Value Consumers ENERGY Total"
    unique_id: fixed_value_consumers_energy_total

utility_meter:
  fixed_value_consumers_energy_today:
    name: "Fixed Value Consumers ENERGY Today"
    unique_id: fixed_value_consumers_energy_today
    source: sensor.fixed_value_consumers_energy_total
    cycle: daily

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @dgomes, mind taking a look at this issue as it has been labeled with an integration (integration) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `integration` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign integration` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


integration documentation integration source (message by IssueLinks)

dotdoom commented 12 months ago

You may want to put a thumbs up at #88940

janfromberlin commented 10 months ago

In Addition, I suggest the option ( or default behavior? ) to interprete the „unavailable“ State of a sensor as decimal 0. In combination with the hourly update, It would resolve dozens of issues. Many problems are related to source sensors that go offline if not powered (solar inverters, Wifi Plugs, etc.)

issue-triage-workflows[bot] commented 7 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.