Announcement

Collapse
No announcement yet.

Replace comma with dot in published payload

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

    Replace comma with dot in published payload

    Thanks for a great plugin. I've gotten things working and can send and receive data. Now I want to publish a topic where the payload has to include a dot and not a comma, i.e. replace 2,5 with 2.5. Could I do this in the plugin or do I have to convert the value beforehand?

    #2
    On the receive side you can employ regular and numeric expressions. On the publish side it only has capability to have numeric expressions (e.g. <<$$VALUE:/10>>). You may be able to achieve you objective depending upon how regional settings affect the math. If you were to scale and then unscale the number it may convert with the dot in the result. You may also be able to work with the property of a dot being a unit of 1000 in your region. Give it a try and see what happens. For example the DeviceValue is 12,3. See what happens when you use in the Payload template <<$$VALUE:*10/10>> or <<$$VALUE:*1000>>

    Comment


      #3
      If math such as <<$$VALUE:*10/10>> would work wouldn't <<$$VALUE:*1>> also work? Or might this work if evening it does not:
      <<Format$(CDbl(Text1.Text)$$VALUE, "#,##0.00")>>
      That may be off for vbscript. I am not able to check it.

      Karl S
      HS4Pro on Windows 10
      1070 Devices
      56 Z-Wave Nodes
      104 Events
      HSTouch Clients: 3 Android, 1 iOS
      Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

      Comment


        #4
        The expression analyzer in mcsMQTT is not based on use of vb.script. What the consideration is how the analyzer deals with regional math. As an example the VB function Val() converts strings to numbers and always uses the US convention for numbers. This means when run in Europe vs. running the same code in USA will product different results if the strings have commas and decimals.

        This does remind me that there is a Round(n,d) function in the analyzer where n is the number and d is the number of significant digits after the decimal. This function uses the .NET Math.Round function so it may (or may not) use the period. <<Round($$VALUE:,2)>>

        And upon further reflection there are a number of string functions as well. These are all documented in Table 2 of the mcsMQTT manual. There is a Replace(x,y,z) function that may be able to be used such as <<Replace($$VALUE:,",",".")>>. I just don't recall how the number would be handled since it is not a string at this time of the evaluation.

        There is also a Format(x,y) function that uses the .NET Microsoft.VisualBasic.Format function

        If none of these tricks and functions work out, then I can add a function to the expression analyzer that does the replacement of the comma with a decimal.

        Comment


          #5
          I confirmed the following does work as the entry in the Publish Payload text box. (Actually I confirmed a period was changed to a comma).
          Code:
          <<Replace($$VALUE:,",",".")>>

          Comment


            #6
            Originally posted by Michael McSharry View Post
            I confirmed the following does work as the entry in the Publish Payload text box. (Actually I confirmed a period was changed to a comma).
            Code:
            <<Replace($$VALUE:,",",".")>>
            Great, thank you. I will test this. I did a workaround in the meantime using a vb.net script, converting the value to a string and replacing the dot.

            If I would like to do the other way around converting dot to comma on the inbound payload using regex, what should I fill the Payload RegEx fields with?

            Comment


              #7
              There is exactly this example in the mcsMQTT manual for regular expression. You could also do it with a basic expression just as I showed for the publish but don't use the << and >>

              Comment

              Working...
              X