MySensors distance sensor unit_of_measurement configuration

I have successful connected two mysensors distance nodes + mqtt gateway and I’m seeing them in HA.
I see the correct values when I use the MQTT tab in the Developer Tools.
The two sensor nodes do have the same sketch (except node_id) and are outputting their values in cm.

When I look in the tab States in the Developer Tools, I see my two mysensor nodes.
But one has unit_of_measurements: cm and the other unit_of_measurements: m

I have only configured the mysensors entry in the configuration, the sensors are autodetected by HA.
So why two different units of measurement?
Where can I configure this?
Is it set in the mysensor1.pickle file?

First off all, check the autodiscovery messages mysensors sent. HA uses whatever the autodiscovery messages sent.

That is just the question, the nodes sketch code is identical except the node_id.
Yet HA gives them a different unit_of_measurement.

From what I can read in the mysensors docs, the unit is not sent to the controller during the presentation.
So where does this data comes from? I could imagine a default value, but why different?

I’ve changed the persistence file from pickle format to json format to be able to read it, but this unit_of_measurement is not mentioned inside this file.

Ok, found the solution.

I digged into the code dev branch of home assistant and found following file in \home-assistant\components\sensor\
In this file the defaults for each type op sensor are defined in an array.

    'V_TEMP': [None, 'mdi:thermometer'],
    'V_HUM': ['%', 'mdi:water-percent'],
    'V_DIMMER': ['%', 'mdi:percent'],
    'V_LIGHT_LEVEL': ['%', 'white-balance-sunny'],
    'V_DIRECTION': ['°', 'mdi:compass'],
    'V_WEIGHT': ['kg', 'mdi:weight-kilogram'],
    'V_DISTANCE': ['m', 'mdi:ruler'],
    'V_IMPEDANCE': ['ohm', None],
    'V_WATT': ['W', None],
    'V_KWH': ['kWh', None],
    'V_FLOW': ['m', None],
    'V_VOLUME': ['m³', None],
    'V_VOLTAGE': ['V', 'mdi:flash'],
    'V_CURRENT': ['A', 'mdi:flash-auto'],
    'V_PERCENTAGE': ['%', 'mdi:percent'],
    'V_LEVEL': {
        'S_SOUND': ['dB', 'mdi:volume-high'], 'S_VIBRATION': ['Hz', None],
        'S_LIGHT_LEVEL': ['lx', 'white-balance-sunny']},
    'V_ORP': ['mV', None],
    'V_EC': ['μS/cm', None],
    'V_VAR': ['var', None],
    'V_VA': ['VA', None],

So for V_DISTANCE the default is ‘m’.
Seeing that the penny dropped finally. The first sensor is one that I activated one year ago.
The second is the one I activated this weekend.
I updated also the first one with the latest mysensor lib 2.3.2 to be sure that the sketch code of the two sensors was identical.
I forgot that I did a customisation of the auto detected sensor, I changed the default ‘m’ to ‘cm’ in my case because the sensors are outputting centimeters.

Can happen. Always document your changes for later :slight_smile:

HI @evb, could you share your mysensors code?
I will use a ultrasound proximity sensor to measure a cistern water level, and once I use hass as well, I think your code will save me many hours trying to adapt codes to work with hass!!!


@oliverdog I have putted my Mysensors sketches online on Github : GitHub - ericvb/MySensorsArduinoSketches: MySensors Arduino sketches running at my home

You will find the specific ultrasonic sketch here : MySensorsArduinoSketches/sketches/ArduinoUltrasonicSensorWithEncryptionNewPingMedianGithub at master · ericvb/MySensorsArduinoSketches · GitHub

1 Like