Inconsistent translation from metric to imperial

Hi- I have two opengarage units monitoring two garages (attached and detached). I installed temperature sensors on both, and HA is retrieving those statistics. The configurations are identical other than the internal IP and the name. I even did a diff check:

The issue is that Lovelace sees one as C and one as F, so they are getting put on different charts. Sometimes. When it does happen, it looks like this’

I also verified the states of the sensors with the dev tools just for good measure.


My HA is set in imperial and I’d like everything shown in F. What is going on that the sensors get treated differently?

Why do they say Celcius in the YAML for unit_of_measurement?

Did you set a device_class to temperature for them?

I’m pretty sure setting the device_class will cause HA to use the system settings for the temperature. Maybe it figured out one was a temp sensor and the other it didn’t know so it’s applying the unit_of_measurement label to it.

So yeah, specify device_class: temperature for both then report back. Also remove or update the unit_of_measurement to F if you want.

1 Like

@jocnnor, thank you for taking a look. I’ve modified the yaml to include a device_class of temperature, and that seems to be working for now. I hope that locks it into acting more consistently! (see Inconsistent translation from metric to imperial below)

Just for anyone else who may find this looking for future help, I failed to mention that the JSON object reported by the opengarage reports in Celsius. It looks like this:

{
  "dist":145,
  "door":0,
  "vehicle":1,
  "rcnt":57,
  "fwv":111,
  "name":"Garage East Stall",
  "mac":"XX:XX:XX:XX:XX:XX",
  "cid":3719337,
  "rssi":-66,
  "temp":5.20,
  "humid":42.30
}

The sensors ended up looking like this:

#Garage
  - platform: rest
    resource: http://192.168.1.229/jc
    name: Garage Temperature
    value_template: '{{ value_json.temp }}'
    unit_of_measurement: '°C'
    device_class: temperature
#Detached Garage    
  - platform: rest
    resource: http://192.168.1.227/jc
    name: Detached Garage Temperature
    value_template: '{{ value_json.temp }}'
    unit_of_measurement: '°C'
    device_class: temperature

The unit_of_measurement is explicitly set as Celsius so that HA knows it might need to do some math on it if your system settings are imperial. The device_class appears to help HA know beyond a shadow of a doubt that the sensor represents a temperature. Maybe because the values are so small in the winter time the code has some edge cases where it is hard to make assumptions? I’m just speculating, I suppose one could read through the repo if they wanted to get to the bottom of it all.

Finally, just for the record, the unicode degree symbol is the one that you get with the keyboard shortcut alt+0176 (aka U+00B0).

Dang it! I reloaded the UI in lovelace after I made the ‘it’s working fine’ post, and I it went back to displaying the temperature simultaneously on two graphs again:

The detached garage sensor has a harder time maintaining a connection with my mesh network + HA than my attached garage sensor does. Could the frequent disconnects cause HA to try and report the temperature in both formats?

Does anyone have any further ideas?

Why is detached garage temp on both charts now?

That’s an excellent question! My best guess is that the frequent network disconnecting and reconnecting of my detached garage’s opengarage unit causes some sort of issue with HA ‘remembering’ that a value should be reported in imperial vs metric? I’m at a loss.

The temperature gets graphed as: both units of measure, as imperial only, and as metric only. I’ll live with it, as I’m pretty sure it’s related to the weak outskirts of my mesh network. I think my next troubleshooting step will be to try and reinforce the mesh by adding a node in the garage.

if the result for the temperature is ºC, then you want to use ºC as the unit of measure. Home assistant will convert it to your system units. In his case ºF. So it will take the ºC value and multiply it by 9/5*ºC+32. If he sets the unit of measure, he doesn’t need to set the device_class, although it doesn’t hurt to.

@Bayou-Billy The issue is your database. 1 (most likely the first) piece of data has the wrong units stored in the database. So when home assistant displays the history information it screws up. If you just wait, it will go away when that data is thrown out. You could also delete the database.

2 Likes

@petro awesome! That makes way more sense than my mumbo-jumbo speculation :grinning: I have the DB set for three days of storage, so I’ll make a mental note to double check then.

There’s definitely a flaw when setting this up. This thread pops up once every few months, so you aren’t the only one who has this issue. The good news is that it always goes away.

1 Like

FWIW I’ve observed with my MQTT temperature sensors (Acurite from RTL_433 to MQTT) seems like if they “go offline” I get a blip where Home Assistant thinks they are C instead of F and it takes 24 hours from the blip before the graphs “fix themselves”.

I don’t know why this happens, but I have observed it happening when mine go offline even for a brief time when I monkey with stuff. Maybe that’s part of your issue, you may benefit from investigating that issue first.

I also have this problem EVERY time that I add a new temperature sensor, it is stuck on C for 24 hours then jumps to F correctly. That makes me think even more it’s some kind of connectivity issue confusing Home Assistant.

1 Like

Oddly, in my experiences deleting the DB and restarting everything resulted in EVERYTHING showing as C instead of F…much worse. I found I had to just “wait it out” when this happens. In my case it’s only 24 hours though, even though my DB saves 7 days.

There’s no connectivity though. These graphs purely come from the history database. It does not look at the current state. I’d wager if you changed your mqtt sensor you can get around this issue. You’re most likely storing ‘unknown’ as a state which doesn’t get converted.

That’s because you’re only viewing the single day graph in the history page. If you were to widen it to 3 days and the bad datapoint is inside the 3 day window, you’d most likely get the same result.

The graphs are made from SQL look ups only. So the data from the look up drives the graph.

There is still something wrong though. Maybe we’re not talking about the same thing but I’m using the YR platform for Weather badges. I deleted the database and rebooted. A week later and some are still showing metric while right next to it another badge is showing imperial.

Look at this screenshot. Temps in F, wind speed and precipitation in metric. It shows the same thing in the History - some in imperial, some in metric.

ha

Did you clear your cache and refresh the page (CTRL+F5)? Those are ui elements, not the history graphs. Those are based on your current setup. If they have the wrong units then either you don’t have the units set properly for your system (Seems like you do), or you haven’t refreshed the cache in your browser.

It isn’t anything with caching. Just to make sure I started up Edge (which I never use - I use Firefox) and it shows the same thing. I’ve never visited the interface with Edge.

I know this isn’t the history, I’m saying it’s also showing this in the history page. See screenshot:

ha2

YR doesn’t support imperial. Switch your weather platform to something that outputs a weather domain item. I.E. any other weather platform.

EDIT: Just to clarify, its up to the platform to convert anything that isn’t temperature. Home assistant only converts temperature for the user. The platforms need to change the calculations for all other sensors and YR does not.

Thank you for the clarification.

Is there somewhere it is documented that YR doesn’t support imperial? How are we supposed to know this information? The YR page says nothing about it either way. If the page had made it clear, I wouldn’t have spent so much time messing with this issue.

doesn’t look like it.

:man_shrugging: You’re welcome to add to the documentation.

“If your integration isn’t properly documented, it will be rejected.”

There, fixed.