# Shelly1 and mqtt 2.4.0 Binding

**URL:** <https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502>\
**Category:** Solutions\
**Tags:** mqtt, mqtt-binding, shelly\
**Created:** [January 9, 2019, 9:45pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502 "2019-01-09T21:45:51Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pekka](https://community.openhab.org/user_avatar/community.openhab.org/pekka/32/44420_2.png) [@Pekka](https://community.openhab.org/u/Pekka)\
**Post date:** [January 9, 2019, 9:45pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/1 "2019-01-09T21:45:51Z")

</div>

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)

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/e/9/e96ad656bde1349e315284f714cbf79cd9035d11.png)  
 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/8/e/8eb0e96622645b673ffde2e82d96fb634e66ed9d.png)

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

---

<div class="post-metadata">

**Author:** ![Brignoud](https://community.openhab.org/user_avatar/community.openhab.org/brignoud/32/34268_2.png) [@Brignoud](https://community.openhab.org/u/Brignoud)\
**Post date:** [January 12, 2019, 6:04pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/2 "2019-01-12T18:04:49Z")

</div>

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”]

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/3/6/3616ffe183f8744df568981b8f63f063401d9dd1.png)

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”  
..

---

<div class="post-metadata">

**Author:** ![Pekka](https://community.openhab.org/user_avatar/community.openhab.org/pekka/32/44420_2.png) [@Pekka](https://community.openhab.org/u/Pekka)\
**Post date:** [January 12, 2019, 6:36pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/3 "2019-01-12T18:36:54Z")

</div>

There is no /online/ in my example…

---

<div class="post-metadata">

**Author:** ![KevinI](https://community.openhab.org/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@KevinI](https://community.openhab.org/u/KevinI)\
**Post date:** [January 12, 2019, 7:13pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/4 "2019-01-12T19:13:36Z")

</div>

Hi,

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

```csv
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

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

```

Done from my phone so hopefully copied ok.

K

---

<div class="post-metadata">

**Author:** ![Brignoud](https://community.openhab.org/user_avatar/community.openhab.org/brignoud/32/34268_2.png) [@Brignoud](https://community.openhab.org/u/Brignoud)\
**Post date:** [January 12, 2019, 10:23pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/5 "2019-01-12T22:23:03Z")

</div>

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](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/c/3/c346328e8d7731d2faf60b4b68adb66dd8c72665.png)

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

---

<div class="post-metadata">

**Author:** ![KevinI](https://community.openhab.org/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@KevinI](https://community.openhab.org/u/KevinI)\
**Post date:** [January 12, 2019, 10:46pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/6 "2019-01-12T22:46:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brignoud](https://community.openhab.org/user_avatar/community.openhab.org/brignoud/32/34268_2.png) [@Brignoud](https://community.openhab.org/u/Brignoud)\
**Post date:** [January 13, 2019, 11:28am UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/7 "2019-01-13T11:28:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brignoud](https://community.openhab.org/user_avatar/community.openhab.org/brignoud/32/34268_2.png) [@Brignoud](https://community.openhab.org/u/Brignoud)\
**Post date:** [January 13, 2019, 9:34pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/8 "2019-01-13T21:34:37Z")

</div>

> [@KevinI](#):
>
> “Shelly1” @ “Study”

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

---

<div class="post-metadata">

**Author:** ![KevinI](https://community.openhab.org/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@KevinI](https://community.openhab.org/u/KevinI)\
**Post date:** [January 13, 2019, 10:49pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/9 "2019-01-13T22:49:51Z")

</div>

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.

> [@Sonoff Tasmota with MQTT Binding 2.4 (using config files)](https://community.openhab.org/t/sonoff-tasmota-with-mqtt-binding-2-4-using-config-files/61494):
>
> [The new MQTT Binding](https://www.openhab.org/addons/bindings/mqtt/) supports auto-discovery via the [Homie 3.x convention](https://homieiot.github.io/) and via the [HomeAssistant MQTT specification](https://www.home-assistant.io/docs/mqtt/discovery/). Of the 2 options, the Homie convention is [better for use with OpenHAB as it allows for full device capabilities to be auto-discovered](https://www.openhab.org/blog/2018-12-16-mqtt-arrives-in-the-modern-openhab-2-x-architecture.html#mqtt-thing-auto-discovery). [Theo Arends’ wonderful Tasmota firmware](https://github.com/arendst/Sonoff-Tasmota) - latest version is 6.4.1.1 - does not currently support the Homie MQTT convention. Hopefully that will change in the future. [Tasmota does support HomeAssistant auto-discovery](https://github.com/arendst/Sonoff-Tasmota/wiki/Home-Assistant), if that meets your requirem…

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

---

<div class="post-metadata">

**Author:** ![hakan](https://community.openhab.org/user_avatar/community.openhab.org/hakan/32/70815_2.png) [@hakan](https://community.openhab.org/u/hakan)\
**Post date:** [January 13, 2019, 11:38pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/10 "2019-01-13T23:38:48Z")

</div>

> [@Brignoud](#):
>
> can you explain me what this syntax means the “@”?

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.

---

<div class="post-metadata">

**Author:** ![olialb](https://community.openhab.org/user_avatar/community.openhab.org/olialb/32/114437_2.png) [@olialb](https://community.openhab.org/u/olialb)\
**Post date:** [January 16, 2019, 7:39pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/11 "2019-01-16T19:39:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![StefanH](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@StefanH](https://community.openhab.org/u/StefanH)\
**Post date:** [February 1, 2019, 6:07pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/12 "2019-02-01T18:07:36Z")

</div>

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" }`

---

<div class="post-metadata">

**Author:** ![StefanH](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@StefanH](https://community.openhab.org/u/StefanH)\
**Post date:** [February 1, 2019, 6:08pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/13 "2019-02-01T18:08:57Z")

</div>

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?

> **[regex101: build, test, and debug regex](https://regex101.com/r/c1TXdg/2)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.

---

<div class="post-metadata">

**Author:** ![LungBen](https://community.openhab.org/user_avatar/community.openhab.org/lungben/32/39804_2.png) [@LungBen](https://community.openhab.org/u/LungBen)\
**Post date:** [July 11, 2019, 11:21am UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/14 "2019-07-11T11:21:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![julesx81](https://community.openhab.org/user_avatar/community.openhab.org/julesx81/32/73442_2.png) [@julesx81](https://community.openhab.org/u/julesx81)\
**Post date:** [November 8, 2019, 8:10pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/15 "2019-11-08T20:10:01Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![dascrip](https://community.openhab.org/user_avatar/community.openhab.org/dascrip/32/31193_2.png) [@dascrip](https://community.openhab.org/u/dascrip)\
**Post date:** [November 11, 2019, 7:16pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/16 "2019-11-11T19:16:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LungBen](https://community.openhab.org/user_avatar/community.openhab.org/lungben/32/39804_2.png) [@LungBen](https://community.openhab.org/u/LungBen)\
**Post date:** [November 17, 2019, 7:26pm UTC](https://community.openhab.org/t/shelly1-and-mqtt-2-4-0-binding/63502/17 "2019-11-17T19:26:33Z")

</div>

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!

 ![Screenshot_20191117-201956_Chrome](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/9/a/9a78e7ac8f80fac3f36dec5a4636b12f91943354.jpeg) ![Screenshot_20191117-201933_Chrome](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/b/7/b70e365aec8e90d3fc1e2f77daf2b97fff0f7608.jpeg) ![Screenshot_20191117-201905_Chrome](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/4/e/4ef326c0033a79202bb7033c85da7433a7dc3425.jpeg) ![Screenshot_20191117-201847_Chrome](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/6/b/6b9dc903d6d8f141fe14a12b4a0f1427a22a86e1.jpeg)  
 ![Screenshot_20191117-201842_Chrome](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/4/f/4fc9ed040c07a6ba507e752212eaf98ff9ea84cc.jpeg)
