Seite 1 von 1

MQTT2

Verfasst: 8. Nov 2019 18:00
von KlausPi
Hallo zusammen,

Folgendes Problem:

Über PaperUI kann ich problemlos alle MQTT Things senden und empfangen.
Will ich das ganze aber über eine *.rules steuern, bleibt alles stumm :x

Code: Alles auswählen

val actions = getActions("mqtt","mqtt:broker:27fe993b")
actions.publishMQTT("stat/irgendeinSonoff/POWER","ON")
Ob per *.rules oder per PaperUI/Control; es kommt die gleiche Message im MQTT.fx an.

Wenn ich per postUpdate aus einer *.rules einen Switch ändere, kommt im MQTT.fx nichts an, lege ich den gleichen Schalter manuel um, funktioniert alles. :?:

Wenn ich eine Rule über diese Rule Engine im PaperUI zusammen klicke, funktioniert es auch.

Was mache ich falsch? Wo ist der Fehler?

Grüße
Klaus

Re: MQTT2

Verfasst: 8. Nov 2019 19:27
von peter-pan
Hast du es schon mal mit "cmnd" statt "stat" probiert ?

Re: MQTT2

Verfasst: 8. Nov 2019 19:36
von KlausPi
Oh Mann.
Vielen Dank.
So dumm. Ist doch logisch .... :lol:

Manchmal braucht man halt das 4 Augen Prinzip :P

Re: MQTT2

Verfasst: 8. Nov 2019 21:24
von peter-pan
Kein Problem. Hab ich gern gemacht. Viel Spass noch

Re: MQTT2

Verfasst: 9. Nov 2019 02:28
von udo1toni
Ansonsten kannst Du auch einfach ein passendes Item per sendCommand ansteuern, das wäre der normale Weg, Befehle aus einer Rule abzusetzen.
Die mqtt Action ist eher für Fälle interessant, in denen die Steuerung über ein Item nicht funktioniert.

Re: MQTT2

Verfasst: 9. Nov 2019 10:56
von peter-pan
udo1toni hat geschrieben: 9. Nov 2019 02:28 Ansonsten kannst Du auch einfach ein passendes Item per sendCommand ansteuern, das wäre der normale Weg, Befehle aus einer Rule abzusetzen.
Die mqtt Action ist eher für Fälle interessant, in denen die Steuerung über ein Item nicht funktioniert.
...das hatte ich fast vergessen. Der normale Weg zur Steuerung eines Items, ist wie Udo das beschreibt.

Ich nutze die mqttAction nur zum Update der Firmware, z.B.:

Code: Alles auswählen

// Work with a list of selected Sonoff modules
//
val sonoff_device_ids = newArrayList(
         "basic_01",
         "touch_01"
)

// OR
// Work with the grouptopic, addressing ALL modules at once
//val sonoff_device_ids = newArrayList("sonoffs")

// https://community.openhab.org/t/using-sonoff-power-switches-with-tasmota-firmware-and-openhab2-mqtt2-binding/59969/7  // thx to @opus
rule "Sonoff Maintenance"
  when
   Item Sonoff_Action received command
  then
   logInfo("sonoff_maintenance", "Sonoff Maintenance on all devices: " + receivedCommand)
   val actionsBroker = getActions("mqtt","mqtt:broker:hans") // change to your broker name!
   for (String device_id : sonoff_device_ids) {
      switch (receivedCommand) {
         case "restart" : {
             actionsBroker.publishMQTT( "cmnd/" + device_id + "/restart", "1")
             logInfo("sonoff_maintenance", "Sonoff Maintenance: " + device_id + " / " + receivedCommand + " / " + sonoff_device_ids)
            }
         case "queryFW" : {
             actionsBroker.publishMQTT( "cmnd/" + device_id + "/status", "2")
             logInfo("sonoff_maintenance", "Sonoff Maintenance: " + device_id + " / " + receivedCommand + " / " + sonoff_device_ids)
            }
         case "upgrade" : {
//             actionsBroker.publishMQTT( "cmnd/" + device_id +"/otaurl", "http://sonoff.maddox.co.uk/tasmota/sonoff-DE.bin")   // original by @opus
             actionsBroker.publishMQTT( "cmnd/" + device_id +"/otaurl", "http://thehackbox.org/tasmota/release/sonoff-DE.bin")  // my modification, as for me this URL seems the better one  
             actionsBroker.publishMQTT( "cmnd/" + device_id + "/upgrade", "1")
             logInfo("sonoff_maintenance", "Sonoff Maintenance: " + device_id + " / " + receivedCommand + " / " + sonoff_device_ids)
            }
        }
    }
//   Sonoff_Action.postUpdate(NULL)
   Sonoff_Action.postUpdate("OFF")
 end