Zwave2mqtt: [bug] Incorrect unit of measurement formatting with Hass Discovery for Zwave temperature sensors

Created on 16 Apr 2020  Â·  5Comments  Â·  Source: OpenZWave/Zwave2Mqtt

v3.0.2

Build/Run method

  • [x] Docker
  • [ ] PKG
  • [ ] Manually built (git clone - npm install - npm run build )

Zwave2Mqtt version: 3.0.2
Openzwave Version: 1.6.1061

Describe the bug
Home Assistant Hass Discovery is reporting temperature units in C or F rather than °C or °F.

The home assistant core code is defining TEMP_CELSIUS and TEMP_FAHRENHEIT as °C and °F:
https://github.com/home-assistant/core/blob/0.108.5/homeassistant/const.py#L353

Without the correct formatting, it is causing other components like HomeKit to fail with errors such as:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_sensors.py", line 96, in update_state
    temperature = temperature_to_homekit(temperature, unit)
  File "/usr/src/homeassistant/homeassistant/components/homekit/util.py", line 236, in temperature_to_homekit
    return round(temp_util.convert(temperature, unit, TEMP_CELSIUS), 1)
  File "/usr/src/homeassistant/homeassistant/util/temperature.py", line 29, in convert
    raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(from_unit, TEMPERATURE))
ValueError: C is not a recognized temperature unit.
2020-04-15 08:17:30 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/homekit/type_sensors.py", line 96, in update_state
    temperature = temperature_to_homekit(temperature, unit)
  File "/usr/src/homeassistant/homeassistant/components/homekit/util.py", line 236, in temperature_to_homekit
    return round(temp_util.convert(temperature, unit, TEMP_CELSIUS), 1)
  File "/usr/src/homeassistant/homeassistant/util/temperature.py", line 29, in convert
    raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(from_unit, TEMPERATURE))
ValueError: C is not a recognized temperature unit.

To Reproduce
Steps to reproduce the behavior:

  1. Have a device such as the Home Security Sensor - ZW100 MultiSensor 6 (AEON Labs) in the zwave network.
  2. Configure the Gateway with Type: ValueID topics, Payload Type: JSON Time-Value & Hass Discovery enabled
  3. Select the sensor node in the zwave2mqtt control panel
  4. Scroll down to view the Home Assistant - Devices Node's details
  5. Select the id for sensor_temperature_air
  6. Review the Hass Device JSON and note that "unit_of_measurement": "C" is missing the °. See Additional context for an example.

NB Using an MQTT client and manually re-publishing the same Hass Device JSON with the ° added fixes the errors in Home assistant, allowing the temperature values to be successfully processed.

Expected behavior
The ° symbol should be present for all temperature units of measure in the hass discovery payload.

Additional context
Example Hass Device JSON

{
  "type": "sensor",
  "object_id": "temperature_air",
  "discovery_payload": {
    "value_template": "{{ value_json.value }}",
    "device_class": "temperature",
    "unit_of_measurement": "C",
    "state_topic": "zwave/Kitchen/Sensor/49/1/1",
    "json_attributes_topic": "zwave/Kitchen/Sensor/49/1/1",
    "device": {
      "identifiers": [
        "zwave2mqtt_0xf0c9ae1c_node6"
      ],
      "manufacturer": "AEON Labs",
      "model": "ZW100 MultiSensor 6 (0x0064)",
      "name": "Kitchen-Sensor",
      "sw_version": "1.11"
    },
    "name": "Kitchen-Sensor_temperature_air",
    "unique_id": "zwave2mqtt_0xf0c9ae1c_6-49-1-1"
  },
  "discoveryTopic": "sensor/Kitchen-Sensor/temperature_air/config",
  "values": [
    "49-1-1"
  ],
  "persistent": false,
  "id": "sensor_temperature_air"
}
bug

Most helpful comment

Hey @raspberrypython, I thought you might like to know how I solved this. I use the customize section in home assistant to change the unit_of_measurment and the units. For example:

sensor.kids_temperature_air:
  friendly_name: Kids Temperature
  unit_of_measurement: °F
  units: °F

With that said, as @robertsLando pointed out the device xml has the units.. but my devices only support C and F, no °C or °F. Since home assistant does use °C and °F I think it would be awesome if Zwave2Mqtt would automatically prepend the string with ° if it's not already there so that the hass discovery payload has it with the ° since this is something that is specific to home assistant, and not zwave devices in general.

Cheers,

All 5 comments

This should be fixed in the device xml configuration file. Nothing related to z2m


Daniel - Software Engineer

Support me at:
Github sponsors

On 16 Apr 2020, at 21:58, David Noyes notifications@github.com wrote:


v3.0.2

Build/Run method

Docker
PKG
Manually built (git clone - npm install - npm run build )
Zwave2Mqtt version: 3.0.2
Openzwave Version: 1.6.1061

Describe the bug
Home Assistant Hass Discovery is reporting temperature units in C or F rather than °C or °F.

The home assistant core code is defining TEMP_CELSIUS and TEMP_FAHRENHEIT as °C and °F:
https://github.com/home-assistant/core/blob/0.108.5/homeassistant/const.py#L353

Without the correct formatting, it is causing other components like HomeKit to fail with errors such as:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(self.args, *self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/homekit/type_sensors.py", line 96, in update_state
temperature = temperature_to_homekit(temperature, unit)
File "/usr/src/homeassistant/homeassistant/components/homekit/util.py", line 236, in temperature_to_homekit
return round(temp_util.convert(temperature, unit, TEMP_CELSIUS), 1)
File "/usr/src/homeassistant/homeassistant/util/temperature.py", line 29, in convert
raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(from_unit, TEMPERATURE))
ValueError: C is not a recognized temperature unit.
2020-04-15 08:17:30 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(self.args, *self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/homekit/type_sensors.py", line 96, in update_state
temperature = temperature_to_homekit(temperature, unit)
File "/usr/src/homeassistant/homeassistant/components/homekit/util.py", line 236, in temperature_to_homekit
return round(temp_util.convert(temperature, unit, TEMP_CELSIUS), 1)
File "/usr/src/homeassistant/homeassistant/util/temperature.py", line 29, in convert
raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(from_unit, TEMPERATURE))
ValueError: C is not a recognized temperature unit.
To Reproduce
Steps to reproduce the behavior:

Have a device such as the Home Security Sensor - ZW100 MultiSensor 6 (AEON Labs) in the zwave network.
Configure the Gateway with Type: ValueID topics, Payload Type: JSON Time-Value & Hass Discovery enabled
Select the sensor node in the zwave2mqtt control panel
Scroll down to view the Home Assistant - Devices Node's details
Select the id for sensor_temperature_air
Review the Hass Device JSON and note that "unit_of_measurement": "C" is missing the °. See Additional context for an example.
NB Using an MQTT client and manually re-publishing the same Hass Device JSON with the ° added fixes the errors in Home assistant, allowing the temperature values to be successfully processed.

Expected behavior
The ° symbol should be present for all temperature units of measure in the hass discovery payload.

Additional context
Example Hass Device JSON

{
"type": "sensor",
"object_id": "temperature_air",
"discovery_payload": {
"value_template": "{{ value_json.value }}",
"device_class": "temperature",
"unit_of_measurement": "C",
"state_topic": "zwave/Kitchen/Sensor/49/1/1",
"json_attributes_topic": "zwave/Kitchen/Sensor/49/1/1",
"device": {
"identifiers": [
"zwave2mqtt_0xf0c9ae1c_node6"
],
"manufacturer": "AEON Labs",
"model": "ZW100 MultiSensor 6 (0x0064)",
"name": "Kitchen-Sensor",
"sw_version": "1.11"
},
"name": "Kitchen-Sensor_temperature_air",
"unique_id": "zwave2mqtt_0xf0c9ae1c_6-49-1-1"
},
"discoveryTopic": "sensor/Kitchen-Sensor/temperature_air/config",
"values": [
"49-1-1"
],
"persistent": false,
"id": "sensor_temperature_air"
}
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Ah interesting! Thank you for the quick response, much appreciated.
Can you give me a few pointers on which file to be looking at and what to look out for? I’ll do my best to fend for myself from there.

Its ok! I think I found it.
Thank you again, ill close the issue.

Hey @raspberrypython, I thought you might like to know how I solved this. I use the customize section in home assistant to change the unit_of_measurment and the units. For example:

sensor.kids_temperature_air:
  friendly_name: Kids Temperature
  unit_of_measurement: °F
  units: °F

With that said, as @robertsLando pointed out the device xml has the units.. but my devices only support C and F, no °C or °F. Since home assistant does use °C and °F I think it would be awesome if Zwave2Mqtt would automatically prepend the string with ° if it's not already there so that the hass discovery payload has it with the ° since this is something that is specific to home assistant, and not zwave devices in general.

Cheers,

running into the same issue with the same workaround. @robertsLando would you be open to a PR that does this conversion in zwave2mqtt?

Was this page helpful?
0 / 5 - 0 ratings