Send mqtt payload via button

Forum Home Forums Understanding the Software Send mqtt payload via button

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #13840
    grhsc
    Participant

    Dear developer

    In my case, the device operates through mqtt payload, so it is not like a factory, setting start and stop through 0,1
    Instead, a load like this is used to start and stop the device
    {“tagId”:”pump1″,”value”:1}
    {“tagId”:”pump1″,”value”:0}

    So I need to send string. Through settings, I have implemented a button on the screen. After clicking, a string input box pops up. After entering {“tagId”:”pump1″,”value”:1}, the device can be controlled.

    But obviously such input is not user-friendly, and users need to enter different id values.
    Is there a way to send {“tagId”:”pump1″,”value”:1} to the mqtt topic without manual input as long as an ON button is clicked.

    If it works, I will define another button OFF with the content {“tagId”:”pump1″,”value”:0}

    I guess it should be possible via formulas or other advanced functions, but I’m not quite familiar with it yet.
    Looking forward to your help, thank you in advance.

    #13848
    Mikhail
    Moderator

    Hello,

    Add to the Scripts table:

    public string GetPayload()
    {
      return "{\"tagId\":\"pump1\",\"value\":" + CmdVal + "}";
    }
    

    Then use GetPayload() as an output formula of the channel.
    Let me know if it works or not.

    #13853
    grhsc
    Participant

    Allow me to express my gratitude to you, not only for the effective and quick reply, but also for the wonderful design of rapidscada. Whenever I look forward to a feature, it has been designed.

    #13854
    grhsc
    Participant

    I have tested it and it works fine.
    super perfect!
    thanks again

    #13857
    Mikhail
    Moderator

    Cool! It can be useful for many users 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.