Need help with things file for Sonoff switch

I’ve been using openHAB and have created a system with a Garage Door Opener/Monitor, a Water Heater temperature monitor and a couple of switches. I started by creating everything in the GUI then went to files for sitemap and items. I’m now trying to convert the smart switches to use a things file. I deleted one of the switches in PaperUI and created a things file for it.
ClassicUI is showing the switch correctly, it switches on and off and indicates the state with ON or OFF and the icon changes colour.
My problem is nothing happens. I’ve checked with MQTT.fx and the second switch configured in PaperUI sends commands to the switch but no command is sent from the first switch when operated.
Here are the contents of my item. and things files.
Switch s26_1 “S26_1 On/Off [%s]” {channel=“mqtt:topic:sonoffs26_1”} // Not working
Switch s26_2 “S26_2 On/Off [%s]” {channel=“mqtt:topic:6ac5f883:sonoffs26_2”} // Working
Bridge mqtt:systemBroker:embedded-mqtt-broker [host=“openhab”, secure=false, retain=true] {
Thing mqtt:topic:sonoffs26_1 “sonoffs26_1” @ “myHome/Living_Room” {
Type switch : power “S26_1 On/Off” [

Can anyone suggest where I have gone wrong.

I use tasmota firmware with sonoff devices, add it in paperui, create related item from paperui and manage from simple UI or rules file.
Why set things from file if not necessary?
Can you show us mqqt messages?
This is my paperui example with tasmota lite and sonoff mini :slight_smile:
MQTT State Topic
An MQTT topic that this thing will subscribe to, to receive the state. This can be left empty, the channel will be state-less command-only channel.

MQTT Command Topic
An MQTT topic that this thing will send a command to. If not set, this will be a read-only switch.

Custom On/Open Value
A number (like 1, 10) or a string (like “enabled”) that is additionally recognised as on/open state. You can use this parameter for a second keyword, next to ON (OPEN respectively on a Contact).

Custom Off/Closed Value
A number (like 0, -10) or a string (like “disabled”) that is additionally recognised as off/closed state. You can use this parameter for a second keyword, next to OFF (CLOSED respectively on a Contact).

I thought I made it clean in my post, I’ve already done all that. I’m after advice on creating a things file.
Why? Because I like to lift the bonnet.

Try adding the ON and OFF as below:

Bridge mqtt:systemBroker:embedded-mqtt-broker [host=“openhab”, secure=false, retain=true] {
  Thing mqtt:topic:sonoffs26_1 “sonoffs26_1” @ “myHome/Living_Room” {
      Type switch : power “S26_1 On/Off” [

You’ve probably got two broker bridge Things now, one from PaperUI and one created from your file.
It is possible to make two bridges to the same broker but I think you need to be very careful about it. Just making a duplicate is doomed, I think.

In addition to @rossko57s statement, whenever creating things via file, look on PaperUI in order to get the correct syntax for the channel statement. You can’t change the thing created by file on PaperUi but it will show there!

I did try on=“ON” and off=“OFF” and just added it again but it made no difference.

Thanks rossko,
I think you are correct. I had the Bridge statement in both my nodemcu1.things and also sonoffs26.things files so I’ve removed the one from this file but it didn’t make any difference.
There is only one MQTT Binding showing under Bindings in PaperUI.
In Services I have MQTT Services Broker and MQTT system broker connection. Clicking Manage in the system broker connection show nothing. Are these correct?

I’ve no idea. You said you had one MQTT derived Item working, so if that still works you have a working broker. You probably need to link your other generic MQTT Thing to the correct bridge broker Thing.

It gets messy if you sdcatter your config across PaperUI, and multiple files as well, but it can be done…

If you do not use, or can not use the hierarchy -

Bridge blah { 
    Thing {

Then you have to tell each topic Thing what Bridge it belongs to.

I’ve recreated the switch in PaperUI and again it is working.
Here is what I have in PaperUI for the working thing

Name = SonoffS26_1
Location = myHome/Living_Room
Bridge Selection = MQTT Broker-mqtt:systemBroker:embedded-mqtt-broker

MQTT State Topic = stat/sonoffs26_1/POWER
MQTT Command Topic = cmnd/sonoffs26_1/POWER

Linked Item
Label = S26_1 On/Off (s26_1)
Type = Switch

While testing I’ve found another strange behavior.
When testing the script I disable the GUI created thing and when testing the GUI created thing I change the thing file extension to disable it but when I do this all things go offline. In PaperUI they show UNINITIALIZED_HANDLER_MISSING_ERROR and I have to restart the openhab2 service to get them back online. Is this normal or is it part of my problem?

Many bindings are not so clever at handling in-flight edits of Things. It’s common to need to restart the binding at least to deal with it.

OK. I’ll ignore the offlines and just keep restarting after I have made changes.
Through experimenting with the things suggested I’ve found if I comment out the Bridge statement and add (mqtt:broker:127_0_0_1_1883) to my thing then the thing does not appear under things in PaperUI.

I have a two things files one for a nodemcu and the other for SonoffS26. Should I have the Bridge statement at the start of both or is it better to consolidate them into one things file with a Bridge statement at the start?

In my details of the PaperUI thing above there is a Link to s26_1 but s26_1 is not in my things file. Should it be?

No. Do not create duplicates.

You will find it easier to manage, but that’s up to you.

No idea. By editing and deleting stuff, you can create orphan links to non-existing Items, probably smart to remove if you think there is no Item.

Thanks rossko,
Am I getting frustrated.
Between posts I’ve continue to search the forum. In another thread it was suggested to create a Bridge thing which I did, removing the Bridge statements from my two things files and putting it in the bridge.things file but this didn’t work, nodemcu1 and sonoff26 things remained offline even after a reboot. Maybe it has something to do with the order in which openhab reads the things files.
I’ve now consolidated all scripted things into one file and the nodemcu1 is still working but my sonoffs26_1 is not.

Here are my items and new things files.


Bridge mqtt:systemBroker:embedded-mqtt-broker [host=“openhab”, secure=false, retain=true] {
Thing mqtt:topic:nodemcu1 “nodemcu1” @ “myHome/Outside” {
Type number : temperature “Temperature” [
Thing mqtt:topic:sonoffs26_1 “SonoffS26_1b” @ “myHome/Living_Room” {
Type switch : power “S26_1 On/Off” [


Switch s26_1 “S26_1 On/Off [%s]” {channel=“mqtt:topic:sonoffs26_1”} // Not working
Switch s26_2 “S26_2 On/Off [%s]” {channel=“mqtt:topic:6ac5f883:sonoffs26_2”} // Working with GUI create thing

Have you looked on PaperUI in order to check the needed syntax for the channel of the sonoffS26_1?
My guess for the needed syntax would be:
Switch s26_1 “S26_1 On/Off [%s]” {channel=“mqtt:topic:embedded-mqtt-broker:sonoffs26_1”}

1 Like

If that one is working, then you must have another Bridge Thing as well as the one defined in your file, because 6ac5f883 is not the name of your file defined Bridge.

As I said earlier, you can have two Bridges to the same actual broker, but it needs to be carefully controlled. Two accidental links to same broker probably will not work.

1 Like

FYI,Support for the embedded broker has been dropped, you may want to use a different one e.g. Mosquitto.

Thanks opus,

I had already tried that syntax but it didn’t work but to be sure I tried it again and it still doesn’t work.
I’m restarting after every change now to make sure any changes I make are recognised.

Thanks everyone for you help, I found where I was going wrong.
I looked at the script created thing in PaperUI and as you can see below there is “power” at the end of the statement. I’ve been over this time and again and I’d swear that wasn’t there before. I added this to the switch definition in the items script and it worked.


Line from items file;
Switch s26_1 “S26_1 On/Off [%s]” {channel=“mqtt:topic:sonoffs26_1:power”} // Working

Thanks again to everyone who offered help, I was about to give up and stick with the PaperUI created thing. Now to change my second Sonoff S26 from GUI to script.