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.63k stars 30.78k forks source link

MySensors temperature data changed from Farenheit to Celcius with wrong label #73459

Closed n8henrie closed 2 years ago

n8henrie commented 2 years ago

The problem

I've been running a MySensors temperature sensor for years without issue. It collects and reports data in Celsius to an arduino serial gateway connected by USB., which reports the data in Celsius to HomeAssistant. However, my HomeAssistant is configured to use Imperial units.

A summary the situation that has been working well for years: sensor takes temperature, reports this to my gateway in Celsius. HomeAssistant is configured to display in imperial, so it does so, and in my frontend I see a correct Fahrenheit temperature.

It seemed to be fine until a couple of months ago, when suddenly the values reported changed to Celsius, though they were still labelled as if they were Fahrenheit; in short, it looked almost exactly like https://github.com/home-assistant/core/issues/72625

The actual temperature is in the 70s F, but I see: ↓

Screen Shot 2022-06-13 at 13 20 47

If I use the entity editor to change Unit of Measurement to *C, the situation is even worse:

Screen Shot 2022-06-13 at 13 21 07

I've tried adding device_class: temperature to my customize.yaml as well as unit_of_measurement: "ºC" -- neither of these resolve the issue. Setting unit_of_measurement: "ºC" can sometimes get it to display the correct temperature in ºC (as opposed to the negative number you see above), but I want it to display in ºF like it used to.

What version of Home Assistant Core has the issue?

2022.6.5

What was the last working version of Home Assistant Core?

unclear, around 2021.11 or so I got hung up trying to get zwavejs set up, was working then

What type of installation are you running?

Home Assistant Container

Integration causing the issue

MySensors

Link to integration documentation on our website

https://www.home-assistant.io/integrations/mysensors/

Diagnostics information

No response

Example YAML snippet

Mysensors is configured via GUI.

homeassistant:
    unit_system: imperial

In customize.yaml, I have

sensor.temperature_sensor_1_0:
    device_class: "temperature"

I have also tried:

sensor.temperature_sensor_1_0:
    device_class: "temperature"
    unit_of_measurement: "°C"

Anything in the logs that might be useful for us?

Not much:

hass          | 2022-06-13 12:34:32 INFO (MainThread) [mysensors.gateway_serial] Trying to connect to /dev/nano_serial
hass          | 2022-06-13 12:34:32 INFO (MainThread) [mysensors.transport] Connected to Serial<id=0x7f898e0f40, open=True>(port='/dev/nano_serial', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False)

Additional information

I think these may be relevant issues / PRs

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

mysensors documentation mysensors source (message by IssueLinks)

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

Hey there @martinhjelmare, @functionpointer, mind taking a look at this issue as it has been labeled with an integration (mysensors) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

MartinHjelmare commented 2 years ago

Are you converting the temperature to the controller metric setting like in this example sketch?

https://github.com/mysensors/MySensorsArduinoExamples/blob/bba998bce09bc5139eb4ca7a05b0279f4083ff88/examples/DhtTemperatureAndHumiditySensor/DhtTemperatureAndHumiditySensor.ino#L118-L120

The mysensors integration expects the device to report in Celsius or Fahrenheit matching the setting done by the user in the central Home Assistant settings.

n8henrie commented 2 years ago

Thanks for your response.

The mysensors integration expects the device to report in Celsius or Fahrenheit matching the setting done by the user in the central Home Assistant settings.

I assume you're referring to your PR from last fall: https://github.com/home-assistant/core/pull/58476

The mysensors integration expects the device to report in Celsius or Fahrenheit matching the setting done by the user in the central Home Assistant settings.

Which settings?

As far as I can tell there is no user-configurable settings to tell hass what units the gateway is reporting in. Is there no escape hatch for devices that are properly reporting Celsius data, but I would like to display in homeassistant.unit_system units (whatever that may be)?

I did try making a custom mysensors component that overrode that PR, and it didn't seem to fix the behavior. I might have done something wrong.

Are you converting the temperature to the controller metric setting like in this example sketch?

I will need to check, I think it's just set to bool metric = true; EDIT: but to be clear, I haven't changed the sketch, which has been working without issues for years, and to re-flash the chip in my sensor would be difficult, so I'm hoping there's a better solution. I do like it to be reporting in Celsius, as I'd like to become more accustomed to metric units over time, but I'm not there yet.

MartinHjelmare commented 2 years ago

That PR fixed something that had gone missing after a refactor. But the behavior has been like that for the last 6 years.

I'm referring to the general unit system setting in Home Assistant: https://www.home-assistant.io/docs/configuration/basic/

MartinHjelmare commented 2 years ago

You can set a custom unit of measurement for your sensor by using V_UNIT_PREFIX in your sketch.

https://www.home-assistant.io/integrations/mysensors/#custom-unit-of-measurement

n8henrie commented 2 years ago

I'm referring to the general unit system setting in Home Assistant:

Correct, looks like we're both talking about homeassistant.unit_system.

But the behavior has been like that for the last 6 years.

Huh, I wonder what change may have caused this to suddenly start working abnormally.

MartinHjelmare commented 2 years ago

The bug for gateway metric setting was present between 2021.3 and 2021.10 core releases. Fixed in 2021.11.0.

If you created the sensor during the time the bug was present it may have appeared to be working correctly, as it always defaulted to metric gateway setting.

n8henrie commented 2 years ago

If you created the sensor during the time the bug was present

Hmmm, no I think I made it in 2016 or 2017.

I'm suspicious it has something to do with these other issues that cropped up around the same time:

Perhaps I'll try adding state_class?

MartinHjelmare commented 2 years ago

Mysensors temperature sensors have device class and state class set.

https://github.com/home-assistant/core/blob/3da3503673186458014db71289c940643bcd5222/homeassistant/components/mysensors/sensor.py#L44-L48

If the device is not reporting in the unit system of the controller it's not following the expected behavior of the controller.

n8henrie commented 2 years ago

Ah, thanks for that link. My device does set V_TEMP.

If the device is not reporting in the unit system of the controller it's not following the expected behavior of the controller.

Sorry, just to verify terminology -- controller is homeassistant, right? https://www.mysensors.org/controller

I'm also still confused as to what changes broke the expected behavior after many years of working perfectly. I'm happy to work on a PR to perhaps make this configurable if I can figure out what changed. It would seem surprising if, after a change to homeassistant, the best solution were for me to reflash my sensor.

MartinHjelmare commented 2 years ago

Yes, the controller is Home Assistant.

We already offer the user the custom unit of measurement via V_UNIT_PREFIX. We won't accept further options.

n8henrie commented 2 years ago

We already offer the user the custom unit of measurement via V_UNIT_PREFIX

It's not a "custom unit of measurement," it's Celsius for goodness' sake.

We won't accept further options.

Why would it be bad to allow HomeAssistant to interface with a sensor that reports values in different units than the user's preference for display? Isn't that the point of homeassistant.unit_system?

I guess I'll see if I can sort out V_UNIT_PREFIX in order to restore prior functionality, though I'm not sure that I understand the documentation.

https://www.home-assistant.io/integrations/mysensors#sensor-example-sketch-for-mysensors-2x

#define CHILD_ID 1
...
MyMessage msgPrefix(CHILD_ID, V_UNIT_PREFIX);  // Custom unit message.

Would I change this to something like below?

MyMessage msgPrefix("F", V_UNIT_PREFIX);
MartinHjelmare commented 2 years ago

No, the value of the message is set as normal.

msgPrefix.set("custom_lux")
send(msgPrefix.set("custom_lux"));  // Set custom unit.
n8henrie commented 2 years ago

Well, I am somewhat ashamed to admit that deleting and re-adding the integration solved the issue without other changes, so it seems that hass does indeed convert from Celsius sensor data to Fahrenheit as one would hope.

Screen Shot 2022-06-14 at 14 08 49

I have removed everything from customize.yaml and restarted and it continues to show proper Fahrenheit data.

Thank you @MartinHjelmare for your time and attention, sorry for the wild goose chase.