Temperature just switched from C to F - why?

I’ve been using home assistant for a few weeks, and I’m still getting the hang of things. I have a couple temperature sensors that i’ve been tweaking settings for, and I had just changed them this morning (a few hours ago) so that the values were float(), hoping that would allow the graphs to do what I wanted. This seemed to work OK.

However, when I changed my test graph from the last 2 hours to the last 24h, both my sensors suddenly started reporting in Fahrenheit instead of Celsius - but didn’t convert all the old values. So, my graphs look like this:

13%20AM

The sensors themselves report in C (I checked the actual MQTT output), they’re labeled as C in the configuration, and they’ve been happily reporting C for days. Suddenly, this change, and I don’t understand it. I am in the US, and my defaults are imperial, but I certainly didn’t change this in the last few minutes. Anyone have any thoughts?

Here’s the sensor config:

sensor:
  - platform: plex
  - platform: mqtt
    name: livingroom_temperature
    state_topic: "livingroom/sonoff/tele/SENSOR"
    unit_of_measurement: "°C"
    value_template: '{{ float(value_json.DS18B20.Temperature) }}'
  - platform: mqtt
    name: basement_temperature
    state_topic: "basement/sonoff/tele/SENSOR"
    unit_of_measurement: "°C"
    value_template: '{{ float(value_json.DS18B20.Temperature) }}'

…and here’s the graph section, which I just changed:

history_graph:
  gr1:
    name: Temperature
    entities:
      - sensor.livingroom_temperature
      - sensor.basement_temperature
    hours_to_show: 168
  gr2:
    name: temperature_24
    entities:
      - sensor.livingroom_temperature
      - sensor.basement_temperature
    hours_to_show: 24

recorder:
  include:
    domains:
      - sensor
      - switch
      - light

temperature units are global in home assistant. If you specify a sensor with a given unit, home assistant will convert it to the global unit in the user interface.

To change your global unit, see here:

OK, so THAT’S why it picked that moment to change - because I set the units of the sensor. A little confusing, but I suppose I can live with it.

Thanks!

yah, annoying but that’s why it does that. Makes sense, especially if you work in one unit.

@riz94107 I’m curious, were you able to get your graph to display the correct temperature unit? In your graph, the values are graphed at their converted °F values, but the graph still indicates °C as the unit. I have the same behavior with a very similar setup and it’s driving me crazy because I can’t get a combined graph of all my temperatures working. The issue seems to be that some of my sensors report in °F and some report in °C. The unit_of_measurement field on each sensor is set accordingly to its native reporting unit in my sensor config, and my global unit_system is imperial.

- platform: mqtt
  name: "Sonoff MQTT Bathroom Temperature"
  state_topic: "tele/sonoff_bathroom_fan/SENSOR"
  value_template: '{{ value_json["DHT11"]["Temperature"] }}'
  unit_of_measurement: "°F"

- platform: template
  sensors:
    kitchen_temperature:
      friendly_name: 'Kitchen temperature'
      value_template: '{{states.sensor.kitchen_motion_sensor.attributes.temperature}}'
      unit_of_measurement: °C
    living_room_temperature:
      friendly_name: 'Living room temperature'
      value_template: '{{states.sensor.living_room_motion_sensor.attributes.temperature}}'
      unit_of_measurement: °C
    bedroom_temperature:
      friendly_name: 'Bedroom temperature'
      value_template: '{{states.sensor.bedroom_motion_sensor.attributes.temperature}}'
      unit_of_measurement: °C
    bathroom_temperature:
      friendly_name: 'Bathroom temperature'
      value_template: '{{states.sensor.bathroom_motion_sensor.attributes.temperature}}'
      unit_of_measurement: °C

What I end up with in my graph display group is split into 2 graphs:

Any idea what the correct config would be to get them all displaying in °F and in the same graph table?

Try overriding the unit_of_measurement inside the customize section, leaving the unit_of_measurement in your template sensors as is.

Ahhh, good idea! I tried overriding the sensors in the customize section, which allows the sensors to merge and displays °F as the unit, but it inverts the values on the graph for those sensors to °C

customize:
  sensor.kitchen_temperature:
    unit_of_measurement: °F
  sensor.bathroom_temperature:
    unit_of_measurement: °F
  sensor.living_room_temperature:
    unit_of_measurement: °F
  sensor.bedroom_temperature:
    unit_of_measurement: °F

Home_Assistant

Maybe overriding the unit_of_measurement on the group the sensors are in or the history_graph itself is the way to go?

I ended up just having to give up on using the native °C unit, and instead used a conversion formula in the template and set the unit_of_measurement to °F

 kitchen_temperature:
  friendly_name: 'Kitchen temperature'
  value_template: '{{ (((states.sensor.kitchen_motion_sensor.attributes.temperature) * 9 / 5) + 32) | round(1) }}'
  unit_of_measurement: °F

I also had to clear the history for these sensors in my database to clear it of any references to the old units.
Now I just need to figure out why this little DHT11 temperature sensor is so inaccurate :laughing:

Home_Assistant

Sorry I didn’t get back to you sooner. To me, that sounds like a bug. It should be displaying ºF when you use the ºC as the unit and your config is set to ºF. Glad you got it fixed though.

No worries! I knew I could always value template it, but I was really trying to figure out if I was doing something incorrectly or if it was indeed a bug, as that’s what I was starting to suspect because the ºF unit_of_measurement was being correctly passed on my other UI elements. Thanks again.

So this sounds like something I’ve been experiencing on and off for quite some time. I have several sensors that are all in °F, and have a unit_of_measurement of °F, yet when once in a while I delete my database and restart HA (for various testing reasons), one of the sensors shows separately in a graph labeled °C, again, even though the values are °F and the unit_of_measurement is °F. It looks like this:

image

It will stay this way for a while (like maybe a few days or so), then presto-magico, one day I’ll look and they’re merged together on a single °F graph! This has happened at least four or five times over the last few months.

FWIW, here they are on the States page:

And I have unit_system: imperial in configuration.yaml.

There is some goofyness with this for sure. To me it seems like an unreported bug. Not many people are going to have mix and match senor units.

Agreed. I just haven’t gotten around to investigating or doing anything else about it because, as I said, before long it somehow corrects itself (for me, at least) and then works just fine until the next time I blow away my database.

I understand why you’d want to convert for most sensor values, but some are meant to be reasoned over in their original units. I do all of my 3D printer stuff in °C, but track my house in °F.

Here’s where it gets messy…

I am using InfluxDB and Grafana, and once Hass makes the switch °C to °F, it starts submitting it on that measurement name to Influx.

I think the Influx component should NOT convert the values, but send them as specified in the component.

3 Likes

Did you figure this out since this post? I am having the same exact issue. Its pretty annoying.

Nope, I haven’t. Still happens from time to time.

Happens to me too. Just had two of my motion sensors jump to a new graph (marked C, but still showing values in the F range: 65-75).

I just realised that these are sensors that recently became unavailable, so I had to reboot them (battery disconnect/reconnect). Oddly enough, four sensors went offline today, but two of them are now back in the F graph, while two are on the C graph.

This is an old thread, but I think it should be considered a bug if we can’t override the global setting.

Just because something behaves differently than you expect does not make it a bug. You’re welcome to add a feature request. But this is certainly not a bug, it’s by design.

I think this topic has talked about different but related issues. The one that seems clearly like a bug is displaying a sensor, whose unit_of_measurement is, and always has been, F, on a graph where the Y axis is labeled C, yet the values are also clearly F. And then sometime later, the same sensor jumps to a graph where the Y axis is labeled F. That is certainly a bug.