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.78k stars 30.88k forks source link

Incorrect Unit Handling in History-Graph #43145

Closed copperleaf91 closed 2 years ago

copperleaf91 commented 4 years ago

The problem

When displaying a temperature value in the history-graph, the unit displayed is degC however the value is actually degF. Viewing the entity in an entity card or in the configuration screens seems to indicate that the proper unit of degF is being provided.

While on the surface, this appears to perhaps be a bug in the Lovelace history-graph card, there are indications that this may have something to do with how the history itself is storing the units and that perhaps clearing the history may clean up the card. This would explain how for multiple users, the issue cleared after time passed.

Additional details can be found in the community thread: https://community.home-assistant.io/t/weird-issue-with-history-graph-temperature/244436

Environment

Running as docker container on Ubuntu 18.04 on an Intel NUC. Observed in both HA 0.116.4 and 0.117.6.

Problem-relevant configuration.yaml

esphome:
  name: greenhousesensor
  platform: ESP32
  board: node32s

wifi:
  ssid: "xxxxxx"
  password: "xxxxxxx"
  fast_connect: true

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxx"

ota:
  password: "xxxxxx"

sensor:
  - platform: dht
    pin: GPIO5
    temperature:
      name: "Greenhouse Temperature"
    humidity:
      name: "Greenhouse Humidity"
    update_interval: 30s
    model: DHT22
type: history-graph
entities:
  - entity: sensor.greenhouse_temperature
  - entity: sensor.greenhouse_humidity
hours_to_show: 48
refresh_interval: 30
type: history-graph
entities:
  - entity: sensor.home_realfeel_temperature
  - entity: sensor.livingroom_motion_temp
  - entity: sensor.nws_temperature
  - entity: sensor.accuweather_temperature
hours_to_show: 168
refresh_interval: 0
title: 7 Day Temperature

Traceback/Error logs

No errors observed.

Additional information

image image image

probot-home-assistant[bot] commented 4 years ago

history_graph documentation history_graph source (message by IssueLinks)

github-actions[bot] commented 3 years 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.

cchiapusio commented 3 years ago

I re-added my troubled sensor and the C/F issue is no longer present in 2020.2.2. I cannot say when the issue was fixed.

jdhorne commented 3 years ago

This is still happening for me in 2021.4.0. I've attached two examples; the one with the most lines are from a set of Zwave/Zigbee temperature sensors (via Zwave2MQTT and Zigbee2MQTT), and the other is from the Sonoff integration. I've never found any rhyme or reason as to why it happens, nor have I found a repeatable way to fix the issue.

Screen Shot 2021-04-08 at 1 21 32 PM Screen Shot 2021-04-08 at 1 21 40 PM
wallsocket commented 3 years ago

Currently in 2021.4.6 this is happening to me. ZHA and zwave sensors. image

Mark612 commented 3 years ago

I also can confirm this is happening to me. I have a history-graph with 3 sensors, all F. They were working fine, until I replaced the battery on one of them today. And now that sensor graph is being split out from the other two and showing as C. The actual value is in F.

v2021.4.5

RandomArray commented 3 years ago

Happened to me today and a bit of research led me here. I have four identical DHT22 sensors hooked up to 3 esp8266, and 1 esp32 board. The esp32 board is the only one shown on the History Graph in Fahrenheit.

Changing the "Hours to Show" of the graph combines all sensors into Fahrenheit when it is set to <=5 hours. Anything set to >= 6 hours produces the split History Graph with both Celsius and Fahrenheit temperatures graphed. I setup the sensors less than two hours ago.

v2021.5.5

image

billsmithem commented 3 years ago

Just started happening to me in 2021.7.3. Sensor is using ESP Home, 8266, and stopped working in HA though ESPHome logs show it working correctly. Restarted core, as this had fixed missing ESP Home devices in the past, and the device came back up in HA, but with the Lovelace panel claiming it was Celsius while displaying Fahrenheit values. I assume it will eventually age out.

sercrui commented 3 years ago

Another vote for still happening, 2021.8.4 upgraded to 2021.8.6 after noticing it and still there. This is occurring with a brand new esp8266+DHT22 set up with ESPHome. Not enough data to force itto start falling off the chart like others noted but its behaving the same displaying values per the unit settings in °F but listing °C.

image

mt0321 commented 3 years ago

I ran into this issue because my temperature sensor had some data points recorded with an "unavailable" state, and those data points had a unit_of_measurement that was Celsius instead of Fahrenheit.

I used the SQLite Web add-on to query the "states" tables and saw them. Example:

SELECT * FROM "states" WHERE entity_id ="sensor.family_room_temperature" and attributes like '{"unit_of_measurement":"\u00b0C"%'

To fix the issue, I deleted the bad entries.

DELETE FROM "states" WHERE entity_id ="sensor.family_room_temperature" and attributes like '{"unit_of_measurement":"\u00b0C"%'

Hope that helps others.

A possible fix could be to ignore "unavailable" data points (those where state='unavailable') when determining what unit_of_measurement to use in the graph.

github-actions[bot] commented 3 years 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.

TechIsCool commented 2 years ago

This is still happening for me on 2021.12.1. I assume I can fix it with the above SQL code but it would be nice not to have to deal with that.

billsmithem commented 2 years ago

Same here.