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
73.51k stars 30.71k forks source link

Statistics not working due to (incorrectly identified) mismatch of temperature measurement units #76329

Closed nateww closed 2 years ago

nateww commented 2 years ago

The problem

The problem HA Core version 2022.8.1 (although it has existed since 2022.5.0)

When I startup this version of Home Assistant, I get the following error:

2022-08-05 16:32:03.259 WARNING (Recorder) [homeassistant.components.sensor.recorder] The normalized unit of sensor.outdoor_temp_daily_max (°C) does not match the unit of already compiled statistics (°F). Generation of long term statistics will be suppressed unless the unit changes back to °F. 

However, this sensor is in Fahrenheit, and is based on a filter sensor (due to noisy values I receive from the actual sensor) that reads it's value in Fahrenheit.

I did not receive any error in the prior release (2022.4.7), so this is a new regression.

What version of Home Assistant Core has the issue?

2022.8.1

What was the last working version of Home Assistant Core?

2022.4.7

What type of installation are you running?

Home Assistant Core

Integration causing the issue

None

Link to integration documentation on our website

No response

Diagnostics information

See https://github.com/home-assistant/core/issues/71770, which was closed without actually investigating the issue.

I finally tried the upgrade again, and the same error occurs.

Example YAML snippet

sensor:
- platform: statistics
  name: "Outdoor Temp Daily Max"
  entity_id: sensor.433_outdoor_temperature
  state_characteristic: value_max
  sampling_size: 800
  max_age:
    hours: 24
- platform: mqtt
  name: 433_raw_outdoor_temperature
  state_topic: "rtl_433/LaCrosse-TX141THBv2/temperature_F"
  expire_after: 600
  force_update: true
  unit_of_measurement: "°F"
  device_class: temperature
- platform: filter
  name: "433_outdoor_temperature"
  entity_id: sensor.433_raw_outdoor_temperature
  filters:
    - filter: outlier
      window_size: 4
      radius: 2.0
    - filter: lowpass
      time_constant: 10
    - filter: time_simple_moving_average
      window_size: "00:05"
      precision: 1

Anything in the logs that might be useful for us?

Additional information

Because the sensor is a bit noisy (values jump around a lot), I use the moving average of 5 minutes to make it MUCH less noisy, and then run the max for the day based on the damped sensor value.

Also, I'm using an external database (MariaDB)

+-----------------+
| VERSION()       |
+-----------------+
| 10.3.29-MariaDB |
+-----------------+
nateww commented 2 years ago

As before, I get the following error when I look at the /developer-tools/statistics, which is (obviously) incorrect.

Unsupported unit in recorded statistics
The unit °F of the statistics in your database for this entity is not a supported unit for the device class of the entity, temperature. It should be °C.

Do you want to update the unit of the history statistics to °C?

The temperature is being reported (natively) as Fahrenheit, so I don't want/need it converted to Celcius.

nateww commented 2 years ago

Also note that I have not (yet) converted to the new MQTT sensor format, as I keep having to revert to a working version of Home Assistant.

nateww commented 2 years ago

From developer tools, even the system knows the correct units.

state_class: measurement
age_coverage_ratio: 0.86
buffer_usage_ratio: 1
source_value_valid: true
unit_of_measurement: °F
device_class: temperature
icon: mdi:calculator
friendly_name: Outdoor Temp Daily Max