Announcement

Collapse
No announcement yet.

Double replace in publish payload template?

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

    Double replace in publish payload template?

    Hi,

    I've got sirens that will take this payload to sound the siren:
    Code:
    {"warning": {"mode": "fire", "level": "high", "strobe" : false, "duration": 30}}
    And this payload to silence the siren:
    Code:
    {"warning": {"mode": "fire", "level": "low", "strobe" : false, "duration": 30}}
    I'd like to make two buttons for these two payloads, in the same device. One named "Alarm" and the other "Avstill". The device has been setup with "Avstill = 0" and "Alarm = 1"

    I've tried using Replace(x,y,x), but I've had no luck so I must be messing up something with the formatting. I'm struggling to find the right way to do it.

    Here is my attempt, but it results in an invalid JSON. I've tried a lot of moving bracket / quotes etc around, but still with no luck. I'm able to replace a single value, but the nested function has me beat.
    Code:
    {"warning": {"mode": "fire", "level": "<<Replace(<<Replace("$$VALUE:","0","low")>>,"1","high") >>, "strobe" : false, "duration": 30}}
    That template results in the following payload, no matter which button I use:
    Code:
    {"warning": {"mode": "fire", "level": ","1","high")>>, "strobe" : false, "duration": 30}}
    Please advice, thanks

    #2
    I do not believe I have provisions for nest inline expression. One of the following should do it for you

    Code:
    {"warning": {"mode": "fire", "level": "$$LABEL:", "strobe" : false, "duration": 30}}
    {"warning": {"mode": "fire", "level": "<<Lower("$$LABEL:")>>", "strobe" : false, "duration": 30}}
    
    {"warning": {"mode": "fire", "level": "$$VSP:", "strobe" : false, "duration": 30}}
    {"warning": {"mode": "fire", "level": "$$STATUS:", "strobe" : false, "duration": 30}}
    The second is the same as the first where it gets the text from HS Status/Graphics tab setup. If it is already lower case then no need to use the "Lower" inline expression
    The third and fourth get the text from the mcsMQTT Edit tab VSP section. VSP is the first text on a line and STATUS is the second text on the line.

    If the first three do not give you what you need then use the mcsMQTT Edit tab to define the text for STATUS to match what you need and then use $$STATUS:

    Comment


      #3
      Hmm.. Not sure I made myself clear here?

      The payload needs to say "low" and "high". The buttons I want to say "Avstill" and "Alarm" respectively. So I don't want to send the labels, but I need to send a different JSON for the different buttons.

      Does that make sense?

      Comment


        #4
        I will make the inline expression analyzer recursive so nested expressions can be done.

        Comment


          #5
          Update at http://mcsSprinklers.com/MCSMQTTHS4_51701.zip for HS4 and http://mcsSprinklers.com/MCSMQTT_51701.zip for HS3. The dll and pdb go into HS subfolder \bin\mcsMQTT. For HS4 you can also replace TCP.html in \html\mcsMQTT but it will not make any difference unless you are using YoLink.

          I tested with following
          Code:
          {"warning": {"mode": "fire", "level": "<<Replace("<<Replace("$$VALUE:","0","low")>>","1","high") >>", "strobe" : false, "duration": 30}}

          Comment


            #6
            Thank you so much - it works!

            Comment


              #7
              Wait.. Was this unnecessarily complicated?

              Reading your answer to Moskus here - I could have just changed the CAPI label to make the buttons say what I want. I would still have the wrong "status" though.

              Is is possible to set up $$VSP: to give "low" while the $$STATUS: is "Avstill" in the edit tab?

              Thanks a bunch

              Comment


                #8
                In mcsMQTT VSP there is a key and a status. The key is the MQTT payload. The status is the HS VSP.status property. You can setup "low=0;Avstill" on the Edit tab so HS will show "Avstill" rather than "low". This is what I was trying to explain in post #2. When it comes time to publish you can select $$VSP: rather than $$VALUE to get the "low" in the payload.

                It was good anyway to generalize the inline expression in case it may be needed somewhere else.

                Comment


                  #9
                  Originally posted by Michael McSharry View Post
                  In mcsMQTT VSP there is a key and a status. The key is the MQTT payload. The status is the HS VSP.status property. You can setup "low=0;Avstill" on the Edit tab so HS will show "Avstill" rather than "low". This is what I was trying to explain in post #2. When it comes time to publish you can select $$VSP: rather than $$VALUE to get the "low" in the payload.

                  It was good anyway to generalize the inline expression in case it may be needed somewhere else.
                  Thanks. I've been on vacation for the past days so haven't been able to follow up

                  This works well in setting the text on the buttons as I want it, which is great It does end up with the device status being the payload though, or can that be changed manually perhaps?

                  Here is a device I've set up with the current VSP List in mcsMQTTs edit-tab:
                  Code:
                  Payload OFF=0;Av VSP
                  Payload ON=1;På VSP
                  Click image for larger version

Name:	mcsmqtt.png
Views:	100
Size:	172.5 KB
ID:	1486721

                  I end up very close to what I want to achieve. The last thing that irks is the device value showing "OFF" or "ON" when I'd really like it to say the same as the buttons ("Av" and "På").

                  Comment


                    #10
                    The last thing that irks is the device value showing "OFF" or "ON" when I'd really like it to say the same as the buttons ("Av" and "På").
                    Since your MQTT message has payload of OFF and ON you cannot change this in the mcsMQTT Edit tab. What you can do is change it from the HS Devices page Status/Graphics tab with it's edit capability. mcsMQTT will be setting HS to 0 or 1 based upon payload of OFF or ON and HS will show status of whatever you have setup with your edit. If you later edit this device from the mcsMQTT Edit tab it will return the HS status to OFF and ON

                    Comment

                    Working...
                    X