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?
Publish msg on the fly
- FlyingDiver
- Posts: 7830
- Joined: Sat Jun 07, 2014 10:36 am
- 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
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
Re: Publish msg on the fly
Thanks. I think that will do the trick.FlyingDiver wrote:The connector has a publish message action that can be called from a script.
...
Re: Publish msg on the fly
Well, I probably responded too fast. Could you post a short example of how that might be called from an embedded script. Thanks.berkinet wrote:Thanks. I think that will do the trick.FlyingDiver wrote:The connector has a publish message action that can be called from a script.
...
- FlyingDiver
- Posts: 7830
- Joined: Sat Jun 07, 2014 10:36 am
- 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
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
Re: Publish msg on the fly
[/size]Perfect, got it working. Thanks!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)