Shelly vs OpenHAB

Shelly vs OpenHAB

The Shelly brand is known for its products that primarily communicate over WiFi, including smart plugs, relay switches, blinds control relays, and many other devices. One of the advantages for deployment is the ability to both read and control these devices using the universal MQTT protocol. Across existing add-ons for both OpenHAB and Home Assistant, we will demonstrate how to use Shelly devices without installing any additional extensions.

 

Hardware

Shelly devices supporting WiFi and MQTT (in this tutorial, Shelly Plus Plug S, Shelly Smoke Plus)

Pi-Home - if you don't have it, see the section How to Do It

Software

OpenHAB

 

Introduction

Shelly Plus Plug S

It is powered from the mains, always online on WiFi, and can be controlled via MQTT.

Shelly Smoke Plus

It is battery-powered, goes to sleep after two minutes, and wakes up only in case of a fire, quickly connects and sends an MQTT message. During an alarm, it can be turned off via a web interface. It is not possible to control the siren externally! (It's a pity, it would also be useful to have the option of external USB power and an always-online feature)

 

 

We will use the already installed Pi-Home by default with an existing MQTT server. First, connect the Shelly device to power, in this case, Shelly Plus Plug S into a socket. You will see a WiFi network named "ShellyPLusPLug.......". Connect to this network and enter the universal address for Shelly in your browser, which is http://192.168.33.1

After loading the window, set your home WiFi in Settings->WiFi and save. The device should connect to your WiFi. You can check IP from your router and set static address for it. Then, in Settings-> MQTT, you can enable the MQTT protocol. The server address is the address of your Raspberry Pi with OpenHAB and MQTT server.

Enable MQTT on Shelly

 

You can also secure access to the Shelly interface by encrypting it in Settings -> Authentication. Then turn off Bluetooth and AP functions so that Shelly doesn't unnecessarily broadcast an unsecured network. After saving, Shelly should start sending some information via MQTT. To capture this information for diagnostic purposes, you can use any MQTT listener or simply SSH into Raspberry Pi and enter the command:

sudo mosquitto_sub -h localhost -t '#' -v -u openhabian -P yourMQTTpassword

 

Then, you will see all MQTT communication, including something like this:

Shelly MQTT Example

Caution: Shelly can be Generation 1 or 2. Accordingly, the structure of the MQTT message may vary. Below, we will show a real example for both variants. The image shows Shelly Gen2 MQTT message.

 

Shelly Generation 1

In OpenHAB, go to Things, add a new one (plus icon), choose MQTT Binding -> Generic MQTT Thing. In the Bridge, select your MQTT Broker, enter some meaningful ID and description, and create the Thing. Then open the "Code" tabs and paste the following code. Change the header if necessary and especially change the ID (xxxxxxxxx in code) to your real Shelly ID. You can find it on the web interface or in the MQTT topic from the previous point.

Shelly Plus Plug S

UID: mqtt:topic:pihome:shelly
label: Shelly socket
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: off
  payloadAvailable: on
bridgeUID: mqtt:broker:pihome
location: MQTT
channels:
  - id: Relay0
    channelTypeUID: mqtt:switch
    label: Relay0
    description: null
    configuration:
      commandTopic: shellies/shellyplug-s-XXXXXXXXX/relay/0/command
      stateTopic: shellies/shellyplug-s-XXXXXXXXXXX/relay/0
      off: off
      on: on

Save and create a new Channel item Add and Link Item and name it something. You will get a switch-type item that should control the respective socket. Various rules can be applied to this new item in OpenHAB.

 Shelly Item OpenHAB

 

 

Shelly Generation 2

In OpenHAB, go to Things, add a new one (plus icon), choose MQTT Binding -> Generic MQTT Thing. In the Bridge, select your MQTT Broker, enter some meaningful ID and description, and create the Thing. Then open the "Code" tabs and paste the following code. Change the header if necessary and especially change the ID to your real Shelly ID. You can find it on the web interface or in the MQTT topic from the previous point.

Shelly Plus Plug S

UID: mqtt:topic:pihome:shellyplusplugs-xxxxxxxxxx
label: Shelly PLug SW001
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: off
  payloadAvailable: on
bridgeUID: mqtt:broker:pihome
location: MQTT
channels:
  - id: relay0
    channelTypeUID: mqtt:switch
    label: Power Switch
    description: null
    configuration:
      commandTopic: shellyplusplugs-xxxxxxxxxxxx/rpc
      formatBeforePublish: '{"id":0, "src":"MQTT","method":"Switch.Set", "params":{"id":0,"on":%s}}'
      stateTopic: shellyplusplugs-xxxxxxxxxxxxxx/status/switch:0
      transformationPattern: JSONPATH:$.output
      off: "false"
      on: "true"

Shelly Smoke Plus

 
- id: relay1
    channelTypeUID: mqtt:switch
    label: Fire alarm 1
    description: null
    configuration:
      commandTopic: shellyplussmoke-xxxxxxxxxx/rpc
      formatBeforePublish: '{"id":0, "params":{"id":0,"alarm":%s}}'
      stateTopic: shellyplussmoke-xxxxxxxxxxxxxx/status/smoke:0
      transformationPattern: JSONPATH:$.alarm
      off: "false"
      on: "true"

 

Save and create a new Channel item Add and Link Item and name it something. You will get a switch-type item that should control the respective socket. Various rules can be applied to this new item in OpenHAB.

Shelly Item OpenHAB

 Shelly Smoke PLus MQTT

 

Usage Examples:

- switching indoor sockets (Christmas tree, lights, pumps, etc.)

- controlling heating, boiler based on the photovoltaic power (use a relay on DIN or a robust socket at least 16A)

- upgrading traditional switches to smart ones via Shelly relays

- controlling blinds via Shelly relays

- smoke alarm - notification + turn off electricity in object

Rate the article:

Average: 4 (1 vote)

Support Us:

Add comment:

Add comment

Newest articles in blog

Tailscale - remote access without public IP
Tailscale - remote access without public IPRating: 
80%

The Tailscale service solves access between individual devices if you don't have a public IP address. It's free for one user with support for up to 100 devices. We'll show you how to install Tailscale on a Raspberry Pi that you'll have at home and on a client (Android, iPhone) from which you'll want to access the home Raspberry Pi. Our example will be remote access to OpenHAB running on a Raspberry Pi. However, the same setup applies to many other applications - home NAS, PiHole, Home Assistant, Domoticz, NextCloud, and others.

Shelly OpenHAB MQTT
Shelly vs OpenHABRating: 
80%

The Shelly brand is known for its products that primarily communicate over WiFi, including smart plugs, relay switches, blinds control relays, and many other devices. One of the advantages for deployment is the ability to both read and control these devices using the universal MQTT protocol. Across existing add-ons for both OpenHAB and Home Assistant, we will demonstrate how to use Shelly devices without installing any additional extensions.

Victron & OpenHAB
Victron vs Smart HomeRating: 
0%

In this post, we will show you how to retrieve information from a photovoltaic power plant by Victron. We will connect to the Cerbo unit via MQTT. Based on these values, we can control various appliances (heating, boiler, etc.) and prevent the battery from being drained when they don't need to be.

Smart Home GoodWe inverter
Smart Home vs GoodWeRating: 
50%

In the post, we will demonstrate step by step how to communicate directly with the GoodWe inverter in a smart home setup and obtain real-time information (unlike the SEMS portal). This information is essential if we want to react to current parameters in a smart home, such as activating additional cooling or controlling a socket with a various load.

Voice control smart home
Voice control of the houseRating: 
60%

In this article, we will connect the Amazon Echo Dot voice assistant with open source home automation. We won't be using OpenHAB Cloud, so everything runs locally. In this case, a few additional settings are necessary, but the result is worth it!

MikroTik - Winbox, DHCP, Ranges
Basics - Winbox, DHCPRating: 
68.7%

In this series, we will look at the step-by-step setup of MikroTik devices for home users or a small business (up to 25 people). In the first article, we will focus on the initial setup - we will download Winbox and set up DHCP for the primary network and guest network. Similarly, we will also adjust the WiFi settings.

Alarm Smart Home PIR
Alarm from existing PIR sensors in a smart home.Rating: 
0%

In a your smart home, PIR sensors may not only be used to switch lights on and off based on motion, it is possible to utilize these sensors to detect the presence of motion in a particular room. This information can be used to create a relatively reliable uncertified home security system. In this guide, you will find the logic for how this can work in the OpenHAB software in our model smart home.

NFC Tag Example in Smart Home
NFC tags in smart homeRating: 
80%

NFC (Near Field Communication) tags are small plastic or paper stickers that can be used to automate various functions in the smart home. In this article, we will show you examples of use and a guide on how to write an action on an NFC tag using a mobile phone.

WireGuard iOS
WireGuard on iOS devicesRating: 
85%

In this article, you will find a detailed guide on how to connect to WireGuard VPN from iOS.

WireGuard on Android device
WireGuard on Android devicesRating: 
0%

In this article, you will find a detailed guide on how to connect to WireGuard VPN from Android.