Shelly1 and mqtt 2.4.0 Binding

Just a quick reference: Using the original firmware, you can control your shelly 1 switch with the new mqtt 2.4.0 binding as follows:

Create a mqtt broker, providing your broker’s data, and create a MQTT Thing. In the MQTT Thing configuration, create a new channel with the followin Data:

  • Channel type: On/Off switch
  • Channel ID, Label: As you like
  • Channel configuration:
    • MQTT state topic: shellies/shelly1-123ABC/relay/0
    • MQTT command topic: shellies/shelly1-123ABC/relay/0/command
  • Show More:
    • On/Open value: on
    • Off/Closed value: off

(replacing shelly1-123ABC by your shelly’s ID)


You can then use the channel to link to a Switch item to control your shelly.

8 Likes

Sorry, this string in the THING file cause Bridge not start (not visible in Paper UI)
[ stateTopic=“shellies/shelly1-4FFC66/online/0”, commandTopic=“shellies/shelly1-4FFC66/online/0/command”, on=“on” off=“off”]

Instead this is fully operational and Paper UI show both Bridge and thing channel configuration
[ stateTopic=“shellies/shelly1-4FFC66/relay/0”, commandTopic=“shellies/shelly1-4FFC66/relay/0/command”]

So it seems I’m wrong with the aliases configuration at the and (on and off)…
Preceeding lines in thing file for Bridge configuration is
Bridge mqtt:broker:brignoudBroker [ host=“192.168.xx.xx”, secure=false, username=“openhabian”, password=“xxxx” ]
{
Thing topic shellies {
Channels:
Type switch : shelly1-4FFC66 “Kitchen Lamp”

There is no /online/ in my example…

Hi,

Below is the things config that works for me, I only use cli no paper ui, if this helps.

Bridge  mqtt:broker:mosquitto "Mosquitto" [ host="0.0.0.0", secure=false, username="openhab", password="Xxxxxxx", clientID="openHAB2"  ]
{
        Thing topic StudyShelly1 "Shelly1" @ "Study" {
                Channels:
                Type switch : power "Power" [ stateTopic="shellies/shelly1-056DD7/relay/0", on="on", off="off", commandTopic="shellies/shelly1-056DD7/relay/0/command", on="on", off="off" ] 
        }
}

And my single item

Switch MQTT_Test2 "Study Shelly1" <switch>  (SF_Study) [ "Lighting" ] { channel="mqtt:topic:mosquitto:StudyShelly1:power" }

Done from my phone so hopefully copied ok.

K

2 Likes

Replicated your config step by step except the shelly ID and some minor
I got nothing but the broker and the thing available and still didn.’ see the value passing throught MQTTfx
I defined a Switch in sitemap that seems to do nothing alterning the state

In my Shelly panel configuration I got this
Does it misleading with the OpenHab configuration files we shared ?
image

I regulary see value in transit when I operate from the phisical button or virtual Shelly app so MQTT is fully working I assume

Hi,

Just checked mine from the phone and it shows the same message in the “Will Topic”, but that doesn’t change regardless of if I turn the Shelly off via the Shelly web app or OH switch.

Have you tried enabling full logging on mosquito and watch the messages for state changes?

Do you use habmin and if so does the broker and Shelly switch show as available under configuration/ things?

K

Just checked the last (?) thing, I just wanted to try adding the port to the Bridge configuration
It’s works now as expected!

By the way, port number is the standard (1883) but it seems configuration need it anyway
Don’t know if is normal behaviour or if it has dignity to pay attention to it by the OH mantainers
Thank you all for supporting, you made me understand a lot with MQTT

can you explain me what this syntax means the “@”?

Hi,
Like a lot of people here I’ve been using other people’s examples to get my own working with the new mqtt 2.4, the link below is where I started with some of this.

But if I made an educated guess the first “Shelly 1” is just a nice name for the topic, so in Habmin is see Shelly 1 under things instead of StudyShelly1, @ “Study” is just a nice location name but not sure if it has any other use.
The docs don’t really mention the use from what I’ve seen.

K

1 Like

The word after the “@” ist the “Location” in the “Control” Tab in the Paper UI. I’m not aware of any other place that this information is used.

Did anybody create a channel for the shelly1 input?
Topic: shellies/shelly1-XXXXXXXX/input/0

How should this look like. It reports 0 and 1 depending on the state.

works out of the box without mapping 0 or 1 to OFF or ON with these settings:

things:
Type string : extSwitch "External Switch" [ stateTopic="shellies/shelly1-55521D/input/0" ]

items:
String Shelly1_01_extSwitch "Shelly1-01 Ext Switch" { channel="mqtt:topic:mosquitto:Shelly1-01:extSwitch" }

any idea how I can use the JSON transform to display the out of the box firmware of a specific shelly switch? For example this is what I see via MQTT:

shellies/announce {“id”:“shelly1-55521D”,“mac”:“B6E62D55521D”,“ip”:“192.168.2.32”,“new_fw”:false, “fw_ver”:“20190122-162034/v1.4.5@5cbc6229”}
shellies/announce {“id”:“shellyswitch-5A4CE4”,“mac”:“B6E62D5A4CE4”,“ip”:“192.168.2.31”,“new_fw”:false, “fw_ver”:“20190122-162045/v1.4.5@5cbc6229”}

as you can see, they both use the same topic. thus I need to check fw_ver value only if id = %desired device%

Or any idea how to use this regex?

This helped me a lot to get Shelly 2.5 working.
Thanks!

sorry man @LungBen , could you post your config? Things , item and sitemap (eventually rules or JS) on shelly 2.5 but nothing…
i have read many posts but i’m at the same start point…

For me it works as follow:
Things:

Thing mqtt:topic:OG1_ba_li_schalter "OG1_ba_li_schalter" (mqtt:broker:mosquitto) {
        Channels:
        Type string : online    "Online"        [ stateTopic="shellies/shellyswitch25-xxx13/online" ]
        Type switch : power1    "Power1"        [ stateTopic="shellies/shellyswitch25-xxx13/relay/0", on="on", off="off", commandTopic="shellies/shellyswitch25-xxx13/relay/0/command", on="on", off="off"]
        Type switch : power2    "Power2"        [ stateTopic="shellies/shellyswitch25-xxx13/relay/1", on="on", off="off", commandTopic="shellies/shellyswitch25-xxx13/relay/1/command", on="on", off="off"]
        }

Items:

Switch OG1_ba_li_decke "Licht Decke" <light> (gOG1_ba,gOG1_Licht) ["Lighting"]  { channel="mqtt:topic:OG1_ba_li_schalter:power1" }
Switch OG1_ba_li_spiegel "Licht Spiegel" <light> (gOG1_ba,gOG1_Licht) ["Lighting"]  { channel="mqtt:topic:OG1_ba_li_schalter:power2" }

Quite easy and simple.

Hi,

attached are screenshots of my openHAB configuration (in PaperUI - requires OpenHAB 2.4).
Unfortunately I cannot provide screenshots of my Shelley config now, my garden water equipment is already switched off for winter. Hope that the information is nevertheless helpful!