Sensor unit of measurement not changing

Running hass.io 0.103.6.

I ran into this issue when creating a template sensor to get the current temperature from my nest thermostat. I made a mistake specifying the unit of measurement, but I had a big problem trying to get it correct. When I modified the sensors.yaml to use the proper value, it would never change to reflect that in the state attributes. I removed the sensor completely and restarted ha, then re added the sensor, but it still used the old unit of measurement. I even went into the db and deleted all the state and history data for that sensor, but I could not get it to use my new unit of measurement. I finally had to add it under a different name to get the proper value.

I think I’m seeing the same thing now with the darksky sensor. I’m a US guy, but my wife likes to see temperatures in Celsius, so while I have a weather card in the UI that shows my imperial values (using the darksky integration, not the sensor), I wanted to change the darksky sensor to use metric values and I would setup a custom darksky card I found in the forums here that does use the sensor. I changed the darksky sensor to use si as the units of measurement, but it’s not changing in the states list. However, I did add some new monitored_conditions and those show up with the right metric values. It’s just the ones that were already there that won’t change.

Is there a way to get HA to completely reset it’s knowledge about a particular sensor so I can re-add it with the right values?

Bruce, unfortunately, what you are trying to do is not possible in the backend without doing some crafty stuff. Home assistant converts all temperatures into the ‘system’ temperature units. So if you set up home assistant to report Fahrenheit, it will only report Fahrenheit. Even if you create sensors specifically to output in Celsius, home assistant will still convert it.

Now there are multiple ways to get around this. I’ll list them in easiest to hardest order.

  1. Make a template sensor that converts the F to C. But list the unit_of_measure as unit less or something other than ºC / ºF.
  2. Use a custom card that allows you to template values. Custom:button-card can do this inside the card. The Custom:template-card will allow you to do this on any style card but it’s harder to use.

Personally, I’d go the custom lovelace card route.

Hi Petro,

Thanks for the reply. Maybe I’ll try to fork and modify the custom darksky weather card from @m.p.frankland to do the conversions. I thought about the template-card, but I like the look of a true weather type card.

Bruce

That would probably be the easiest solution if you know how to do it.

I got it working. I thought I wouldn’t even need to modify the js because the author of the darksky weather card allows you to specify the sensors to use. I was able to create template sensors for the temperatures that convert the DarkSky temps to celsius. However the card was getting the unit of measure from the system, so while it was displaying the correct temperatures, the UOM was still showing as ‘°F’. So, I added a couple lines that allow you to override the UOM values via the config for the card.

Imgur

I’ll post the template sensors I created and put in a PR to the author of the card for my changes.

1 Like