[Beginner] Publish MQTT value from openHAB to Tasmota device

  • Platform information:

    • Hardware: Raspberry Pi 3b+ Processor: BCM2835; Linux 4.19.50-v7+ armv7l
    • OS: Raspbian GNU/Linux 10 (buster); Firmware #896
    • Java Runtime Environment: (build 11.0.8+10-post-Raspbian-1deb10u1); Version 11.0.8" 2020-07-14
    • openHAB version: 2.5.9 Release Build
  • Issue of the topic: Syntax for MQTT publish message

Dear community,

I am stuck with a MQTT item and I am sure you can help me.

I use the standard MQTT embedded broker for my openHAB setup and have the following thing via text file configured:

Bridge mqtt:systemBroker:embedded-mqtt-broker [ host="localhost", secure=false, username="NAME", password="PASSWORD"] {
 Thing topic Briefkasten "Briefkasten" {
    Channels:
    Type switch : TelePeriod "TelePeriod" [commandTopic="cmnd/Briefkasten/TelePeriod", 300="ON", 0="OFF"]
    Type switch : DeepSleep "DeepSleep" [commandTopic="cmnd/Briefkasten/DeepSleepTime",300="ON", 0="OFF"]
    }
}

I want to change the TelePeriod and the DeepSleepTimer values via MQTT with the following items for my Tasmota device:

Switch TelePeriod "TelePeriod" {channel="mqtt:topic:embedded-mqtt-broker:Briefkasten:TelePeriod"}
Switch DeepSleep "DeepSleep" {channel="mqtt:topic:embedded-mqtt-broker:Briefkasten:DeepSleep"}

The first item for TelePeriod does change the value sucessfully of the Tasmota device correctly when I switch on/off:
image

The second item, DeepSleep, does not work. In my Tasmota log I only get “0 when I switch on/off”:
image

I am able to send a DeepSleepTimer value sucessfully with MQTT.fx, so in general my idea works:

2021-03-18 13:55:42,621  INFO --- PublishController              : publish
2021-03-18 13:55:42,621  INFO --- MqttFX ClientModel             : attempt to add PublishTopic
2021-03-18 13:55:42,622  INFO --- MqttFX ClientModel             : sucessfully published message 300 to topic cmnd/Briefkasten/DeepSleepTime (QoS 0, Retained: false)
2021-03-18 13:55:42,902  INFO --- ReceivedMessagesController     : TopicsCollectorService: messageArrived: topic: stat/Briefkasten/RESULT

So I guess that I need to tweak my DeepSleepTimer channel on the Briefkasten thing. What would be the best way to simply publish a message like

cmnd/Briefkasten/DeepSleepTime "300"

For now I just used switch item to control relais via MQTT. I am wondering why the TelePeriod just works “out of the box”.

Thanks for your help and best regards,
Markus

Instead of

300="ON", 0="OFF"

for both try

on=300, off=0

or

on="300", off="0"

for both.

No idea why the TelePeriod is working with your current syntax!

Another note:

openHAB2.x was designed around Java 8, and should be run with Java 8 only. Using it with Java 11 may cause unpredictable events, and you won’t get much support!

1 Like

Thanks for your help, unfortunately your suggested changes didn’t help. I tried to following combinations:

on=300, off=0
on="300", off="0"
ON=300, OFF=0
ON="300", OFF="0"

for both items. TelePeriod always worked, DeepSleepTime was always the same result with 0.

Any other idea? I dont assume that this is an Tasmota issue because with MQTT.fx its working as expected.

#1 edit:
I created a generic MQTT thing for my Tasmota device and added the DeepSleepTime topic with a channel and an item, it works with this. But I want to have this in my text file configured like most of my stuff. So still, it is doable, I just need to figure out the syntax.

#2 edit:
I just changed (updated) the channel name from DeepSleep to DeepSleepTime just from my gut-feeling that there might be an issue from previous testing. And see there, with a fresh channel it works.

Type switch : DeepSleepTime "DeepSleep" [commandTopic="cmnd/Briefkasten/DeepSleepTime", on="30", off="0"]

Thanks for you support anyway :slight_smile: I really appreciate it

Why? The MQTT channel definition simply does not have OFF= or ON= parameters. It doesn’t help trying random stuff.
It does have documented on= and off= parameters.
You do have a choice of number or string, but I think the string is the favourite here.
People do seem to struggle with these parameters sometimes.

Set it up with your best attempt, then restart the binding bundle to make sure it is using the most recent settings. Small Thing edits sometimes pass without in-flight adoption.
That seems to be supported by -

where Teleperiod apparently continues to work even with a definitely messed-up parameter.

1 Like

openHAB has a bug where it doesn’t always properly load a Things file after that file has been saved. You may have run into this issue. I usually solve it by doing this.

EDIT: That’s what @rossko57 was also alluding to in the post above.

1 Like

Let me double check my syntax for the parameters tomorrow again in order to prevent me struggling with this as soon openhab pulls the latest version and recognizes the wrong state I seem to have now.

So it has to be either one of this

on=300, off=0
on=“300”, off=“0”

Is the second one indicating a string?

1 Like

Yep!

1 Like

Dear both,

on="300", off="0"

did the trick. I had to restart the binding and openHAB a few times, but now its running smoothly so far with the correct syntax suggested from you both.

Complete briefkasten.thing file looks now like this:

Bridge mqtt:systemBroker:embedded-mqtt-broker [ host="localhost", secure=false, username="USERNAME", password="PASSWORD"] {
 Thing topic Briefkasten "Briefkasten" {
    Channels:
    Type switch : Einwurf "Einwurf" [stateTopic="stat/Briefkasten/POWER1"]
    Type switch : Entnahme "Entnahme" [stateTopic="stat/Briefkasten/POWER2"]
    Type switch : Zustand "Zustand" [stateTopic="tele/Briefkasten/LWT",transformationPattern="MAP:briefkasten.map"]
    Type switch : TelePeriod "TelePeriod" [commandTopic="cmnd/Briefkasten/TelePeriod", on="300", off="0"]
    Type switch : DeepSleepTime "DeepSleep" [commandTopic="cmnd/Briefkasten/DeepSleepTime", on="30", off="0"]
    }
}

Thanks for your patience and support! :slight_smile:

Best regards,
Markus

1 Like