Publish msg on the fly

Posted on
Mon Nov 07, 2022 11:22 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Publish msg on the fly

I have an http listener (a hacked version of your HTTPD2 plugin) that listens for incoming messages and changes a device state on or off. . I then want to use that state change as a trigger. For now, I am happy to have two triggers (on and off) for each state I want to monitor. I may try to generalize it a bit in the future. So far, that works fine. I can trigger on the state change and write to the log. However, I what I really want to do is to publish an mqtt message. The messages I want to send are already saved as the on off msgs in an mqtt Shim device, so I can just copy them from there.

All that is lacking is a scriptable feature of the mqtt connector to send an arbitrary msg. Is there a way to do that now? Is this even of interest to anyone else?

Posted on
Mon Nov 07, 2022 11:25 am
FlyingDiver offline
User avatar
Posts: 7220
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Publish msg on the fly

The connector has a publish message action that can be called from a script.

Code: Select all
    <Action id="publish" deviceFilter="self">
        <Name>Publish Message</Name>
        <CallbackMethod>publishMessageAction</CallbackMethod>
        <ConfigUI>
            <Field id="topic" type="textfield">
                <Label>Topic:</Label>
            </Field>
            <Field id="payload" type="textfield">
                <Label>Payload:
               
               
               
               
               
               
               
               
               
               
                </Label>
            </Field>
           <Field id="qos" type="menu" defaultValue="0">
              <Label>QoS Level:</Label>
              <List>
                 <Option value="0">0</Option>
                 <Option value="1">1</Option>
                 <Option value="2">2</Option>
              </List>
            <Field id="qosNote" type="label" fontSize="small" fontColor="darkgray">
                <Label>QoS is ignored for messages to DXL brokers.</Label>
            </Field>
           </Field>
           <Field id="retain" type="menu" defaultValue="0">
              <Label>Retain:</Label>
              <List>
                 <Option value="0">False</Option>
                 <Option value="1">True</Option>
              </List>
           </Field>
            <Field id="retainNote" type="label" fontSize="small" fontColor="darkgray">
                <Label>Retain is ignored for messages to DXL brokers.</Label>
            </Field>
            <Field id="simpleSeparator2" type="separator"/>
            <Field id="messageNote" type="label" fontSize="small" fontColor="darkgray">
                <Label>Variable and Device State Substitution is enabled for topic and playload fields. Use the format %%v:12345%% for variables and %%d:12345:someStateId%% for device states.</Label>
            </Field>
        </ConfigUI>
    </Action>

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Nov 07, 2022 11:32 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Publish msg on the fly

FlyingDiver wrote:
The connector has a publish message action that can be called from a script.
...
Thanks. I think that will do the trick.

Posted on
Mon Nov 07, 2022 12:05 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Publish msg on the fly

berkinet wrote:
FlyingDiver wrote:
The connector has a publish message action that can be called from a script.
...
Thanks. I think that will do the trick.
Well, I probably responded too fast. Could you post a short example of how that might be called from an embedded script. Thanks.

Posted on
Mon Nov 07, 2022 12:12 pm
FlyingDiver offline
User avatar
Posts: 7220
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Publish msg on the fly

Code: Select all

props = {   
    'topic': 'foo/bar/test',
    'payload': 'RAW DATA',
    'qos': '0' ,
    'retain': '0'
}

mqttPlugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.mqtt")
if mqttPlugin.isEnabled():
    mqttPlugin.executeAction("publish", deviceId=1269849630, props=props)
   
   

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Nov 07, 2022 1:03 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Publish msg on the fly

FlyingDiver wrote:
Code: Select all
props = {   
    'topic': 'foo/bar/test',
    'payload': 'RAW DATA',
    'qos': '0' ,
    'retain': '0'
}
mqttPlugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.mqtt")
if mqttPlugin.isEnabled():
    mqttPlugin.executeAction("publish", deviceId=1269849630, props=props)   
 
Perfect, got it working. Thanks!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest