Thing: Shelly via MQTT

Hi,

I have a problem getting my shelly1 to work.
I created a thing via PaperUI:
59

I created an items file without he following content:
Switch ShellyBuero "Büro-Licht" {mqtt=">[ShellyBuero:shellies/shelly1-5548C3/relay/0/command:command:*:MAP(shelly.map)],<[ShellyBuero:shellies/shelly1-5548C3/relay/0:state:MAP(shelly.map)]"}

I also tried:
Switch ShellyBuero "Büro-Licht" {mqtt=">[mqtt:topic:ShellyBuero:shellies/shelly1-5548C3/relay/0/command:command:*:MAP(shelly.map)],<[mqtt:topic:ShellyBuero:shellies/shelly1-5548C3/relay/0:state:MAP(shelly.map)]"}

without any luck.

Any suggestions?

TIA
.d

This is a configuration for MQTT binding version 1.x

MQTT binding version 2.x uses Things and channels, version 1.x does not.

Taking into account that it’s what you get by default and that you’ve managed to make a Thing, you probably have 2.x installed.

Abandon whatever old guide is telling you about {mqtt= and look at more recent ones, you’ll be wanting to configure and link channels for your thing and Item.

Thx for the reply.

Do you have an working example for version 2.x?

There’s a few
https://community.openhab.org/search?context=topic&context_id=80071&q=Shelly%20mqtt%20channels&skip_context=true

Thx, found some example, but still struggling.

mqtt.things:
Bridge mqtt:systemBroker:embedded-mqtt-broker "MQTT-Broker" [ host="127.0.0.1", port=1883, secure=false, clientID="openHAB2", qos="1"] { Thing topic ShellyBuero "ShellyBuero" { Channels: Type switch : power "Licht" [ stateTopic="shellies/shelly1-5548C3/relay/0", on="on", off="off", commandTopic="shellies/shelly1-5548C3/relay/0/command", on="on", off="off" ] } }

shelly.items:
Switch ShellyBuero "ShellyBueroLicht" <switch> [ "Licht" ] { channel="mqtt:topic:ShellyBuero:Licht:power" }

The button is on my map, but it is still not switching.

Any suggestion?

TIA
.d

Have you set up a broker, is openHAB connecting to that OK?
You can use a tool like mqtt.fx to observe messages passing through your broker.

I can see Messages with MQTT.fx.

That’s good. So, if you operate the OH switch and it sends a message, is it the topic and payload that the shelley is looking for? If you operate the shelley locally, does it produce a topic and payload that you’ve configured OH to look for? May we know what these messages are?

1 Like

You’ve created the MQTT Broker Thing. Does it show as online in PaperUI?

If yes, create a Generic MQTT Thing. Then create a Switch Channel on the that MQTT Thing.

  • state topic: shellies/shelly1-<uid>/relay/0 where <uid> is the unique ID of the Shelly1
  • command topic: shellies/shelly1-<uid>/relay/0/command
  • Custom ON/OPEN value: on
  • Custom OFF/CLOSED value: off

Link that Channel to an Item.

Is is showing UNINITIALIZED - HANDLER_CONFIGURATION_PENDING.
Something with an unique id missing.

how do i set the id in the file?

Bridge mqtt:systemBroker:embedded-mqtt-broker "MQTT-Broker" [ host="127.0.0.1", port=1883, secure=false, clientID="openHAB2", qos="1"]
{
   Thing topic ShellyBuero2 "ShellyBuero" {
   Channels:
     Type switch : power "Licht" [ stateTopic="shellies/shelly1-5548C3/relay/0", on="on", off="off", commandTopic="shellies/shelly1-5548C3/relay/0/command", on="on", off="off" ]
 }
}

Now its online.

I separated the things file into two files.

mqtt.things:
Bridge mqtt:broker:mqttbroker "MQTT-Broker" [ host="127.0.0.1", port=1883, secure="AUTO" ]

shelly.things:
Thing topic mqtt:broker:mqttbroker:shellyBuero "ShellyBuero" { Channels: Type switch : power "Licht" [ stateTopic="shellies/shelly1-5548C3/relay/0", on="on", off="off", commandTopic="shellies/shelly1-5548C3/relay/0/command", on="on", off="off" ] }

But it is still not switching.

I’m able to see the messages in MQTT.fx when i switch manually, but not when switching with openhab.

Reminder; they might be interesting, but we can’t see them.

You’re right.
They were in my head and you are outside :wink:

Okay, you can see the Shelly MQTT update and it seems to match your Thing -

so you should be getting updates to your Item when you switch at the Shelly. Is that working? Anything in events.log?

There is a problem in your thing where you have
on="on", off="off",
twice. I don’t think that will stop it working but you should take one set out.

This comes up when open hab tries to display the switch:
2019-08-17 12:06:20.200 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'ShellyBuero' for widget org.eclipse.smarthome.model.sitemap.Switch 2019-08-17 12:06:20.209 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'ShellyBuero' for widget org.eclipse.smarthome.model.sitemap.Switch 2019-08-17 12:06:20.212 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'ShellyBuero' for widget org.eclipse.smarthome.model.sitemap.Switch 2019-08-17 12:06:20.217 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'ShellyBuero' for widget org.eclipse.smarthome.model.sitemap.Switch

This comes up when switching:

2019-08-17 12:06:23.800 [INFO ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/ShellyBuero' for the unknown item 'ShellyBuero'. 2019-08-17 12:06:26.516 [INFO ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/ShellyBuero' for the unknown item 'ShellyBuero'.

I took out the double on/off.

You don’t have an Item named ShellyBuero
Check spelling, uppercase etc. against your xxx.items file
Look in your openhab.log at boot time for entry
- Loading model 'xxx.items'

OK, 1 step further.

2019-08-17 13:49:04.870 [ome.event.ItemCommandEvent] - Item 'shellybuero' received command ON 2019-08-17 13:49:04.877 [nt.ItemStatePredictedEvent] - shellybuero predicted to become NULL 2019-08-17 13:49:05.945 [ome.event.ItemCommandEvent] - Item 'shellybuero' received command OFF 2019-08-17 13:49:05.956 [nt.ItemStatePredictedEvent] - shellybuero predicted to become NULL 2019-08-17 13:49:28.347 [ome.event.ItemCommandEvent] - Item 'shellybuero' received command ON 2019-08-17 13:49:28.355 [nt.ItemStatePredictedEvent] - shellybuero predicted to become NULL 2019-08-17 13:49:29.366 [ome.event.ItemCommandEvent] - Item 'shellybuero' received command OFF 2019-08-17 13:49:29.379 [nt.ItemStatePredictedEvent] - shellybuero predicted to become NULL 2019-08-17 13:49:30.019 [ome.event.ItemCommandEvent] - Item 'shellybuero' received command ON 2019-08-17 13:49:30.026 [nt.ItemStatePredictedEvent] - shellybuero predicted to become NULL 2019-08-17 13:49:30.644 [ome.event.ItemCommandEvent] - Item 'shellybuero' received command OFF 2019-08-17 13:49:30.652 [nt.ItemStatePredictedEvent] - shellybuero predicted to become NULL

But i’m not reading any messages in MQTT.fx and the shelly is not switching.

after saving the things file again i got:

2019-08-17 14:05:39.651 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'shelly.things' has errors, therefore ignoring it: [1,17]: missing EOF at ':'

shelly.things:
Thing topic mqtt:broker:mqttbroker:shellybuero "ShellyBuero" { Channels: Type switch : power "Licht" [ stateTopic="shellies/shelly1-5548C3/relay/0", on="on", off="off", commandTopic="shellies/shelly1-5548C3/relay/0/command"] }

1,17 is the first :

Is your other things file with the broker bridge loading ok?

I’ve put both into one file.

mqtt.things:
Bridge mqtt:broker:embedded-mqtt-broker “MQTT Bridge”
[
host=“127.0.0.1”,
port=1883,
secure=“AUTO”
]

{
Thing topic shellybuero "BüroLicht " {
Channels:
Type switch : ShellyBueroLicht “Büro Licht” [stateTopic=“shellies/shelly1-5548C3/relay/0”, commandTopic=“shellies/shelly1-5548C3/relay/0/command”, on=“on”, off=“off”]
}
}

2019-08-17 14:38:24.101 [me.event.ThingUpdatedEvent] - Thing ‘mqtt:topic:embedded-mqtt-broker:shellybuero’ has been updated.