Integrating Shelly 2.5 using MQTT

Hello ladies and gents,

I have recently bought a shelly 2.5 and would like to control it using mqtt. I set up the broker and added the device to the configuration.yaml using the cover template. Heres the snippet of the config.yaml:

cover:
- platform: mqtt
  name: "lus_grosses_rollo"
  command_topic: "shellies/shellyswitch-E61A17/roller/0/command"
  position_topic: "shellies/shellyswitch-E61A17/roller/0/pos"
  set_position_topic: "shellies/shellyswitch-E61A17/roller/0/command/pos"
  availability_topic: "shellies/shellyswitch-E61A17/online"
  payload_available: "true"
  payload_not_available: "false"
  qos: 1
  retain: false
  payload_open: "open"
  payload_close: "close"
  payload_stop: "stop"
  position_open: 100
  position_closed: 0
  optimistic: false

Problem: The shelly shows up as a device, but there is no reaction to the buttons whatsoever.
grafik.
The device is shown as “not available”

Also, the logs for that device are (obviously) empty.

Can anybody tell what I did wrong? Any input would be much appreciated.

Thanks,
Martin

I have a Shelly 2.5 as well. However, the MQTT topics of my switch have a different structure:

shellies/shellyswitch25-E5E50F/relay/0/command

I’m referring to the extra 25, not to the relay mode vs. roller mode.

2 Likes

Thx Holger, I tried adding the extra “25” to the structure - however to no avail :frowning:

Assuming the Shelly is connected to your Wifi network, you could use an MQTT client to verify if the device is publishing.

This is how it looks like for my Shelly 2.5:

pi@raspberrypi:~ $ mosquitto_sub -h localhost -t '#' -v | grep shellyswitch25
shellies/shellyswitch25-E5E50F/relay/0 off
shellies/shellyswitch25-E5E50F/relay/0/power 0.00
shellies/shellyswitch25-E5E50F/relay/0/energy 1
shellies/shellyswitch25-E5E50F/relay/1 off
shellies/shellyswitch25-E5E50F/relay/1/power 0.00
shellies/shellyswitch25-E5E50F/relay/1/energy 0
shellies/shellyswitch25-E5E50F/relay/power 0.00
shellies/shellyswitch25-E5E50F/relay/energy 0
shellies/shellyswitch25-E5E50F/input/0 0
shellies/shellyswitch25-E5E50F/input/1 0
shellies/shellyswitch25-E5E50F/temperature 60.12
shellies/shellyswitch25-E5E50F/overtemperature 0

Thank you again, Holger. Yes, the shelly is hooked up with the wifi - it worked with the shelly cloud/app, but I wanted to make it work via mqtt.

When I ssh into my hassio and run ´mosquitto_sub -v -h localhost -t ‘#’`

it returns Error “Address not available” -> So it appears as though the broker did simply not exist?!

If I run ´ps -A | grep mosquitto ` I get

core-ssh:~# ps -A | grep mosquitto
   81 root      0:00 grep mosquitto

which also confuses me since it should shot the mosquitto broker running, but not a process called grep mosquitto?!

When I install a mosquitto client on my laptop, making it a client, and do the same, I get

martin@laptop:~$ mosquitto_sub -v -h 192.168.178.43 -t '#'
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.

On the webinterface of my hassio it says:


Interestingly, 192.168.178.44 is the Shelly2.5’s IP address.

I use the mosquitto MQTT broker as installed on OS level, I do not use the docker add-on. Hence “localhost”.

Looks like you configured your MQTT broker to require credentials. If that is the case you need to configure those credentials in the web interface of the shelly switch.

Nope, configured mosquitto without login credentials:

This is what the settings of the shelly switch look like

grafik
grafik
(No login credentials)

I’ve had a look at the docs for this add-in:

To allow anonymous connections, you have to set “anonymous”: true, if I’m not mistaken.

Do you have other devices that can successfully communicate?

Thanks once again Holger, sadly that did not change it.

In case you (anybody) might be wondering, here are broker log and (the relevant part of the) shelly config:

  1. It seems as though there is an initial communication between client and broker which then fails
  2. I seem to be a bit confused: When I set up the Mosquitto broker, the broker asked me to set up a “broker user” which is called “mqtt_user” in my case. Is this the user I need to set up in my mosquitto configuration?
[19:32:24] INFO: Setup mosquitto configuration
[19:32:24] WARNING: SSL not enabled - No valid certs found!
[19:32:24] INFO: No local user available
[19:32:25] INFO: Initialize Hass.io Add-on services
[19:32:25] INFO: Initialize Home Assistant discovery
[19:32:25] INFO: Start Mosquitto daemon
1566322345: mosquitto version 1.6.3 starting
1566322345: Config loaded from /etc/mosquitto.conf.
1566322345: Loading plugin: /usr/share/mosquitto/auth-plug.so
1566322345: |-- *** auth-plug: startup
1566322345:  ├── Username/password checking enabled.
1566322345:  ├── TLS-PSK checking enabled.
1566322345:  └── Extended authentication not enabled.
1566322345: Opening ipv4 listen socket on port 1883.
1566322345: Opening ipv6 listen socket on port 1883.
1566322345: Opening websockets listen socket on port 1884.
1566322345: Warning: Mosquitto should not be run as root/administrator.
1566322345: New connection from 192.168.178.29 on port 1883.
1566322345: Socket error on client <unknown>, disconnecting.
1566322346: New connection from 192.168.178.43 on port 1883.
1566322346: New connection from 192.168.178.29 on port 1883.
1566322346: Socket error on client <unknown>, disconnecting.
1566322347: New connection from 172.30.32.1 on port 1883.
1566322347: Socket error on client <unknown>, disconnecting.
1566322347: New connection from 192.168.178.43 on port 1883.
[INFO] found mqtt_user on Home Assistant
1566322349: New client connected from 192.168.178.43 as auto-613E9445-CC26-7BF0-C2AB-4BD7AD33FE16 (p2, c1, k60, u'mqtt_user').
1566322349: New connection from 192.168.178.29 on port 1883.
1566322349: New connection from 172.30.32.1 on port 1883.
1566322349: Socket error on client <unknown>, disconnecting.
1566322349: Socket error on client <unknown>, disconnecting.
[INFO] found homeassistant on local database
1566322349: New client connected from 172.30.32.1 as auto-FCCAC898-9218-0F6E-B2B2-03222DB6BD58 (p2, c1, k60, u'homeassistant').
1566322227: New connection from 192.168.178.44 on port 1883.
1566322227: Socket error on client <unknown>, disconnecting.
1566322227: New connection from 172.30.32.1 on port 1883.
1566322227: New connection from 192.168.178.29 on port 1883.
1566322227: Socket error on client <unknown>, disconnecting.
1566322227: New connection from 192.168.178.43 on port 1883.
1566322228: Socket error on client <unknown>, disconnecting.
1566322228: New connection from 172.30.32.1 on port 1883.
[INFO] found homeassistant on local database
1566322229: New client connected from 172.30.32.1 as auto-1B175EEF-AB18-9EE7-2082-85CCD236190A (p2, c1, k60, u'homeassistant').
1566322229: New connection from 192.168.178.29 on port 1883.
1566322229: New connection from 192.168.178.43 on port 1883.
1566322229: Socket error on client <unknown>, disconnecting.
1566322229: Socket error on client <unknown>, disconnecting.
[INFO] found mqtt_user on Home Assistant
1566322230: New client connected from 192.168.178.43 as auto-A402241D-6069-FE3A-62D9-0AB861949057 (p2, c1, k60, u'mqtt_user').
1566322230: New connection from 192.168.178.29 on port 1883.
1566322230: Socket error on client <unknown>, disconnecting.
1566322231: New connection from 192.168.178.29 on port 1883.
1566322231: Socket error on client <unknown>, disconnecting.
1566322232: New connection from 192.168.178.29 on port 1883.
1566322232: Socket error on client <unknown>, disconnecting.
1566322234: New connection from 192.168.178.29 on port 1883.


There is a discussion with > 200 entries here where people report problems with the mosquitto-addon.

I have installed mosquitto the traditional way on a pi that also runs my fhem, deconz and homebridge, no issues at all. I would recommend this over the addon.