What is wrong in my cfg- eller items-commands? (ESPEasy and openHAB 2)

I am new in this openHAB 2 and ask you for some help with a Sonoff S20 that I try to connect to openHAB 2 that is installed on a Synology NAS.
I have flashed the Sonoff with ESPEasy.

mqtt.cfg has only two lines:

mybroker.url=tcp://192.168.1.51:1883
mybroker.clientId=nas

switch.items contains:

Switch VDrummet "Vardagsrummet" {mqtt=">[mybroker:/BalkongdorrLamp/lightSwitch/Switch:command:ON:1],>[mybroker:/BalkongdorrLamp/lightSwitch/Switch:command:OFF:0],<[mybroker:/BalkongdorrLamp/lightSwitch/Switch:state:ON:1],<[mybroker:/BalkongdorrLamp/lightSwitch/Switch:state:OFF:0]"}
Switch VDrummet "Vardagsrummet" {mqtt=">[mybroker:/BalkongdorrLamp/lightState/Switch:command:ON:1],>[mybroker:/BalkongdorrLamp/lightState/Switch:command:OFF:0],<[mybroker:/BalkongdorrLamp/lightState/Switch:state:ON:1],<[mybroker:/BalkongdorrLamp/lightState/Switch:state:OFF:0]"}

vardagsrummet.things

Thing network:device:switch "BalkongLampa" @ "BalkongdorrLamp" [ hostname="192.168.1.210" ]

demo.sitemap

sitemap demo label="Huset" {
    Frame label="Datum" {
        Text item=Date
    }
 	Frame label="MQTT" {
		Switch item=VDrummet label="Vardagsrummet Balkong"	
	}
}

With Basic UI the switch is visible and can be switched on and off.

With the command

/mosquitto_sub -v -h 192.168.1.51 -t '#'

I can see that the following information is sent:

/BalkongdorrLamp/lightState/Switch 0
/BalkongdorrLamp/lightState/Switch 1
/BalkongdorrLamp/lightState/Switch 0
/BalkongdorrLamp/lightState/Switch 1
/BalkongdorrLamp/lightState/Switch 0
/BalkongdorrLamp/lightState/Switch 1
/BalkongdorrLamp/lightState/Switch 0

But the switch does not change.

Can somebody tell me what I am doing wrong?

You use the same name 2 times in items

1 Like

Ok, thanks. I will change that and see if it works.

Just a question. What is the goal of the thing definition?
For switching the sonoff it is not neccersary.
Your correct item definition (if only one!) could be made shorter.
For example:
Switch Sonoff_S20_4 “Sonoff_S20_4” (gLight)
{ mqtt=">[broker:cmnd/sonoff-084CBE/power:command:*:default], <[broker:stat/sonoff-084CBE/POWER:state:default]" }

It is for the first time that I use openHAB, I thought that I always needed a thing definition.

What does the sonoff-084CBE mean and where do I find this expression for other sonoff devices?

Thanks for your help.

sonoff-084CBE ist just the name off the switch.
I use the topic definition from Theo Arendst see


Here you find a few examples, and it is a good starting point.

1 Like

Your example works with Tasmota,
but my Sonoff is flashed with ESPEasy.

So please some example for ESPEasy items in openHAB 2.

Hi. 100% work :smile:

Switch   Device_Water_Switch   "Water Valve"	   <water>   { mqtt="<[zbox:/water/sensors/state:state:MAP(1_is_on.map)], >[zbox:/water/sensors/setstate:command:*:MAP(on_is_1.map)]" }

1_is_on.map:

0=OFF
1=ON
-=?
NULL=?

on_is_1.map:

OFF=0
ON=1

Hi,

You should try to avoid staring your MQTT topics with /
Essentially it create an empty “root” topic and although allowed by the MQTT protocol it is not best practice and can lead to errors and/or confusion

Regards

Hi,

Thanks for your help, guys!

I got it working with the following switch.items:

Switch mySwitch01 "Vardagsrummet"  {mqtt=">[mybroker:/BalkongdorrLamp/gpio/12:command:ON:1],>[mybroker:/BalkongdorrLamp/gpio/12:command:OFF:0],<[mybroker:/BalkongdorrLamp/lightState/Switch:command:OFF:0],<[mybroker:/BalkongdorrLamp/lightState/Switch:command:ON:1]"}

And demo.sitemap:

sitemap demo label="Huset" {
    Frame label="Datum" {
        Text item=Date
    }
 	Frame label="MQTT" {
		Switch item=mySwitch01 label="Vardagsrummet Balkong"	
	}
}

It looks like you could create an MQTT loop there
The input “<” mqtt should be state not command
Try changing the last two to:

<[myBroker:/BalkongdorrLamp/lightState/Switch:state:MAP(0off1on.map)

and create a map file named 0off1on.map containing:

0=OFF
1=ON
1 Like

I tried your proposal and changed switch.items to:

Switch mySwitch01 "Vardagsrummet"  {mqtt=">[mybroker:/BalkongdorrLamp/gpio/12:command:ON:1],>[mybroker:/BalkongdorrLamp/gpio/12:command:OFF:0],<[mybroker:/BalkongdorrLamp/lightState/Switch:state:OFF:0],<[mybroker:/BalkongdorrLamp/lightState/Switch:state:ON:1]"}

But then I loose some functionality: The button on the S20 does not work correct anymore and the icons/button on the BasicUI don’t change color anymore.

However, thank you for your help.

Sorry, I made a mistake. It works with your change.
But it does not change anymore the button on the BasicUI.

Why do you make this extra MAP-file instead of writing “…state:0=OFF” ?

The map traslates the info received from 0 to OFF and 1 to ON
You could use 2 “input” instructions instead
It is very useful when you get information with several values

try adding autoupdate=false at the end of the binding
like this

{ mqtt="whateverthebindingis", autoupdate="false" }

No, it does not change the color of the button on the BasicUI and it does not change when the button is pressed.

In the Sonoff I have the following rule:

on lightSwitch#Switch do
   if [lightState#Switch]=0
      gpio,12,1
   else
      gpio,12,0
   endif
endon

While everything is working correctly with the code in answer 10.

Ok, back to basics
What do you use the sonoff for?

Hi, I use the Sonoff for switching a lamp.
And the next step will be that the lamp will switch on depending of the sunset and switch of depending of the time setting.

Try this one:

Switch mySwitch01 "Vardagsrummet"  {mqtt=">[mybroker:/BalkongdorrLamp/gpio/12:command:ON:1],>;[mybroker:/BalkongdorrLamp/gpio/12:command:OFF:0],<;[mybroker:/BalkongdorrLamp/lightState/Switch:state:0:OFF],<;[mybroker:/BalkongdorrLamp/lightState/Switch:state:1:ON]"}

Hi Vincent, Did you understand that the switch is working fine with the settings from topic 10 from Mar 20?

No sorry.
Can you mark the thread as solved, please?

1 Like