Unit of measurement for Pressure sensor



  • Hello!
    I'm very new to mysensors and home assistant so chances are that I misunderstood something completely.

    I've been playing around with one node and one gateway connected via serial to my Raspberry Pi and the entities, one for temperature and one for pressure, are found in home assistant.

    The temperature sensor is working fine and i am able to get a nice "line chart" on my home screen but when I try to do the same with my pressure sensor I get an error saying that the sensor does not have a "unit of measurement" and thus the line chart can not be drawn. Another annoying thing is that the pressure sensor creates a message in the log saying something like "sensor 1_0 changed to 954.3" everytime the value changes.

    So looking over the integration guide at home assistant's homepage I read the following:
    By using V_UNIT_PREFIX, it’s possible to set a custom unit for any sensor. The string value that is sent for V_UNIT_PREFIX will be used in preference to any other unit of measurement, for the defined sensors. V_UNIT_PREFIX can’t be used as a stand-alone sensor value type. Sending a supported value type and value from the tables above is also required. V_UNIT_PREFIX is available with MySensors version 1.5 and later.

    Trying this generates an error saying something like "Not a valid message sub-type: 43 for dictionary value @ data['sub-type']"

    Reading the Serial Protocol 2.X I find that the variable "V_UNIT_PREFIX" is to be used with the sensor types S_DISTANCE, S_DUST or S_AIR_QUALITY. It does not say anything about the S_BARO being compatible with the V_UNIT_PREFIX.

    I'm not at home right now so I can't supply any source code at the moment but I still have some questions you might be able to answer:

    1. Am I doing this the wrong way? I.e. should just skip the V_UNIT_PREFIX from the node and somehow set the unit in home assistant? Is this what you would use Templates for?

    2. Does anyone have a working example to post using a pressure sensor.

    Thank you!



  • Hi @niclas,

    you could create a customize.yaml file in the root folder of your HA installation (the same folder with configuration.yaml, automations.yaml, etc in it) and add the following to it:

    sensor.mysensor_60_3: 
      friendly_name: Barometer
      unit_of_measurement: hPa
    

    You might have to restart HA afterwards or reload the config. This deals with the issue directly in HA.

    The first line is the entity of your pressure sensor with the format of sensor.sketchname_nodeID_childID. It should be listed under the following url: yourHAip:port/developer-tools/state.

    friendly_name is optional and changes, well, the name that is displayed under the sensor icon and unit_of_measurement tells HA what unit your values represent, so that it can display a suitable graph. Since you mentioned a value of 954.3, I assumed hPa is the unit you're looking for.

    mys_baro.png

    Here's a link related to this topic in the HA documentation.

    Hope that works for you.



  • Thank you!
    After posting here I continued to google the subject and did eventually find the page you are referring to. I'm eager to get home and try it out. I'm having some difficulties wrapping my head around the entities and devices of home assistant but I guess it's often like that when you explore a new concept. Little by little it starts to make sense and all of a sudden the penny drops and you understand everything(or at least most of it).

    I am still wondering about the purpose of V_UNIT_PREFIX is and why it's only applicable for a limited set of sensor types...

    I'll check in here again tonight or tomorrow morning with the results!



  • It works! Thank you!



  • Glad it worked for you!

    Regarding the error you got: I suspect that your MySensors integration in configuration.yaml is to blame. Did you specify a version?

    mysensors:
      [...]
      version: '2.3'
    

    If no version is specified, it defaults to an old 1.4 protocol version, which might not support this feature.

    If you get this error solved like that, you are on the right track with V_UNIT_PREFIX and the changes in customize.yaml I suggested above aren't neccessary anymore. HA should then detect which unit your sensor should use.



  • @BearWithBeard
    Hmmm... I didn't realise the Version is supposed to go in the configuration file as well. The version is correctly listed in my persistance-file but I'm not so sure if I have it in my configuration file.

    But, reading the Serial Protocol for mysensors it clearly says that "V_UNIT_PREFIX" is used by "S_DISTANCE, S_DUST, S_AIR_QUALITY" so perhaps the error message is correct?

    I'll report back later tonight.



  • @niclas No, unless there's something else going on, you get this error because you are using the 1.4 serial protocol that the HA MySensors integration uses by default if you don't specify a different version, and 1.4 doesn't support V_UNIT_PREFIX. You quoted the relevant sentence in your first post above:

    V_UNIT_PREFIX is available with MySensors version 1.5 and later.

    Source: Custom unit of measurement section in the MySensors Sensor documentation.

    I admit, the documentation is a little unclear about this, but it refers to the version of the HA integration, which is based on pymysensors. The version you specify in the configuration file determines which of the protocol versions that are implemented in pymysensors it should use, not the MySensors library version you're running on your node. The versions listed for each node in the persistence file has nothing to do with the capabilities of the MySensors integration. (At least not that I know of.)

    I assumed that the V_UNIT_PREFIX could be used with any sensor type and regarded the specified sensors in the serial protocol only as a guideline. Since I had some time to spare, I just modified the provided example sketch (for 2.x) from the link above and presented a S_BARO sensor of type V_PRESSURE, set the unit to "myPi" via send(msgPrefix.set("myPi")) and sent some static dummy data. It works.

    mys_baro_prefix.png


    Update: I commented out the protocol version in my configuration and restarted HA so that it defaults to 1.4, powered the node:

    2020-02-27 12:07:57 WARNING (MainThread) [mysensors] Not a valid message: Not valid message sub-type: 43 for dictionary value @ data['sub_type']



  • Late reply but, adding the version to my configuration file solved the problem just like you suggested. So this topic is now solved using two methods. Very nice!


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 5
  • 2
  • 3
  • 1

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts