crteensy
(Christoph)
July 21, 2016, 11:32pm
1
I have a device that subscribes to device/kueche/licht/set to receive commands. When its state changed, it publishes to device/kueche/licht. This works fine when using an android app to publish and subscribe to those topics. I can also see the correct traffic on a linux laptop using mosquitto_pub and mosquitto_sub.
However, I’m having trouble configuring an item to send the correct commands. Here’s my current item configuration:
Switch Licht_kueche “Licht Küche” (gTest) {mqtt="<[piffi-mosquitto:device/kueche/licht:state:ON:1]",
mqtt="<[piffi-mosquitto:device/kueche/licht:state:OFF:0]",
mqtt=">[piffi-mosquitto:device/kueche/licht/set:command:ON:1]",
mqtt=">[piffi-mosquitto:device/kueche/licht/set:command:OFF:0]"}
(no line breaks in the actual code)
What works: when I publish using the android app, the device changes its state and this is immediately reflected by the item. When the device is ON (after I switched it on using android), I can only use the item to switch it off.
Why? What’s wrong with my config?
imhofa
(Andreas Imhof)
July 22, 2016, 5:01am
2
Hello Christoph,
the binding of the item is wrong. You should once configure your binding (mqtt) and within the " you describe the commands:
Switch Licht_kueche "Licht Küche" (gTest) {mqtt="<[piffi-mosquitto:device/kueche/licht:state:ON:1], <[piffi-mosquitto:device/kueche/licht:state:OFF:0], >[piffi-mosquitto:device/kueche/licht/set:command:ON:1], >[piffi-mosquitto:device/kueche/licht/set:command:OFF:0]"}
crteensy
(Christoph)
July 22, 2016, 6:38am
3
OK that makes sense, I just didn’t adapt the examples correctly.
Furthermore, I conclude that it’s not possible to mix MQTT for status and a REST interface for commands?
watou
(John Cocula)
July 22, 2016, 7:38am
4
The in-bound binding config strings should be in this format :
Switch Licht_kueche "Licht Küche" (gTest) {
mqtt="<[piffi-mosquitto:device/kueche/licht:state:MAP(onoff.map)],
>[piffi-mosquitto:device/kueche/licht/set:command:ON:1],
>[piffi-mosquitto:device/kueche/licht/set:command:OFF:0]"}
with transform/onoff.map
containing something like:
0=OFF
1=ON
You can add other bindings to the item, like if you wanted to send commands via HTTP:
Switch Licht_kueche "Licht Küche" (gTest) {
mqtt="<[piffi-mosquitto:device/kueche/licht:state:MAP(onoff.map)]",
http=">[*:POST:http://www.domain.org/kueche/licht/?status=%2$s]" }
So the item gets its state from MQTT, but forwards its commands over HTTP.
crteensy
(Christoph)
July 22, 2016, 7:00pm
5
both suggested solutions work well, but the second one:
Switch Licht_kueche "Licht Küche" (gTest) {
mqtt="<[piffi-mosquitto:device/kueche/licht:state:MAP(onoff.map)],
>[piffi-mosquitto:device/kueche/licht/set:command:ON:1],
>[piffi-mosquitto:device/kueche/licht/set:command:OFF:0]"}
seems to be slightly more responsive. Does the number of bind statements have such a visible effect on performance?
crteensy
(Christoph)
July 22, 2016, 7:20pm
6
I just tried two config parts instead of four or three and that seems to work too:
Switch Licht_kueche "Licht Küche 2" (gTest) {mqtt="
<[piffi-mosquitto:device/kueche/licht:state:MAP(kueche_licht.map)],
>[piffi-mosquitto:device/kueche/licht/set:command:*:MAP(kueche_licht_set.map)]
"}
kueche_licht.map:
0=OFF
1=ON
kueche_licht_set.map:
OFF=0
ON=1
Also, line breaks seem to be allowed - is that correct?
Simplifying further:
Switch Licht_kueche "Licht Küche 3" (gTest) {mqtt="
<[piffi-mosquitto:device/kueche/licht:state:default],
>[piffi-mosquitto:device/kueche/licht/set:command:*:MAP(kueche_licht_set.map)]
"}
because the device sends “0” and “1” which openHAB seems to interpret correctly. Great!
Not quite - I get warnings:
[WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn't post update for 'Licht_kueche'
1 Like