Before you ask…
Community forum is NOT a helpdesk
Let’s put this in the front: nobody here works for openHAB. The community members are helping with an Open Source Project, not a commercial software.
Additionally, the forum is NOT dealing with general Home Automation topics, the focus is on openHAB. In some cases, various products or technologies which are not directly linked to openHAB can be discussed but with the proper
title, category or tag.
We are ALL volunteering our free time to help o…
People would like to help but you make it very hard for them… please consider reading this topic.
December 20, 2018, 2:57pm
@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
What is the equivalent for MQTT?
December 20, 2018, 3:07pm
I don’t use jython but maybe this link will help.
This file has been truncated.
# Jython scripting for openHAB 2.x
This is a repository of experimental Jython code that can be used
with the [Eclipse SmartHome](https://www.eclipse.org/smarthome/) platform and [openHAB 2.x](http://openhab.org/) (post OH snapshot build 1318).
A previous version with reduced functionality, but compatible with OH 2.3, has been archived in this [branch](https://github.com/OH-Jython-Scripters/openhab2-jython/tree/original_(%3C%3D2.3)).
These works are based on the original contributions of Steve Bate, for which we are very thankful! :vulcan_salute:
- [Getting Started](Getting-Started.md)
- [Quick Start Guide](Getting-Started.md#quick-start-guide)
- [Jython Scripts and Modules](Getting-Started.md#jython-scripts-and-modules)
- [File Locations](Getting-Started.md#file-locations)
- [Jython Modules](Jython-Modules.md)
- [Component Scripts](Component-Scripts.md)
- [Example Jython Scripts](Example-Jython-Scripts.md)
- [Defining Rules](Defining-Rules.md)
- [Raw ESH Automation API](Defining-Rules.md#raw-esh-automation-api)
- [Using Jython Extensions](Defining-Rules.md#using-jython-extensions)
- [Rule and Trigger Decorators](Defining-Rules.md#rule-and-trigger-decorators)
December 20, 2018, 3:13pm
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 …
December 20, 2018, 3:33pm
Is this what your are looking for? See the paragraph called
December 20, 2018, 3:51pm
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.
December 20, 2018, 4:18pm
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.
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.
December 20, 2018, 8:09pm
From the hints above I was able to use MQTT action from Jython script:
Install MQTT action (this what I was missing, thx
Import the action:
from core.actions import Mqtt
Mqtt.publish(String brokerName, String topic, String message)