Tasmota and MQTT Binding

I’m trying to add a Tasmota Sonoff T1 UK 2CH switch via PaperUI.

I have it set up so that I can see that it is being received by the broker, however I think I need to define some sort of transformation for ON=1 and OFF=0, but am confused by the JSON transformation script option in the PaperUI.

I get the following error:

 [WARN ] [hab.binding.mqtt.generic.ChannelState] - Command '{"POWER1":"ON"}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"POWER1":"ON"}
20:05:12.402 [WARN ] [e.core.thing.binding.BaseThingHandler] - Handler GenericMQTTThingHandler tried updating the thing status although the handler was already disposed.

EDIT: I added the following in the transformation options:

{"POWER1":"ON"}

and:

{"POWER1":"OFF"}

which seems to have done the trick, however I still get the warning:

20:05:12.402 [WARN ] [e.core.thing.binding.BaseThingHandler] - Handler GenericMQTTThingHandler tried updating the thing status although the handler was already disposed.

No, you should only need to install JSONPATH Transformation and then use
JSONPATH:$.POWER1 as the incoming transformation.

1 Like

I think I need to ditch the PaperUI and perhaps add my MQTT Sonoff things in the things file.
I have managed to read the switch over MQTT, and with a rule I can switch a Hue light on and off, but what I need to figure out is how to update the switch state when some other input changes the state of the light (Alexa for instance).

What I’m trying to achieve, is the LED on the switch should turn off when I turn the light on and on when I turn the light off. This is fine if I am using the switch, but if I use Alexa to turn the light on and off, the state of the switch doesn’t toggle to reflect the change.

This is fairly easy (though it’s all relative!) - when a Tasmota device receives a command from anything it will publish a response on the RESULT topic. At the very least, that RESULT message will include the POWER state.

OpenHAB can subscribe to these RESULT topics using the stateTopic property of a thing, which means it is ‘constantly listening’ for them. Once received, you can then update your item with the required information.

If you show a screenshot of your Tasmota MQTT setup page we could probably guide you through setting up the things, items and sitemap required.

I’m currently on the phone though, so maybe see if the following link helps? It’s for an RGB LED strip, but the controller has Tasmota on it…

Thanks for your reply.

The issue with the link you posted is that it is a text based configuration for mosquitto.
I’m using the embedded broker, which is already configured via paperUI.
In the past I have used mosquitto as my broker, and a text based configuration, with these same switches…however, it was a few years ago, and I’ve forgotten how to set this up.

Yeah, no idea how to use the embedded broker, though I presume the only difference is how the bridge is setup.

Be aware though that in future releases of openHAB the embedded broker is being removed, so it might be wise to move back to Mosquito again…!

1 Like

Oh ok, I think I’ll backtrack somewhat and get Mosquitto working again.
Thanks for the heads up :+1:

Trying to get mosquitto working and I have the following:

i@raspberrypi:~ $ sudo systemctl status mosquitto
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-06-29 08:19:55 BST; 1min 40s ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 23029 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
 Main PID: 23029 (code=exited, status=1/FAILURE)

Jun 29 08:19:55 raspberrypi systemd[1]: mosquitto.service: Service RestartSec=100ms expired, scheduling restart.
Jun 29 08:19:55 raspberrypi systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Jun 29 08:19:55 raspberrypi systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker.
Jun 29 08:19:55 raspberrypi systemd[1]: mosquitto.service: Start request repeated too quickly.
Jun 29 08:19:55 raspberrypi systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Jun 29 08:19:55 raspberrypi systemd[1]: Failed to start Mosquitto MQTT v3.1/v3.1.1 Broker.
pi@raspberrypi:~ $ sudo systemctl start mosquitto
Job for mosquitto.service failed because the control process exited with error code.
See "systemctl status mosquitto.service" and "journalctl -xe" for details.
pi@raspberrypi:~ $

Did you uninstall the openHAB embedded broker? They might be fighting for access to the same port.

After removing the embedded broker I’d restart openHAB just to be safe…

I had removed the embedded broker, but a restart was all that was needed… Thanks :+1:

Almost there!

I have Mosquitto installed and running, I have defined my Things file as described in the RGB strip controller linked a few posts above, but am having an issue with the JSON transformation:

13:55:54.755 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.POWER' in '{"POWER1":"ON"}'

Change any instance of $.POWER to $.POWER1 in your things file.

Yea, I thought that and already done it:

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [host="192.168.1.114", secure=false]

{

    //RGB1 LED strip

    Thing mqtt:topic:swPorch "Porch Switch" (mqtt:broker:MosquittoMqttBroker) {

        Channels:

            Type switch:switch "Power" [

                commandTopic="stat/Porch/POWER1",

                stateTopic="stat/Porch/RESULT",

                transformationPattern="JSONPATH:$.POWER1",

                on="ON",

                off="OFF"

            ]

            Type switch : reachable "Reachable" [

                stateTopic = "tele/Porch/LWT",

                on="Online",

                off="Offline"

            ]

    }

}

So with the above things file you get the same error in the logs?

What version of openHAB are you running?

Yes, same error.

14:17:25.000 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.POWER' in '{"POWER1":"ON"}'

version 2.5.5

Interesting. openHAB hasn’t picked up the changes in the newer things file for some reason.

Maybe try a restart of openHAB?

Yea, seems so, as I just added the 2nd channel and it isn’t showing the new channel in paperui…restarting now

I’m using Visual Code Studio to edit the things file, but I did also ssh into the PI and saw that the changes were actually in the things file

Ok, so the error for channel 1 has gone and I have tried to add a second channel for the other switch and the things file looks like this:

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [host="192.168.1.114", secure=false]

{

    //Porch Switch

    Thing mqtt:topic:Porch "Porch Switch" (mqtt:broker:MosquittoMqttBroker) {

        Channels:

            Type switch:switch "Power1" [

                commandTopic="stat/Porch/POWER1",

                stateTopic="stat/Porch/RESULT",

                transformationPattern="JSONPATH:$.POWER1",

                on="ON",

                off="OFF"

            ]

            Type switch : reachable "Reachable" [

                stateTopic = "tele/Porch/LWT",

                on="Online",

                off="Offline"

            ]

            Type switch:switch "Power2" [

                commandTopic="stat/Porch/POWER2",

                stateTopic="stat/Porch/RESULT",

                transformationPattern="JSONPATH:$.POWER2",

                on="ON",

                off="OFF"

            ]

    }

}

This gives the following error:

14:30:41.121 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.POWER1' in '{"POWER2":"OFF"}'

And the second channel doesn’t show up in the paperui, I guess I’ve configured the things file wrong?

This is probably a result of using the RESULT topic in stateTopic. Anytime anything changes in the device the RESULT topic will be fired. As both channels subscribe to that topic they will both try to extract their particular JSONPATH. One will of course be wrong.

What happens if you use stat/Porch/POWER1 in the stateTopic for the first channel, and stat/Porch/POWER2 in the second channel?

I’ve also just noticed: your commandTopic should probably be something like cmnd/Porch/POWER1 for the first channel, and similarly cmnd/Porch/POWER2 for the second.

And lastly, the second channel change

Type switch:switch "Power2"

to

Type switch:switch2 "Power2"

The name after the colon is the unique identifier for that channel, so it must be unique!

So the second channel is now showing up, but both channels give the following error (almost like transformation is no longer need?)

14:55:19.963 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.POWER1' in 'OFF'
14:55:19.966 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.POWER1' in 'OFF'

The error for channel 2 is the same, but with POWER2 instead