MQTT2

Einrichtung der openHAB Umgebung und allgemeine Konfigurationsthemen.

Moderatoren: seppy, udo1toni

Antworten
KlausPi
Beiträge: 27
Registriert: 12. Sep 2019 19:53
Answers: 0

MQTT2

Beitrag 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

Benutzeravatar
peter-pan
Beiträge: 2758
Registriert: 28. Nov 2018 12:03
Answers: 30
Wohnort: Schwäbisch Gmünd

Re: MQTT2

Beitrag von peter-pan »

Hast du es schon mal mit "cmnd" statt "stat" probiert ?
Pi5/8GB(PiOS Lite 64-bit(bookworm)/SSD 120GB - OH4.3.5 openhabian

KlausPi
Beiträge: 27
Registriert: 12. Sep 2019 19:53
Answers: 0

Re: MQTT2

Beitrag von KlausPi »

Oh Mann.
Vielen Dank.
So dumm. Ist doch logisch .... :lol:

Manchmal braucht man halt das 4 Augen Prinzip :P

Benutzeravatar
peter-pan
Beiträge: 2758
Registriert: 28. Nov 2018 12:03
Answers: 30
Wohnort: Schwäbisch Gmünd

Re: MQTT2

Beitrag von peter-pan »

Kein Problem. Hab ich gern gemacht. Viel Spass noch
Pi5/8GB(PiOS Lite 64-bit(bookworm)/SSD 120GB - OH4.3.5 openhabian

Benutzeravatar
udo1toni
Beiträge: 15247
Registriert: 11. Apr 2018 18:05
Answers: 242
Wohnort: Darmstadt

Re: MQTT2

Beitrag 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.
openHAB4.3.3 stable in einem Debian-Container (bookworm) (Proxmox 8.3.5, LXC), mit openHABian eingerichtet

Benutzeravatar
peter-pan
Beiträge: 2758
Registriert: 28. Nov 2018 12:03
Answers: 30
Wohnort: Schwäbisch Gmünd

Re: MQTT2

Beitrag 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
Pi5/8GB(PiOS Lite 64-bit(bookworm)/SSD 120GB - OH4.3.5 openhabian

Antworten