Open a-x- opened 2 years ago
Is it possible to add "unit_of_measurement" for sensors with HA autodiscovery? Temperature sensor example(from aqara temperature and humidity sensor): "unit_of_measurement": "°C", "state_class": "measurement",
Humidity sensor example: "unit_of_measurement": "%", "state_class": "measurement",
This trick will add easy-reading values to HA interface
JSON: { "name": "BoilerRoom Humidity", "availability_topic": "boilerroom/status", "payload_available": "available", "payload_not_available": "unavailable", "device": { "manufacturer": "MQTT IO", "model": "v2.2.6", "identifiers": [ "mqtt-io", "RPi_UPS" ], "name": "Boiler Room" }, "device_class": "humidity", "unique_id": "RPi_UPS_dht22_sensor_boilerroom_humidity", "state_topic": "boilerroom/sensor/boilerroom_humidity", "unit_of_measurement": "%", "state_class": "measurement", "expire_after": 125 }
I managed to enable this by changing following in config.yml
sensor_modules:
sensor_inputs:
I managed to enable this by changing following in config.yml
sensor_modules:
- name: Temp1 module: ds18b type: DS18B20 address: 000004cd45ba
sensor_inputs:
- name: Temp1 module: ds18b20 interval: 10 digits: 1 ha_discovery: name: Temp1 device_class: temperature unit_of_measurement: °C
Really good solution, but i suggest to use quotes unit_of_measurement: "°C" for temperature or unit_of_measurement: "%" for humidity. Otherway you will have error raise ScannerError("while scanning for the next token", None, yaml.scanner.ScannerError: while scanning for the next token found character '%' that cannot start any token
hey OP can you close this because it is already possible?
As stated before you can simply do:
sensor_modules:
- name: ds18b_module
module: ds18b
type: DS18B20
address: 0000057b6ebc
sensor_inputs:
- name: temp_sensor
module: ds18b_module
interval: 30
ha_discovery:
name: Temperature sensor
device_class: temperature
unit_of_measurement: °C
Describe the bug It will fix ha graphs and storing
a) mqtt-io graph:
b) correct graph:
Config
Hardware
System: does not matter
Additional context