edsel
(Harry Kas)
March 19, 2018, 3:51pm
1
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?
hr3
(Harry)
March 19, 2018, 3:59pm
2
You use the same name 2 times in items
1 Like
edsel
(Harry Kas)
March 19, 2018, 4:01pm
3
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]" }
edsel
(Harry Kas)
March 19, 2018, 6:48pm
5
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
edsel
(Harry Kas)
March 20, 2018, 8:46am
7
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
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
vzorglub
(Vincent Regaud)
March 20, 2018, 9:33am
9
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
edsel
(Harry Kas)
March 20, 2018, 9:40am
10
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"
}
}
vzorglub
(Vincent Regaud)
March 20, 2018, 9:47am
11
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
edsel
(Harry Kas)
March 20, 2018, 9:58am
12
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.
edsel
(Harry Kas)
March 20, 2018, 10:21am
13
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” ?
vzorglub
(Vincent Regaud)
March 20, 2018, 11:17am
14
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" }
edsel
(Harry Kas)
March 20, 2018, 12:33pm
15
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.
vzorglub
(Vincent Regaud)
March 20, 2018, 12:38pm
16
Ok, back to basics
What do you use the sonoff for?
edsel
(Harry Kas)
March 22, 2018, 10:16am
17
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.
vzorglub
(Vincent Regaud)
March 22, 2018, 10:46am
18
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]"}
edsel
(Harry Kas)
March 22, 2018, 10:59am
19
Hi Vincent, Did you understand that the switch is working fine with the settings from topic 10 from Mar 20?
vzorglub
(Vincent Regaud)
March 22, 2018, 12:03pm
20
No sorry.
Can you mark the thread as solved, please?
1 Like