I’ve been struggling to find a solution for this, what it comes down to is the History Graph is not consistent in upholding the unit of measure for some temperature entities I have (Shelly H&T). Here’s an example:
Your database has a ºC in it and it won’t merge the graphs until that piece of data is purged or beyond your 14 days. So do nothing and it will fix itself. That’s why the 1 day works and the 14 day doesn’t. The 1 day data doesn’t contain the ºC in the database, but the 14 day one does.
Units are pulled from the first datapoint in the series. So if your first data point has the wrong units, you have to wait for that datapoint to be outside your dataset.
During this current 2 week period though, there hasn’t been any changes to units with the sensor firmware or HA configs. The first data point in the dataset has the same units as the current datapoints, otherwise, wouldn’t there be an invalid conversion occurring across the whole history graph? In my examples above (14/12 day graphs), if the HA frontend is using the “incorrect” Celsius unit, my HA config should convert it to imperial, but the numeric value remains the same (when comparing 12day vs 10/8/6/1day). I don’t believe this is intended behavior and may be a bug in HA when showing >~10days of data in a History Graph card.
I’ve been collecting data on the sensor in question and storing it in InfluxDB since July. Here’s some history to where I tried forcing a unit change in firmware of the sensor, thus causing a conversion of value.
It is my assumption that data passed from the HA Recorder to InfluxDB is stored after HA unit conversions. If this is a valid assumption, there’s something with unit interpretation that HA is bugging out on.
The sensor graphs don’t use influx db, they use the home assistant database. Just do a SQL look up of that item and you’ll see that it has ºC in the database, not ºF. You’re welcome to continue to argue, but you just need to purge your HA database or wait.
I know that HA doesn’t use the separate InfluxDB for its data, my point with bringing that into discussion is that I’ve consistently recorded the the same numeric data and yet this inconsistency occurs.
Your advice to purge the database of the data or wait until the recorder autopurges it is basically what I’ve done for nearly a year and hearing that is the only option is disappointing since it will only continue on. I don’t believe I’ve argued anything yet and don’t see how adding more context around my thoughts is, I am merely trying to ask for help for my problem: Why is this inconsistency in units occurring and how do I fix it.
Don’t change your unit of measurement. As soon as you change it, it adds a new unit of measurement in the HA database. That will cause your graphs to use a different unit of measurement if that’s the first unit of measurement found in the database.
I’m trying to explain how it works and you keep basically saying “I don’t like the explanation, help!!!”. There’s nothing you can do with the basic database. You’d have to move to something else, then you’d have to learn how to edit it. You can edit the current database, but it’s a pain. This is ultimately the issue with databases in general.
Thanks, I always wondered how that happened. I guess I didn’t realize that the unit of measure is stored in a text field, attributes, in the states table. And, within that, it appears to be coded in, what, JSON? Almost a database within a database. At any rate, interesting approach to keep the database structure very simple and flexible.
My point is, the OP can confirm or disprove that there’s nothing else going on (beyond the expected behavior) by checking the offending values in the states table. It’s not really difficult to copy the home-assistant_v2.db file to another machine and open it up in DB Browser or whatever.
I haven’t changed my units of measurements within the current duration of Recorder’s purge_keep_days (my config is set to 14 days) and I’m telling you that all the units within the environment (sensor firmware is reporting data in imperial, HA unit_system’s is set to imperial, History Graph doesn’t have anything set) are consistent.
But here we are and the sensor’s is showing a metric unit of measurement.
So I figured I double check and do this per your recommendation, queried the states table with a entity_id filter for the specific entity name, and received 815 rows. Looking at the attributes field, example here:
…for due diligence and to double check, split out the json and ran a value count on all of the unit_of_measurement unique values, just to see what the breakdown was, and sure enough, all 815 report “\u00b0F”. 32000 character limit here, but tab separated data if anyone’s interested: ha_db_dump_shelly_htgarage.tsv - Pastebin.com
I would submit your findings on github by creating a new issue against home assistant core. Post all the data and screenshots you provided here. I was able validate your data.