[SOLVED] How to publish to mqtt topic with jython


(Eyal Cohen) #1

Help will be appreciated

Thx


(Elias H.) #2

People would like to help but you make it very hard for them… please consider reading this topic.


(Eyal Cohen) #3

@BrutalBirdie Thx, I thought the the topic is enough

I want to be able to publish a message to MQTT topic (py rule). I don’t know which function and from which package I need to import the function. E.g., for HTTP I do the following:

from org.eclipse.smarthome.model.script.actions.HTTP import sendHttpGetRequest

sendHttpGetRequest("http: ...)

What is the equivalent for MQTT?

Thx


(CM6.5 H102) #4

I don’t use jython but maybe this link will help.


(Eyal Cohen) #5

@H102

I have this code and they show how to work with actions but the MQTT is missing there and I currently cannot find how to do it. Still searching …

Thx


(Hilbrand Bouwkamp) #6

Is this what your are looking for? See the paragraph called Rule Actions:


(Eyal Cohen) #7

@hilbrand

Not sure, there are no instructions there what you need to import in order to use it in Jython script. It also somehow complicate things as this is the new MQTT binding (AFAIK) and I am still using MQTT version 1.


(Hilbrand Bouwkamp) #8

Not tested but this could looks like the import:

from org.eclipse.smarthome.model.script.actions.Things import getActions

Also you can install both version 1 and 2 of mqtt next to each other. You only need to configure a generic bridge/thing. I think that might work.


(David Graeff) #9

For mqtt1 actions you need the mqtt1 actions binding installed. Have a look at that bindings documentation for how it would work in DSL rule files and that should give you a hint for how to do it in python syntax.


(Eyal Cohen) #10

Thx all,

From the hints above I was able to use MQTT action from Jython script:

  1. Install MQTT action (this what I was missing, thx @David_Graeff)

  2. Import the action:
    from core.actions import Mqtt

  3. Call it
    Mqtt.publish(String brokerName, String topic, String message)