Emil
(Emil)
May 31, 2017, 9:50am
1
Hello. I’m studying openhab and mqtt. Set up a broker mosquitto, created test items:
Switch mqttsw1 "Switch 1" (all) {mqtt=">[mosquitto:/testsw/1:command:on:default],>[mosquitto:/testsw/1:command:off:default]"}
And displayed on a sitemap:
sitemap default label="My first sitemap"
{
Frame label="MQTT" {
Switch item=mqttsw1 label="MQTT Switch 1"
}
}
If you change the position of the switch, the messages testsw / 1: ON are published. But when I publishes testsw / 1: OFF with another client mqtt, the basic UI switch does not change its position. How do I make the switch position change when I get the publication?
Dim
(Angelos)
May 31, 2017, 10:04am
2
This is because you have not configured an inbound configuration (a subscription to a topic) in OH2 to be able to read the status of the device/switch.
modify your item line as follows:
Switch mqttsw1 "Switch 1" (all) {mqtt=">[mosquitto:/testsw/1:command:*:default],<[mosquitto:/testsw/1:state:state:default]"}
or:
Switch mqttsw1 "Switch 1" (all) {mqtt=">[mosquitto:/testsw/1:command:on:default],>[mosquitto:/testsw/1:command:off:default],<[mosquitto:/testsw/1:state:state:default]"}
This assumes that your device supports status reporting
Hmm did I do something wrong with my Sonoff ?
Because I can turn on/off but same as @Emil it does not update the status.
Switch MQTT_Grill "MQTT Grill Lampe" (ALL,Office_Outdoor, Office_First_Floor, MySQLPersist) { mqtt=">[mosquitto:cmnd/sonoff-977686/POWER:command:*:default], <[mosquitto:stat/sonoff-977686/POWER:state:default]" }
Dim
(Angelos)
May 31, 2017, 10:27am
4
Your item config looks good and it is according to the info that I can find (I don’t use the sonoff myself):
Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP...
ITEAD Smart Home Products
https://www.itead.cc/wiki/Sonoff_Smart_Home_Solution
[image][image][image]
These very cheap modules come with their special smartphone app but are all actually based on the famous ESP8266. It didn’t take long till the tinkerer community got a hold of that and started hacking. After opening up the cases, all you need to do is solder a few header pins and connect your FTDI breakout programmer. Alternative firmwares are ready to provide nice MQTT based Wifi SmartHome end…
Did status updates work before? maybe you changed something recently in your system?
“Long shot” note: If you recently upgraded your Mosquitto MQTT Broker Server to version 1.4.12, you may have a problem with the clientID naming.
But on the other hand… sonoff-977686
does not include ‘#’, ‘+’, or ‘/’ and you can send on/off commands… so this must not be the root-cause…
See: Redirecting...
2 Likes
Emil
(Emil)
May 31, 2017, 11:34am
5
Unfortunately, it did not help, in mqtt.cfg it is necessary to specify the configuration of data saving?
Dim
(Angelos)
May 31, 2017, 11:37am
6
Which device are you using? (is it a Sonoff module? which one?) Or you are just testing mqtt without a physical device?
No need to change something in mqtt.cfg
Edit: I made a mistake in the item config… try this:
Switch mqttsw1 "Switch 1" (all) {mqtt=">[mosquitto:/testsw/1:command:on:default],>[mosquitto:/testsw/1:command:off:default],<[mosquitto:/testsw/1:state:default]"}
Emil
(Emil)
May 31, 2017, 11:49am
7
So does not work either. At the moment I do not use the module. Now I’m studying openhab, switch to BasicUI and track on android MQTT Dashboard, then publish from mobile i monitor the status change in BasicUI
rossko57
(Rossko57)
May 31, 2017, 12:15pm
8
So you’re saying that you cannot read the status of a device that does not exist?
Emil
(Emil)
May 31, 2017, 12:24pm
9
And the switch should not change its position when receiving the power-on message without the device?
Update:
I just checked my Sonoff MQTTs and now it looks like everything is working fine
1 Like
Dim
(Angelos)
May 31, 2017, 4:29pm
11
This should work (it works for me at least):
Switch mqttsw1 "Switch 1" (all) {mqtt=">[mosquitto:testsw/1:command:*:default],<[mosquitto:testsw/1:state:default]"}
Publish a message from another client and see your switch react in your OH2 sitemap:
mosquitto_pub -t testsw/1 -m OFF
1 Like
Emil
(Emil)
May 31, 2017, 6:52pm
12
Yes, it works. Thanks for the help.
Explain to me please to understand what it means *, it turns out it accepts all the messages of publication testsw \ 1?
Dim
(Angelos)
June 1, 2017, 1:14am
13
It’s the trigger for the outbound message.
See: http://docs.openhab.org/addons/bindings/mqtt1/readme.html#item-configuration-for-outbound-messages
Instead of using 2 entries for ON & OFF like in your first post, you use 1 entry with *
Emil
(Emil)
June 4, 2017, 3:26pm
14
I apologize. I do not understand how status works. The device is connected, this is es8266 + DHT22. If you switch the switch to OpenHAB on other devices, the state will change, but if you switch to a smartphone, the status does not change in openhab and does not update the temperature information, it is updated only after the page reloads. Tell me, what will I miss?
Switch mqttsw1 "Switch 1" (all) {mqtt=">[mosquitto:/ESP/LED/001:command:on:1],>[mosquitto:/ESP/LED/001:command:off:0],<[mosquitto:/ESP/LED/001:state:default]"}
Number temp "temp [%.1f]" {mqtt="<[mosquitto:/ESP/DHT/TEMP:state:default]"}
Text item=temp label="Temp [%s C]" icon="temperature"
Switch item=mqttsw1 label="MQTT Switch 1"
1 Like
gosouth
(Gosouth)
May 29, 2018, 4:21pm
15
If I use the :command:*:default the switch does not change. What is wrong?
Thanks.
THIS WORKS:
Switch qLDbed "LD Bed" (gESP8266) {mqtt="
>[broker:/pucon/haus/licht/control:command:ON:1],
>[broker:/pucon/haus/licht/control:command:OFF:0],
<[broker:/pucon/haus/licht/state:state:default]" }
THIS DOES NOT WORK:
Switch qLDbed "LD Bed" (gESP8266) {mqtt="
>[broker:/pucon/haus/licht/control:command:*:default],
<[broker:/pucon/haus/licht/state:state:default]" }
Dim
(Angelos)
May 29, 2018, 5:53pm
16
obviously, your ESP code does not accept ON/OFF commands. Only 1/0.
The first version of the item config transforms the ON from openHAB to 1 (this will be mqtt payload that will be published).
You can check the payload in both scenarios using a tool (like MQTT.fx)
vzorglub
(Vincent Regaud)
May 29, 2018, 6:06pm
17
You can add mapping to openHAB to do the transformation from ON to 1 and OFF to 0 for you.
In your transform folder add a file called ON1OFF0.map with the following content:
OFF=0
ON=1
Now you item is:
Switch qLDbed "LD Bed" (gESP8266) {mqtt=">[broker:/pucon/haus/licht/control:command:*:MAP(ON1OFF0.map)], <[broker:/pucon/haus/licht/state:state:default]" }
1 Like
gosouth
(Gosouth)
May 29, 2018, 7:12pm
18
Dim, you are right!
Thank you and Mr. MQTT.fx a lot.
1 Like
gosouth
(Gosouth)
May 29, 2018, 7:23pm
19
Hello Vincent, this works however with :
OFF=0
ON=1
thanks.
vzorglub
(Vincent Regaud)
May 29, 2018, 7:24pm
20
Yes sorry my bad. If your ESP published 0 or 1 as a state then you can use OFF=0 and ON=1 in the inbound mqtt