How to setup a Sonoff 4ch in openHAB

I have recently installed the latest version of openHAB on a raspberry pi 3 b+. all the add ons were installed as well as mqtt binding. the consol from my Sonoff says it is connected via mqtt to openhab.

I am trying to get the the switch into opneHAB UI but am so far unsuccessful. the below content in the file “sonoff4ch.items” I created in the items folder.

//Sonoff 4ch Master Bedroom

Switch Sonoff4ch_4Channel1 “Channel 1” [ “Switchable” ] { mqtt=">[broker:sonoff/Sonoff4ch_4/cmnd/POWER1:command::default],<[broker:sonoff/Sonoff4ch_4/cmnd/POWER1:state:default]" }
Switch Sonoff4ch_4Channel2 “Channel 2” [ “Switchable” ] { mqtt=">[broker:sonoff/Sonoff4ch_4/cmnd/POWER2:command:
:default],<[broker:sonoff/Sonoff4ch_4/cmnd/POWER2:state:default]" }
Switch Sonoff4ch_4Channel3 “Channel 3” [ “Switchable” ] { mqtt=">[broker:sonoff/Sonoff4ch_4/cmnd/POWER3:command::default],<[broker:sonoff/Sonoff4ch_4/cmnd/POWER3:state:default]" }
Switch Sonoff4ch_4Channel4 “Channel 4” [ “Switchable” ] { mqtt=">[broker:sonoff/Sonoff4ch_4/cmnd/POWER4:command:
:default],<[broker:sonoff/Sonoff4ch_4/cmnd/POWER4:state:default]" }

and the code I wrote in “sitemap”

Frame label=“Lights”

Switch item=Sonoff4ch_4Channel1        label="Bedside Lamp 1"       icon="switch"

Switch item=Sonoff4ch_4Channel2 label=“Bedside Lamp 2” icon=“switch”
Switch item=Sonoff4ch_4Channel3 label=“Master Bedroom3” icon=“switch”
Switch item=Sonoff4ch_4Channel4 label=“Master Bedroom4” icon=“switch”


So far nothing seems to show up on the open tab control panel.

can someone please help me with this setup.

First you need to use the code fences when publishing code:

The answer to your problem is right under your nose:
The sonoff MQTT full topic is sonoff/cmnd/sonoff_MasterBedroom/

and topic used in your items is: sonoff/Sonoff4ch_4/cmnd/

Good luck

Hi vzorglub,

I already made that change. thank you. spending so much time sometimes we miss the little things.

I have already made that change but am still not seeing it in the paper ui.

how do I link the items to my sitemap??

any ideas

Your second error is because you didn’t read the docs, both for OH and tasmotta:

From tasmota wiki - openHAB section:

Switch LivingRoom_Light "Living Room Light" <light> (LR,gLight)
    { mqtt=">[broker:cmnd/sonoff-A00EEA/POWER:command:*:default],
            <[broker:stat/sonoff-A00EEA/POWER:state:default]" }

Compare that with your code.

Also you didn’t monitor your log openhab.log to see what errors you had. OH would have told you that ou had a binding parsing error.

I did read through the entire article. I made the following changes also,

Switch Sonoff4ch_4Channel1 “Channel 1” [ “Switchable” ] (LR,gLight) { mqtt=">[broker:sonoff/cmnd/Sonoff4ch_4/POWER1:command::default],<[broker:sonoff/stat/Sonoff4ch_4/POWER1:state:default]" }
Switch Sonoff4ch_4Channel2 “Channel 2” [ “Switchable” ] (LR,gLight) { mqtt=">[broker:sonoff/cmnd/Sonoff4ch_4/POWER2:command:
:default],<[broker:sonoff/stat/Sonoff4ch_4/POWER2:state:default]" }
Switch Sonoff4ch_4Channel3 “Channel 3” [ “Switchable” ] (LR,gLight) { mqtt=">[broker:sonoff/cmnd/Sonoff4ch_4/POWER3:command::default],<[broker:sonoff/stat/Sonoff4ch_4/POWER3:state:default]" }
Switch Sonoff4ch_4Channel4 “Channel 4” [ “Switchable” ] (LR,gLight) { mqtt=">[broker:sonoff/cmnd/Sonoff4ch_4/POWER4:command:
:default],<[broker:sonoff/stat/Sonoff4ch_4/POWER4:state:default]" }

it still does not show up in paper ui.

Because it’s still wrong!

Switch Sonoff4ch_4Channel1 “Channel 1” [ “Switchable” ] (LR,gLight) { mqtt=">[broker:sonoff/cmnd/Sonoff4ch_4/POWER1:command::default],<[broker:sonoff/stat/Sonoff4ch_4/POWER1:state:default]" }
Switch Sonoff4ch_4Channel2 “Channel 2” [ “Switchable” ] (LR,gLight) { mqtt=">[broker:sonoff/cmnd/Sonoff4ch_4/POWER2:command::default],<[broker:sonoff/stat/Sonoff4ch_4/POWER2:state:default]" }
Switch Sonoff4ch_4Channel3 “Channel 3” [ “Switchable” ] (LR,gLight) { mqtt=">[broker:sonoff/cmnd/Sonoff4ch_4/POWER3:command::default],<[broker:sonoff/stat/Sonoff4ch_4/POWER3:state:default]" }
Switch Sonoff4ch_4Channel4 “Channel 4” [ “Switchable” ] (LR,gLight) { mqtt=">[broker:sonoff/cmnd/Sonoff4ch_4/POWER4:command::default],<[broker:sonoff/stat/Sonoff4ch_4/POWER4:state:default]" }

You didn’t put the * between the two :: after the command section in the outbound binding.

These items will never show in paperUI because they are manually created in a text file for a 1.9x binding.
You should see them in the sitemap though once you get the syntax right

its already there. copying and pasting the text here is removing the * between the two : :

Then I would advise not copying and pasting, it tends to delete and insert characters at random especially from a browser.

Oh sorry… that’s y i out the image last time. It’s there still something wrong with the syntax.

No, looks right now.
Do your switches appear in the sitemap?

I have done ssh to my device and viewed the file from there. It is empty and also the switches are not appearing on paper ui

Again, the switches will NEVER appear on paperUI, but they should be on your sitemap
The events.log in is /var/log/openhab2/events.log

ssh in and do
tail /var/log/openhab2/events.log
That will keep a running screen with what happens in the log

Do you have an MQTT client installed like mqtt.fx or mqtt-spy
Install one and subscribe to your mqtt broker witht the topic #
Action the switches on the sonoff, what do you get on mqtt.fx?

Can you show the contents of your mqtt.cfg file, please?

The sitemap folder has only one readme and a file called sitemap which is empty

The following is from

tail /var/log/openhab2/events.log
2018-05-13 11:29:29.485 [vent.ItemStateChangedEvent] - sonoff_MasterBedroom2 changed from ON to OFF
2018-05-13 11:29:30.083 [ome.event.ItemCommandEvent] - Item 'sonoff_MasterBedroom3' received command OFF
2018-05-13 11:29:30.095 [vent.ItemStateChangedEvent] - sonoff_MasterBedroom3 changed from ON to OFF
2018-05-13 11:29:30.750 [ome.event.ItemCommandEvent] - Item 'sonoff_MasterBedroom' received command OFF
2018-05-13 11:29:30.761 [vent.ItemStateChangedEvent] - sonoff_MasterBedroom changed from ON to OFF
2018-05-13 11:29:38.642 [vent.ItemStateChangedEvent] - sonoff_MasterBedroom changed from OFF to ON
2018-05-13 11:29:38.645 [vent.ItemStateChangedEvent] - sonoff_MasterBedroom1 changed from OFF to ON
2018-05-13 11:29:38.667 [vent.ItemStateChangedEvent] - sonoff_MasterBedroom4 changed from OFF to ON
2018-05-13 11:29:38.671 [vent.ItemStateChangedEvent] - sonoff_MasterBedroom2 changed from OFF to ON
2018-05-13 11:29:38.675 [vent.ItemStateChangedEvent] - sonoff_MasterBedroom3 changed from OFF to ON

the file from mqtt.cfg has no settings activated. all fields contain a # in front.

# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.

# Optional. User id to authenticate with the broker.

# Optional. Password to authenticate with the broker.

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

That’s why it doesn’t work!

You need to put the same settings as your sonoff in the mqtt.cfg file:
Name your broker as it is named in your items: broker
Remove the # in the following lines and write the same value
In your log you should see that OH connects to your broker


But again, this was in the docs:

I did everything now. but still the sitemap file is empty and I see no way to control the device from openhab.

It does not get populated by itself, you need to manually add your entries:

So here is my items file

Switch Sonoff4ch_4Channel1 "Channel 1" [ "Switchable" ] <light> (LR,gLight) { mqtt=">[broker:sonoff/cmnd/sonoff_MasterBedroom/POWER1:command:*:default],<[broker:sonoff/stat/sonoff_MasterBedroom/POWER1:state:default]" }
Switch Sonoff4ch_4Channel2 "Channel 2" [ "Switchable" ] <light> (LR,gLight) { mqtt=">[broker:sonoff/cmnd/sonoff_MasterBedroom/POWER2:command:*:default],<[broker:sonoff/stat/sonoff_MasterBedroom/POWER2:state:default]" }
Switch Sonoff4ch_4Channel3 "Channel 3" [ "Switchable" ] <light> (LR,gLight) { mqtt=">[broker:sonoff/cmnd/sonoff_MasterBedroom/POWER3:command:*:default],<[broker:sonoff/stat/sonoff_MasterBedroom/POWER3:state:default]" }
Switch Sonoff4ch_4Channel4 "Channel 4" [ "Switchable" ] <light> (LR,gLight) { mqtt=">[broker:sonoff/cmnd/sonoff_MasterBedroom/POWER4:command:*:default],<[broker:sonoff/stat/sonoff_MasterBedroom/POWER4:state:default]" }

my sitemap file is

sitemap sonoff label="Sonoff Switches"
    Frame label="Date"
        Text item=Date

    Frame label="Master Bedroom"
        Switch item=Sonoff4ch_4Channel1 label="Asma Bedside Light" icon="light"
        Switch item=Sonoff4ch_4Channel2 label="Mufid Bedside Light" icon="light"
        Switch item=Sonoff4ch_4Channel3 label="Bedside Light 1" icon="light"
        Switch item=Sonoff4ch_4Channel4 label="Bedside Light 2" icon="light"

This is from my logs

2018-05-13 14:01:17.259 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'sonoff.sitemap'
2018-05-13 14:01:17.565 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Text
2018-05-13 14:01:17.568 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Date' for widget org.eclipse.smarthome.model.sitemap.Text
2018-05-13 14:01:17.570 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Date' for widget org.eclipse.smarthome.model.sitemap.Text
2018-05-13 14:01:17.572 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Date' for widget org.eclipse.smarthome.model.sitemap.Text
2018-05-13 14:01:17.574 [WARN ] [basic.internal.render.SwitchRenderer] - Cannot determine item type of 'Sonoff4ch_4Channel1'
org.eclipse.smarthome.core.items.ItemNotFoundException: Item 'Sonoff4ch_4Channel1' could not be found in the item registry
	at org.eclipse.smarthome.core.internal.items.ItemRegistryImpl.getItem( [109:org.eclipse.smarthome.core:0.10.0.b1]
	at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getItem( [155:org.eclipse.smarthome.ui:0.10.0.b1]
	at org.eclipse.smarthome.ui.basic.internal.render.SwitchRenderer.renderWidget( [217:org.eclipse.smarthome.ui.basic:0.10.0.b1]
	at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.renderWidget( [217:org.eclipse.smarthome.ui.basic:0.10.0.b1]
	at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren( [217:org.eclipse.smarthome.ui.basic:0.10.0.b1]
	at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren( [217:org.eclipse.smarthome.ui.basic:0.10.0.b1]
	at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processPage( [217:org.eclipse.smarthome.ui.basic:0.10.0.b1]
	at org.eclipse.smarthome.ui.basic.internal.servlet.WebAppServlet.service( [217:org.eclipse.smarthome.ui.basic:0.10.0.b1]
	at org.eclipse.jetty.servlet.ServletHolder.handle( [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle( [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle( [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at []
	at org.eclipse.jetty.server.session.SessionHandler.doHandle( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle( [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
	at org.eclipse.jetty.servlet.ServletHandler.doScope( [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
	at org.eclipse.jetty.server.session.SessionHandler.doScope( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle( [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at org.eclipse.jetty.server.Server.handle( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at org.eclipse.jetty.server.HttpChannel.handle( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at org.eclipse.jetty.server.HttpConnection.onFillable( [87:org.eclipse.jetty.server:9.3.22.v20171030]
	at$ReadCallback.succeeded( []
	at []
	at$ []
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume( [90:org.eclipse.jetty.util:9.3.22.v20171030]
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume( [90:org.eclipse.jetty.util:9.3.22.v20171030]
	at [90:org.eclipse.jetty.util:9.3.22.v20171030]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob( [90:org.eclipse.jetty.util:9.3.22.v20171030]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$ [90:org.eclipse.jetty.util:9.3.22.v20171030]
	at [?:?]

also there is the following error in the logs.

2018-05-13 14:12:18.579 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonoff4ch.items'
2018-05-13 14:12:18.628 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'sonoff4ch.items' has errors, therefore ignoring it: [1,57]: missing EOF at '<'

2018-05-13 14:12:18.655 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'sonoff4ch.items' has errors, therefore ignoring it: [1,57]: missing EOF at '<'

I think there is a problem with linking the switches. where am I going wrong here. Also in the basic UI it does show the switches now.

ok I figured it out.

I changed the switchable field


Switch Sonoff4ch_4Channel1 "Channel 1" [ "Switchable" ] <light> (LR,gLight) { mqtt=">[broker:sonoff/cmnd/sonoff_MasterBedroom/POWER1:command:*:default],<[broker:sonoff/stat/sonoff_MasterBedroom/POWER1:state:default]" }


Switch Sonoff4ch_4Channel1 "Channel 1" <light> (LR,gLight) [ "Switchable" ] { mqtt=">[broker:sonoff/cmnd/sonoff_MasterBedroom/POWER1:command:*:default],<[broker:sonoff/stat/sonoff_MasterBedroom/POWER1:state:default]" }
1 Like

Yes, order of arguments is important:

Itemtype Itemname "Itemlabel" <icon> (group/groups) [ "Tag" ] {binding/bindings}

First and second is mandatory while all other arguments are optional, but you mustn’t change the order.
There is a new task ‘quantitytype’ which is defined in items as well:

Itemtype:Quantity Itemname "Itemlabel" <icon> (group/groups) [ "Tag" ] {binding/bindings}

But it is not well documented yet…