Beginner, 1st sitemap & sonoff.items via MQTT, just missing something!

  • Platform information:
    • Hardware: rPi 3
    • OS: openHABianPi 4.9.80-v7
    • openHAB version:2.3.0-1 (Release Build)
  • Issue of the topic: 1st openhab2 build, using the openhabianpi image, and mosquitto.
    The target is Sonoff 4ch switch running Tasmota firmware with MQTT configurations.
    The connection from PC client (MQTT.fx 1.6) through mosquitto to the Sonoff switch works fine.
    The topic structure which works is:
    Dragon/Basem/Lights1/cmnd/power2
    and the payload/command is “on” or “off” and doesn’t seem to be case sensitive.

The MQTT # topic and logs are showing that this works, (also the lights go on/off!)

So now I’m trying to work out why the MQTT setup in the item isn’t working.
MQTT log shows no activity when I hit the switch on the sitemap.
openhab log shows the switch being activated, so there’s a break & it’s almost certainly my poor understanding of the syntax of the item file entry.
mqtt.cfg:
mqtth2.url=tcp://localhost:1883
mqtth2.user=openhabian
mqtth2.pwd=password

sonoff.items:
Switch Pwr_B_2 “Basement-2 Light” (LR,gLight)
{ mqtt=">[mqtth2:Dragon/Basem/Lights1/cmnd/power2:command:*:default],
<[mqtth2:Dragon/Basem/Lights1/cmnd:status:default]" }

dragon.sitemap:
sitemap dragons_lair label=“Dragons Lair” {
Frame label=“Basement” icon=“basement” {
Switch item=Pwr_B_2 icon=“light” label=“Basement Pwr 2”
Group item=Basement_Lights
}

openhab log:
2018-11-12 19:15:51.280 [ome.event.ItemCommandEvent] - Item ‘Pwr_B_2’ received command ON
2018-11-12 19:15:51.295 [vent.ItemStateChangedEvent] - Pwr_B_2 changed from OFF to ON
2018-11-12 19:15:51.303 [GroupItemStateChangedEvent] - gLight changed from OFF to ON through Pwr_B_2
2018-11-12 19:15:53.043 [ome.event.ItemCommandEvent] - Item ‘Pwr_B_2’ received command OFF
2018-11-12 19:15:53.064 [vent.ItemStateChangedEvent] - Pwr_B_2 changed from ON to OFF
2018-11-12 19:15:53.079 [GroupItemStateChangedEvent] - gLight changed from ON to OFF through Pwr_B_2

I’ve spent a long time to understand the sonoff firmware, and the MQTT part of it, now I just need to understand the openhab part. I’ve done a lot of reading, but it’s still not clear in my head. I’m sure once I have made it work once I’ll be fine, but there are 239 different ways I’ve NOT made it work so far…
There’s two things I don’t understand about that item syntax, (LR,glight)?
Also - how does the sitemap know which file has the item? (I’m guessing the unique name because all items files are parsed?)
I found another help conversation & tried to convert it to my topic, but I really don’t know where to go from here.
Any nudge in the right direction would be very much appreciated.

This part

 (LR,glight)

is a group declaration …your item will be a part of those groups…

When trying to troubleshoot mqtt its a good thing to try to watch whats passing through your mqtt-broker…you can do that with this linux command:

mosquitto_sub -v -h localhost -p 1883 -t '#'

I also think this part of the item is wrong:

{ mqtt=">[mqtth2:Dragon/Basem/Lights1/cmnd/power2:command:*:default],
<[mqtth2:Dragon/Basem/Lights1/cmnd:status:default]" }

I would change it to:

Switch Pwr_B_2 “Basement-2 Light” (LR,gLight)  {mqtt=">[mqtth2:Dragon/Basem/Lights1/cmnd/power2:command:ON:on],>[mqtth2:Dragon/Basem/Lights1/cmnd/power2:command:OFF:off]" }

Hi Johan,

Magnificent, thanks very very much. Took me a while to spot the missing " in your line, (because I’m a bit slow!) but I got there.

That’s just great, much appreciated, I’m sure I can move on from here for a bit…
I am certain I’ll be asking more Q’s though.

Many thanks
Lee

Sorry about that… Edited now…

Assuming your MQTT Topic is “Lights1” and that your are trying to switch the second switch of your 4ch switch I would change that to:

Switch Pwr_B_2 “Basement-2 Light” (LR,gLight)
{ mqtt=">[mqtth2:cmnd/Lights1/POWER2:command:*:default],
<[mqtth2:stat/Lights1/POWER2:state:default]" }

The command part works with the * for both states (ON and OFF). Copied from my working setup for a sonoff Dual

A good place for sonoff questions is Tasmota - OpenHAB Wiki

All item-files are loaded by OH (an item doesn’t have to be on a sitemap!). The sitemap gets ist items from the running OH instance.

Hi Jurgen,

Thanks for the info. Interestingly I’ve looked at that Wiki, and got only so far before hitting that brick wall.
I think the problem stems from the “Topic” not working.
The “Full Topic” does work, that’s why my original file looked like that.
However, I’ve failed to make “Topic” ever give me any results, regardless of settings, so I tried “Full Topic” and that worked, so I moved on from there, hoping to understand it a bit more and then loop back to fix the “Topic” bit later!
{Background - I’m using the gitclone of version 5.14 from a few months ago, and compiling it wih Atom ide.
There are a couple of things which don’t work for me using this method, I can’t get a web page up to change any variables, (but HTTP commands work OK) and the “topic” thing doesn’t work either.}

Thanks for the assist, maybe I’ll try the default download binary & see where I get with that…

Hi Jurgen,

Thanks for that interesting reply, I tried that syntax, but it didn’t work.
As a test I downloaded 6.3 binary “sonoff.bin” and setabout configuring it by web page. Not as tiresome as I had expected, thought it was maybe slightly easier than hard coding the source & compiling…
Anyway, two positive things came out of this test.

  1. The web page configuration worked (which maybe it doesn’t if you hard code stuff & compile!)
  2. The longform FULL TOPIC worked exactly as before, and the shortform topic failed exactly as before. So at least I’m not doing something wrong in the configure/compile.

Here’s the info page: (edited for the interesting bits)
Sonoff 4CH Module
Program Version 6.3.0
Build Date & Time 2018-10-30T17:33:53
Core/SDK Version 2_3_0/1.5.3(aec24ac9)
Friendly Name 1 Sonoff
Friendly Name 2 Sonoff2
Friendly Name 3 Sonoff3
Friendly Name 4 Sonoff4
MQTT Host 192.168.200.5
MQTT Port 1883
MQTT Client & Fallback Topic DVES_B2CC29
MQTT User mqttuser
MQTT Topic erik
MQTT Group Topic sonoffs
MQTT Full Topic Dragon/Basem/Lights3/cmnd/

and the mqtt command is cmnd/Lights3/Power2 with a payload of ON OFF or TOGGLE
It certainly makes it into the MQTT server, but has no reaction from the module.

Suggestions welcome, but if not, then I’ll stick with the FULL TOPIC…
Thanks & best regards
Lee

I think the custom full topic you are using is the difference to the standard and my setup. Using the standard the Topic would be a part of the Fulltopic, so you have probably setup both of them differently, on purpose?

Hi Jurgen,

Aaaah, that sounds very plausible.
Just tested it, so now it has the same full topic Dragon/Basem/Lights3/cmnd/ (still works)
and the short topic is now “Lights3”
This mqtt doesn’t work:
cmnd/Lights3/POWER1 off

but nope it ignores that mqtt command. I guess I’m still missing something, but I fully embrace your note, and I’ll be thinking about fixing that, thanks.
I’m very pleased I now have this “vanilla” test unit with standard firmware :wink: it emilinates a LOT of variables which is vital for getting a fix I think.
many thanks and best regards
lee