Announcement

Collapse
No announcement yet.

A guide to transforming values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    A guide to transforming values

    I'm trying to work on a few devices to get their values transformed into something more in line with how my zigbee devices display values of devices.

    To start I want to convert the value of my humidity sensor from '51.466999' to just read '51' or better yet '51%' or maybe '51.4%'.

    Looking at the details for the device association I see theres an expression input but it's unclear exactly what the format should be to do this or if i can use concatenation to add string characters for units (Degrees Celsius, Watts, Volts, %, etc) .

    It says you can use math operators or functions. When I search the documentation I saw a few references to Round() or Int() or Trunc() to either transform the number or cast it or truncate it but I cant figure out the exact syntax to put in the expression box and the 500 pages of documentation is virtually impossible to search on this. I can't find anything in this forum with the search either because homeseers search is probably the worst user experience on the planet. It literally gives you a list of 500 forums to manually pick the one you want to search on and they aren't in any order so its impossible to find the mcsmqtt forum and just search that.

    Section 4.1.15 gives some hints on transformations. Section 6.3 however refers to round() being used but then the function signatures below that show it as Round()

    I've tried different variations of the following and have had no success yet:

    Int($$PAYLOAD)
    Round($$PAYLOAD,1)
    <<Int($$PAYLOAD)>>
    <<Round($$PAYLOAD,1)>>
    <<Round($$PAYLOAD:,1)>>
    Int($$VALUE)

    All I ever get is just 0.00000 for the device value after that.

    Is there a guide out there thats just on the format of how to write expressions and which variable is which like $$PAYLOAD, $$VALUE, etc, and which functions can be used.

    Theres also references to round() Round() and ROUND() in some places so I'm not sure what the proper casing is if its all lower, all upper, or sentence case for the functions. I've searched the documentation for examples of Round( and have seen references to using << >> around the expression and sometimes not so it's unclear if brackets are required as well.

    every reference to the variables I've seen is that they are all $$ and upper case.

    Not sure what the difference is between $$PAYLOAD and $$VALUE. the documentation refers to $$VALUE as the device value and the $$PAYLOAD as the last MQTT value received. I'm not sure which variable I want to transform and what the order of operations is. is the device value set and then you transform it or is the mqtt value received, then transformed, then placed in the device. So I'm not sure when in the pipeline the expression contents are run.

    Documentation is so great but very hard to search and virtually impossible to read the whole thing due to its size. I commend you on your documenting everything this plugin can do.

    #2
    If you haven't explored it, options in the HS device Status/Graphics allows for setting number of decimal places, suffix, etc.
    -Wade

    Comment


      #3
      Originally posted by Wade View Post
      If you haven't explored it, options in the HS device Status/Graphics allows for setting number of decimal places, suffix, etc.
      I'm using HS4. There is no UI for this anymore. Just setting a graphic, and the ranges for each one. ranges for controls as well. no access on the homeseer side to transform the data.

      Comment


        #4
        Originally posted by dhod View Post

        I'm using HS4. There is no UI for this anymore. Just setting a graphic, and the ranges for each one. ranges for controls as well. no access on the homeseer side to transform the data.
        I've heard there are issues with status/graphics config in HS4 and I've not tried it, but the settings are here:

        Click image for larger version

Name:	Screenshot 2021-06-23 114643.png
Views:	173
Size:	321.5 KB
ID:	1480815Click image for larger version

Name:	Screenshot 2021-06-23 114704.png
Views:	178
Size:	24.4 KB
ID:	1480816
        -Wade

        Comment


          #5
          If you are receiving a MQTT payload then the Edit tab is used and the Expression textbox. You also need to be aware of the Control/Status UI that should be a Number and that the received message does use the period rather than a comma for decimal delimiter.

          Your context of what you want to transform is the MQTT message payload so the replacement variable will be $$PAYLOAD: Note that in some of your example attempts you do not have the trailing colon in the replacement variable. Replacement variables are case-insensitive.

          This is an Expression and not a Template. In Templates, such as the publish payload template, there needs to be a way to distinguish an expression from text. The double less-than, greater-than surround what is an expression. You will not use them in the Expression textbox.

          I expect the correct text in the Expression textbox to be ROUND($$PAYLOAD:,1)

          The other option you have in this specific case where it is only displayed precision then you can also have it done in HS as Wade pointed out.

          Comment


            #6
            Originally posted by Michael McSharry View Post
            If you are receiving a MQTT payload then the Edit tab is used and the Expression textbox. You also need to be aware of the Control/Status UI that should be a Number and that the received message does use the period rather than a comma for decimal delimiter.

            Your context of what you want to transform is the MQTT message payload so the replacement variable will be $$PAYLOAD: Note that in some of your example attempts you do not have the trailing colon in the replacement variable. Replacement variables are case-insensitive.

            This is an Expression and not a Template. In Templates, such as the publish payload template, there needs to be a way to distinguish an expression from text. The double less-than, greater-than surround what is an expression. You will not use them in the Expression textbox.

            I expect the correct text in the Expression textbox to be ROUND($$PAYLOAD:,1)

            The other option you have in this specific case where it is only displayed precision then you can also have it done in HS as Wade pointed out.
            Thanks for this. it does work. however it converts '51.938999' to '51.900000' not '51.9' I'm not sure if that is working as intended or not.

            In the end I used the suggestion from Wade. That icon must have recently been added to HS4 and i didnt notice it. setting a suffix and decimal place worked and i left the expression empty for mcsmqtt.

            Comment


              #7
              The plugin stores a double precision number in the HS DeviceValue. HS is responsible for converting the number to text for display. I have never seen HS show precision to 6 decimal places as the default. I have usually seen integers displayed. What you have is a good solution.

              Comment

              Working...
              X