Shelly 2 PM and mqtt integration

Hello community, some months ago I did a mqtt config to control all my lights with the wall switches and shelly. I have several Shelly 1 v3 and Shelly 2.5. I had to change one of them (Shelly 2.5 model) with a Shelly 2 PM. I did the same config as per other Shelly 2.5 (GUI is quite different, but all data should be there):

Then in HA I left the original config in mqtt section:

    - name: "Cameretta Interruttore"
      state_topic: "shellies/shelly25-cameretta/relay/1"
      command_topic: "shellies/shelly25-cameretta/relay/1/command"
      qos: 0
      payload_on: "on"
      payload_off: "off"
      retain: false
    - name: "Ingresso Cameretta Interruttore"
      state_topic: "shellies/shelly25-cameretta/relay/0"
      command_topic: "shellies/shelly25-cameretta/relay/0/command"
      qos: 0
      payload_on: "on"
      payload_off: "off"
      retain: false

So every time the wall switch will be used, HA will receive the input and use an automation to switch on/off the light.

Problem is that currently I’m not able to recognize the Shelly 2 PM in HA, so no automation is triggered.

From the Shelly integration I can see what reported below. Obviously I double/triple checked the username/password. Anyway all other Shelly works perfect.

2023-09-26 08:08:32: New connection from 192.168.2.59:51684 on port 1883.
2023-09-26 08:08:32: Client shelly25-cameretta already connected, closing old connection.
2023-09-26 08:08:32: New client connected from 192.168.2.59:51684 as shelly25-cameretta (p2, c1, k60, u'mqtt_user').
2023-09-26 08:10:03: New connection from 172.30.32.1:57258 on port 1883.
error: received null username or password for unpwd check
2023-09-26 08:10:03: Client auto-F345C7B7-94C0-AAE6-765F-CB2790840739 disconnected, not authorised.

Could someone help me to integrate via mqtt the new shelly 2.5 PM? Cause now I cannot switch on 2 lights in my house :slight_smile:
As I wrote, many months are passed (maybe years), is there any other method to integrate Shelly? Currently I’m using the native integration.

Thank you
Lucas

If you are using the core Shelly installation why are you setting up mqtt?

Navigate to the local IP address of your Shelly device, Settings >> Connectivity >> Outbound WebSocket and check the box Enable Outbound WebSocket, under server enter the following address:

ws:// + Home_Assistant_local_ip_address:Port + /api/shelly/ws (for example: ws://192.168.1.100:8123/api/shelly/ws), click Apply to save the settings.

1 Like

Thank you very much, I enabled the Outbound WebSocket and now it works. Sorry, I missed it on documentation. In this way I also disabled the mqtt on new Shelly 2 PM and it still works. I had enabled the mqtt about 2 years ago cause probably HA didn’t support such integration.

Now I have another issue. I tried to disable mqtt on Shelly 1 v3, and add them to the core Shelly integration. I re-created the automation and they work fine from HA, i.e. pressing the switch, the light will be switched on/off. Unfortunately when I use the wall switch there are a long delay so light will be switched off after many seconds. I got an alert on HA that say that cannot communicate with the Shelly and CoIoT should be enabled. I check it and CoIoT is enabled.

There is no Outbound WebSocket on Shelly 1 and for now I rollback to mqtt, but I would like to disable mqtt at all on all my shelly. I don’t understand why I got this issue!

Did you also specify the unicast address as per the instructions for GEN 1 devices?

1 Like

YES, and the best you don’t even need to waste time with mqtt anymore :dancing_men:

Ether go with shelly integration and use web socket or install esphome on your shellys and go with the native api :rocket:

Sure I did it and reboot the shelly, now I restarted also HA and it works! Thank you!

This is what I would like to do, remove the mqtt on HA and shelly, and enable also cloud on shelly.
I did it right now with 1 Shelly and I notice then a very little delay when I press the wall switch compared with mqtt, anyway it’s acceptable.

Switching your loads over the internet utilizing other peoples computers? Not what I suggested. :stop_sign:

I advise for local control with full ownership running your own *ware on the device :point_right: esphome.io

Thanks I’ll check it

It’s really not necessary unless you want to do some more advanced automation on the device.

Shelly are one of the few companies that respect the user’s right to have local control and that is exactly what the core integration does.

I see, however I noticed a little delay in command execution when I use the wall switch (light toggle) compared with mqtt. Nothing dramatic and I can live with it cause it’s a very little delay. Maybe I can try to disable cloud on shelly since I don’t need it and I don’t see any reason to leave it enabled.
However, the most important thing is that now everything work as expected.

If your command to toggle is send hundreds or thousands of kilometers through the world wide web :cloud: that is expected. :man_shrugging:

Some users btw. claim that the esphome native api performs faster than mqtt :point_down:

It’s not if they are using the core integration.

Screenshot 2023-09-28 at 22-39-55 Shelly

I’m in the same boat, and stuck. Maybe someone can help me forward. I have a lot of “Shelly 2.5”-devices that work over MQTT.

(These ones to be exact)

Now I needed a couple more to finish the house but they don’t make them anymore it seems. So I bought the upgrade: Shelly 2PM Gen3.

I figured they would work the same… but the GUI is indeed very different. I tried to set the same settings as my devices in use but when I ‘listen’ for it, it never shows.

The first suggestion is to use “Outbound websocket”, what does that mean exactly? No longer MQTT? And would that work on my older shellies? I can’t find the settings for that there.

I kind of prefer MQTT, it works blazingfast on my other devices.

You can find Outbound websocket under 2PM settings, and then configure it like this (change with your own HA IP address):

And yes, you can completely remove the MQTT integration and use the native Shelly integration instead. I did it and re-configured all my shellies, and now it’s much simpler

1 Like

So, I tried the ‘normal way’ and just added them when Home Assistant detected them in my network. It works great, fast and snappy! So no reason to use MQTT anymore I guess.

Did you reconfigure your old shellies that way too then? Because the
‘outbound websocket settings’ are not there? When I tried to use them over the standard integration it was slow to very slow for the Shelly2.5. Did something change then?

Yes, I replaced MQTT with native integration for all my 25 Shellies (Shelly 1 v3, 1PM, 2PM, Shelly EM, etc…). Recently I also replaced all my Shellies 1 v3 (7) with Shellies 1 mini where the unicast address is not needed anymore. So, at the end, all my Shellies don’t need anymore MQTT and other additional config. Native integration is all I need to integrate them (except for 2PM and outbound websocket setting).
One year ago, after migration, I had an annoying little delay in command execution when I use the wall switch (about 1 second). Now, this delay is gone, most probably thanks to native integration updated in newest HA release.

Regarding the outbound websocket setting, this is needed, in my case, only on 2PM as reported in official documentation, this is the interesting part:

Generation 2 and 3 devices use the RPC protocol to communicate with the integration. Battery-operated devices (even if USB connected) may need manual outbound WebSocket configuration if Home Assistant cannot correctly determine your instance’s internal URL or the outbound WebSocket was previously configured for a different Home Assistant instance. In this case, navigate to the local IP address of your Shelly device, Settings >> Connectivity >> Outbound WebSocket and check the box Enable Outbound WebSocket

Dude! This is golden info! Thanks a lot! I’ll buy you a cup of coffee when we ever meet :wink:

However this is giving me mixed feelings. I was so proud of myself to get MQTT going on those devices. :joy:

Trust me, native integration is much better than MQTT, even because automations will be simplier