zachowj / hass-node-red

Companion Component for node-red-contrib-home-assistant-websocket to help integrate Node-RED with Home Assistant Core
MIT License
460 stars 182 forks source link

ha.entity's unit of measurement is not honored in home assistant #95

Closed b3nj1 closed 2 years ago

b3nj1 commented 2 years ago

Version of the custom_component

Latest: v1.0.1

Configuration

image

Describe the bug

With v0.5.4, the sensor showed up in Home Assistant with the correct temperature. Since I have my HA configured for imperial, the would then be converted to °F for display.

With v1.0.1, the sensor shows up wrong. It looks like it has been converted CtoF twice: 20C -> 69F; 69"C" -> 156"F"

image image
b3nj1 commented 2 years ago

I have a theory that the problem is that native_unit_of_measurement is not being advertised. https://developers.home-assistant.io/blog/2021/08/12/sensor_temperature_conversion

zachowj commented 2 years ago

With 1.0 I switched the sensor entity to use native value. Is your value that you're sending the entity node in C or F? I believe with native it expects the unit type to be what the value is and not what you want it to display. If this is the case I'll need to add that to the release notes.

b3nj1 commented 2 years ago

In my case , the sensor entity node is sending C and is using C as its unit, so it is "what the value is" not what I "want it to display". So, that doesn't seem to be it.

In HA, I don't have any customizations on the sensor. I globally have imperial as my default. In HA, the sensor shows up with unit of F. UPDATE: I tried adding native_unit_of_measurement: °C as a customization, but it didn't change anything.

The values/units are shown above in the screen grabs both in Node-Red and in HA devices in case my description here isn't clear.

It seems other integrations are seeing similar bad temps: https://github.com/home-assistant/core/issues/61163

b3nj1 commented 2 years ago

Should this be native_unit_of_measurement?

https://github.com/zachowj/hass-node-red/blob/0763aec6d8dbbb31fba785278205cca59c25c101/custom_components/nodered/__init__.py#L141

zachowj commented 2 years ago

Should this be native_unit_of_measurement?

The sensor should be using the one from HA SensorEntity

https://github.com/home-assistant/core/blob/6725e4033c418ee2245eeb52796219cddbc23661/homeassistant/components/sensor/__init__.py#L346-L362

I'll take a closer look at this.

zachowj commented 2 years ago

@b3nj1 let me know if that fixes it for you. If not reopen the issue.