8000 Statistics sensor logs bad data right after HA restart · Issue #98262 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Statistics sensor logs bad data right after HA restart #98262
Closed as not planned
Closed as not planned
@gregtakacs

Description

@gregtakacs

The problem

I have two template sensors that logs pH and ORP data from a REST call. Then I added four statistics sensors that track the 24hr minimum and maximum values for these two template sensors.

The issue I'm seeing is that every time I restart Home Assistant the min and max values that get stored in recorder are corrupt and store the current value rather than the actual min/max value as they should. It quickly recovers afterward but the spikes give me concern as I rely on making automated decisions based on these values and if the decision just happens to be made right after a restart the results can be bad (adding too much bleach or acid to my pool)
ph_orp_statistics_problem
states-export.csv

What version of Home Assistant Core has the issue?

core-2023.8.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Statistics

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

pool:
  sensor:
    - platform: rest
      unique_id: fabc1ee2-0bbe-416e-b23d-2474ac25fe4e
      name: iopool
      resource: https://api.iopool.com/v1/pool/48c98574-188c-42d0-9cfc-7c9e029318aa
      value_template: "{{ value_json.title }}"
      json_attributes:
        - id
        - latestMeasure
        - hasAnActionRequired
        - advice
        - mode
      headers:
        x-api-key: !secret iopool_api_key
      scan_interval: 300
      icon: mdi:pool
    - platform: statistics
      name: "Daily ORP Min"
      unique_id: d55f6242-379f-11ee-be56-0242ac120002
      entity_id: sensor.iopool_orp
      state_characteristic: value_min
      max_age:
        hours: 24
    - platform: statistics
      name: "Daily ORP Max"
      unique_id: f7b134f8-1fff-4c29-8910-b88f5e62ce3b
      entity_id: sensor.iopool_orp
      state_characteristic: value_max
      max_age:
        hours: 24
    - platform: statistics
      name: "Daily pH Min"
      unique_id: 84a50585-bbda-48f8-b5a3-06393f384340
      entity_id: sensor.iopool_ph
      state_characteristic: value_min
      max_age:
        hours: 24
    - platform: statistics
      name: "Daily pH Max"
      unique_id: b132e3f6-81ab-4242-98a0-93efedb37fac
      entity_id: sensor.iopool_ph
      state_characteristic: value_max
      max_age:
        hours: 24

  template:
    - sensor:
        - name: "ioPool pH"
          unique_id: f4804a67-1224-4507-a4fb-21d983958b7c
          state: "{{ state_attr('sensor.iopool', 'latestMeasure')['ph'] | round(3) }}"
          device_class: ph
          unit_of_measurement: "pH"
          attributes:
            source: "{{ state_attr('sensor.iopool', 'latestMeasure')['mode'] }}"
            isValid: "{{ state_attr('sensor.iopool', 'latestMeasure')['isValid'] }}"
            measuredAt: "{{ state_attr('sensor.iopool', 'latestMeasure')['measuredAt'] }}"
        - name: "ioPool ORP"
          unique_id: e0ef9122-c53a-41ae-be72-517f3fcbb443
          state: "{{ state_attr('sensor.iopool', 'latestMeasure')['orp'] | round(0) }}"
          unit_of_measurement: "mV"
          device_class: voltage
          attributes:
            source: "{{ state_attr('sensor.iopool', 'latestMeasure')['mode'] }}"
            isValid: "{{ state_attr('sensor.iopool', 'latestMeasure')['isValid'] }}"
            measuredAt: "{{ state_attr('sensor.iopool', 'latestMeasure')['measuredAt'] }}"

Anything in the logs that might be useful for us?

I ran this SQL to pull data:

        SELECT
          *
        FROM
          states
          INNER JOIN states_meta ON
            states.metadata_id = states_meta.metadata_id
        WHERE
          (states_meta.entity_id = 'sensor.iopool_ph' OR states_meta.entity_id = 'sensor.daily_ph_min' OR states_meta.entity_id = 'sensor.daily_ph_max')
AND states.state_id > 27587000
--         AND last_updated_ts <= strftime('%s', 'now', '-3 hour')
        ORDER BY
          last_updated_ts DESC
        LIMIT
          10000;


### Additional information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0