mirror of https://github.com/arendst/Tasmota.git
Added examples for the use with openHAB MQTTv2 binding.
parent
1fe2405db4
commit
88c6fd7049
59
openHAB.md
59
openHAB.md
|
@ -4,6 +4,7 @@ This information applies to the openHAB1 version of the MQTT binding (mqttv1). o
|
|||
|
||||
Fortunately, the mqttv1 binding can be installed again. To do so, set 'legacy = true' in addons.cfg or turn on 'Include Legacy 1.x Bindings' in PaperUI (Configuration > System). Then re-install the mqttv1 binding. Please note that now that mqttv1 is a legacy binding, it will no longer receive updates or fixes. Installing both versions of the binding will allow you to migrate over time to be ready for the eventuality of mqttv1 end of life.
|
||||
|
||||
For users that intend to migrate to mqttv2 some examples for the integration have been added at the end ("Examples for integration with MQTTv2").
|
||||
|
||||
## openHAB Integration
|
||||
|
||||
|
@ -215,6 +216,64 @@ String Sonoff_Current_FW_Available "Current Release [%s]" <sonoff_basic> (Sonoff
|
|||
|
||||
With the item in your sitemap, you will now see the latest release/tag from the tasmota repository.
|
||||
|
||||
## Examples for integration with MQTTv2
|
||||
|
||||
**.things File:**
|
||||
|
||||
```java
|
||||
Bridge mqtt:broker:myMQTTBroker [ host="IPofBroker", secure=false, username="myUser", password="myPassword" , clientID="myMQTTClient" ]
|
||||
{
|
||||
Thing topic sonoff_TH "Light_TH" {
|
||||
Channels:
|
||||
Type switch : PowerSwitch [ stateTopic="tele/sonoff_TH/STATE" , transformationPattern="JSONPATH:$.POWER" , commandTopic="cmnd/sonoff_TH/POWER", on="ON", off="OFF" ]
|
||||
Type string : Version [stateTopic="stat/sonoff_TH/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
|
||||
Type string : Temperature [stateTopic="tele/sonoff_TH/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**.items File:**
|
||||
|
||||
```java
|
||||
Switch Switch_TH "Switch_TH" { channel="mqtt:myMQTTBroker:topic:sonoff_TH:PowerSwitch" }
|
||||
|
||||
String Switch_TH_Temperatur "Temperatur [%.1f °C]" <temperature> {channel="mqtt:myMQTTBroker:topic:sonoff_TH:Temperature"}
|
||||
String Sonoff_Version "Sonoff Version: [%s]" <sonoff_basic> { channel="mqtt:myMQTTBroker:topic:sonoff_6:Version"}
|
||||
```
|
||||
**.rules File for the Maintenance Action:
|
||||
|
||||
```java
|
||||
// Work with a list of selected Sonoff modules
|
||||
val sonoff_device_ids = newArrayList(
|
||||
“sonoff-A00EEA”,
|
||||
//… add all your modules here!
|
||||
“sonoff-E8A6E4”
|
||||
)
|
||||
// OR
|
||||
// Work with the grouptopic, addressing ALL modules at once
|
||||
//val sonoff_device_ids = newArrayList(“sonoffs”)
|
||||
|
||||
rule “Sonoff Maintenance”
|
||||
when
|
||||
Item Sonoff_Action received command
|
||||
then
|
||||
logInfo(“sonoff.rules”, “Sonoff Maintenance on all devices: " + receivedCommand)
|
||||
val actionsBroker = getActions(“mqtt”,“mqtt:broker:MyMQTTBroker”) // change to your broker name!
|
||||
for (String device_id : sonoff_device_ids) {
|
||||
switch (receivedCommand) {
|
||||
case “restart” :
|
||||
actionsBroker.publishMQTT( “cmnd/” + device_id + “/restart”, “1”)
|
||||
case “queryFW” :
|
||||
actionsBroker.publishMQTT( “cmnd/” + device_id + “/status”, “2”)
|
||||
case “upgrade” : {
|
||||
actionsBroker.publishMQTT( “cmnd/” + device_id +”/otaurl", “http://sonoff.maddox.co.uk/tasmota/sonoff-DE.bin”)
|
||||
actionsBroker.publishMQTT( “cmnd/” + device_id + “/upgrade”, “1”)
|
||||
}
|
||||
}
|
||||
}
|
||||
Sonoff_Action.postUpdate(NULL)
|
||||
end
|
||||
```
|
||||
|
||||
## Community Forum
|
||||
|
||||
|
|
Loading…
Reference in New Issue