OpenHab, Shelly1, Mosquitto/REST - does not work

Platform information:

  • Hardware: Raspberry PI3
  • OS: Linux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux
  • Java™ SE Runtime Environment (build 1.8.0_191-b12)
  • openHAB version: 2.4.0

Hello,
at the moment I’m trying to integrate the Shelly 1 into my OpenHab via MQTT.
According to the guides here I done following:

  • Install of MQTT Binding (2.4.0)
  • Add thing MQTTBroker
  • Add channel (mqtt:broker:0e1982c5:shelly1-15E1F2)
  • Install mosquito
  • At shelly1 enable option ‘action execution via MQTT’

At mosquitto.log I can see that OpenHab and the Shelly are connected both.

shelly.items

Switch ShellyTest	"Shelly Test" <light>	(gSF_Corridor, Lights)  { mqtt=">[MQTTBroker:shellies/shelly1-15E1F2/relay/0/command:command:*:MAP(shelly.map)],<[MQTTBroker:shellies/shelly1-15E1F2/relay/0:state:MAP(shelly.map)]" }


Switch ShellyTest2  "Shelly Test2" { http=">[ON:GET:http://192.168.0.21/relay/0?turn=on] >[OFF:GET:http://192.168.0.21/relay/0?turn=off]" }

shelly.map

ON=on
OFF=off
off=OFF
on=ON

Do you have any idea what I’m doing wrong? Cause when I press the switch button ‘ShellyTest’, nothing happens. Only the ‘ShellyTest2’ (rest, no MQTT) works fine, but I cannot read the status of the Shelly there.

Thanks a lot
Tobias

The MQTT2 version binding works via Things, Channels and Items linked to Channels.
In your example you are using the old MQTT1 definitions.
So either change your definitions or install the legacy MQTT1 binding.

Ah ok. Can you tell me how to do it with MQTT2?

Thanks sihui, I already read this article, but the configuration is still unclear.

For my shelly1 the MQTT topic should be

shellies/shelly1-15E1F2/relay/0

correct?

When I try to link to channel to a item, the list is empty.
mqtt

That is your broker thing
You now need to add a new MQTT generic thing

PaperUI -> Configuration -> Things -> + -> MQTT -> Add manually -> Generic Thing

1 Like

I’m also struggleing with the new mqtt binding (2.4.0).

I’m using the shelly 2 for controlling the roller shutters. but i don’t get the correct values send via mqtt. the roller shutter item only sends 0 or 100, but shelly expects open or close.
can this be done via a map file? where to put this in paperUI or in item-file?

After reading this howto it is clearer now.

But after creating a Generic Thing and adding a new channel, the status is “OFFLINE - COMMUNICATION_ERROR java.lang.Exception: No MQTT client”

Perhaps there is a misconfiguration of the state and command topic:

stat/shellies/shelly1-15E1F2/relay/0/
cmnd/shellies/shelly1-15E1F2/relay/0/command

http://shelly-api-docs.shelly.cloud/#shelly1-overview:

Shelly1: MQTT
Shelly1 uses the following topics:

shellies/shelly1-<deviceid>/relay/0 to report status: on or off
shellies/shelly1-<deviceid>/relay/0/command accepts on and off and applies accordingly
Shelly1: /settings

That should be correct, isn’t it?

Bug in OH 2.4. this is already fixed in OH 2.5 snapshots. Alternative: declare the broker in a separate file and don’t touch it while openhab is running.

after reading several other threads i’ve found a solution.

just created one channel of type “text”

String Rollo1ArbeitStatus      "Rollo Arbeit [%s]" (gRollo) {channel="mqtt:topic:Rollo1Arbeit:state"}

And in sitemap defined a switch with a mapping.

Switch item=Rollo1ArbeitStatus icon="blinds" mappings=[open="AUF",close="ZU"]

in BasicUI it looks like this, and it works! :wink:
i could add a mapping to show currect state in text next to buttons.

2018-12-31_17h03_37

Rollershutters are percentage values in openHAB, that’s true. Glad you found a solution (a switch is more suitable for shellys in this case).

@ David_Graeff, puh, too much bugs for me :wink:

Do you have any idea, how to get the status of the Shelly via rest? Here I can send a command, but how can I get the status into the switch in addition?

Switch ShellyTest2  "Shelly Test2" { http=">[ON:GET:http://192.168.0.21/relay/0?turn=on] >[OFF:GET:http://192.168.0.21/relay/0?turn=off]" }

There is only one bug (“java.lang.Exception: No MQTT client”) which is amazing for the code size of mqtt related bundles.

Does anybody know, how to get the status of the Shelly via rest? Here I can send a command, but how can I get the status into the switch in addition?

Switch ShellyTest2  "Shelly Test2" { http=">[ON:GET:http://192.168.0.21/relay/0?turn=on] >[OFF:GET:http://192.168.0.21/relay/0?turn=off]" }

As far as I know all Shelly devices return their status information if you send a “/status” GET request, e.g. http://192.168.2.71/status. This will return a JSON buffer and you can extract the value you need from this response.

Currently, I don’t have a working openHAB example but I will work on it the next days.