# Shelly integration & MQTT (via MacBook)

**URL:** https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672
**Category:** General
**Tags:** mqtt, shelly
**Created:** [16 January 2025 07:40 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672 "2025-01-16T07:40:25Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![onit](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@onit](https://discourse.nodered.org/u/onit)
#### Post date: [16 January 2025 07:40 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/1 "2025-01-16T07:40:25Z")

</div>

Hey Node RED community.

I'm on a beginners level using Node RED to monitor and control Shelly devices.  
My setup at the moment is a Shelly Plus 1 which is connected to my network and I was setting up Node RED on my MacBook.

Now I'm a bit overwhelmed with all steps to do in order to control the Shelly (switching on and off)

Here's what I can say for sure.

- Mosquitto v2.0.20 is installed with homebrew and the broker is running.
- The IP's of MacBook ({MacBook-IP}.9) and Shelly device ({ShellyDevice-IP}.9) indicate that it's connected to the same network.
- Shelly device runs with activated MQTT

Shelly device MQTT settings:

- Connection type: No TLS
- MQTT prefix: shellyplus1-{shellyID}
- Server: {MacBook-IP}.9
- Client ID: shellyplus1-{shellyID}
- Username: {my-mqtt-user-name}
- Password: {my-mqtt-user-password}

Node RED "mqtt out" node set to:

- Topic: shellies/shellyplus1-{shellyID}/relay/0/command/
- QoS: empty
- Server: {MacBook-IP}.9 | Port: 1883 | Protocol: MQTT V3.1.1
- Username: {my-mqtt-user-name}
- Password: {my-mqtt-user-password}

Now when I'm deploying in Node RED, it shows "connecting" below the MQTT-node and I'm not able to trigger anything.

I would appreciate constructive hints for my issue as I assume setting up should be a straight forward thing but I'm lacking of background knowledge.

Thanks in advance 🙂

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 January 2025 08:49 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/2 "2025-01-16T08:49:17Z")

</div>

Seems your not able to connect to the mqtt broker  
mqtt2 has some security settings that are enabled by default, or your user and password are incorrect

have a look here for settings for mqtt config file.

> [@Connection to MQTT broker not possible](https://discourse.nodered.org/t/connection-to-mqtt-broker-not-possible/42455/5):
>
> What version of mosquitto do you have installed ? In your mosquitto.conf file add the lines below because by default the new version 2.0 doesnt allow remote connections by default. [Link](https://mosquitto.org/blog/2020/12/version-2-0-0-released/) allow\_anonymous true listener 1883

---

<div class="post-metadata">

### Author: ![onit](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@onit](https://discourse.nodered.org/u/onit)
#### Post date: [16 January 2025 19:56 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/3 "2025-01-16T19:56:46Z")

</div>

Hey @E1cid.

Thanks for that.

I tried myself through. Found the config file, and uncommented  
allow\_anonymous true  
and  
listener 1883

I also found that _bind\_address 0.0.0.0_ should be in there.

Unfortunately without success. Everything is still having the same outcome.

The node-red terminal message shows:  
[info] [mqtt-broker:Switcher] Connection failed to broker: mqtt://172.20.10.9:1883

However, when I set localhost as Server in Node RED then I see

[info] [mqtt-broker:Switcher] Connected to broker: mqtt://localhost:1883

But that doesn't solve the Shelly issue.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [16 January 2025 20:08 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/4 "2025-01-16T20:08:55Z")

</div>

> [@onit](#):
>
> when I set localhost as Server in Node RED then I see
> 
> [info] [mqtt-broker:Switcher] Connected to broker: mqtt://localhost:1883
> 
> But that doesn't solve the Shelly issue.

Is this your Mac?  
Does it have a static / reserved IP address? What address?  
What is it's hostname and can you specify a hostname in the Shelly?  
What is the IP address of the Shelly (which doesn't have to be static)?

---

<div class="post-metadata">

### Author: ![onit](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@onit](https://discourse.nodered.org/u/onit)
#### Post date: [16 January 2025 20:40 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/5 "2025-01-16T20:40:08Z")

</div>

> Is this your Mac?

Yes

> Does it have a static / reserved IP address? What address?

No, DHCP. The address is 172.20.10.9

> What is it's hostname and can you specify a hostname in the Shelly?

What do you mean by hostname?

As to the Shelly. Here you have a screenshot how the MQTT setting looks (I just googled it):

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0cd2e3b581e4b8e2aa63a18d8c5119a0d85c8e1a.png)

> What is the IP address of the Shelly (which doesn't have to be static)?

It's 172.20.10.2. I assume it gets assigned automatically. It is indeed possible to set a static IP address, Network mask, Gateway and DNS.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 January 2025 21:16 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/6 "2025-01-16T21:16:31Z")

</div>

According to your shelly setting the server is 192.168.10.13  
but your notebook is 172.20.10.9

The IP of the notebook(where mosquitto is installed) should match the IP of the server in the shelly settings. Which should be a local lan IP not your internet wan IP

You should be able to set static IP's in your router using the mac address of the device. The broker will need a static IP.

---

<div class="post-metadata">

### Author: ![onit](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@onit](https://discourse.nodered.org/u/onit)
#### Post date: [16 January 2025 21:41 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/7 "2025-01-16T21:41:17Z")

</div>

Please be aware that the image I posted above is googled and not a screenshot of my own screen. I just posted it for demonstration purposes.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [16 January 2025 22:12 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/9 "2025-01-16T22:12:57Z")

</div>

> [@onit](#):
>
> What do you mean by hostname?

A computer can be referred to on a network using either it's IP address or a hostname.  
I don't know Macs but on my Linux computers the hostname is specified in /etc/hostname and can be shown with the `hostname` command.  
For example:

```auto
pi@GlassPi:~ $ hostname
GlassPi

```

While the IP address _may be_ set by the network DHCP server and might vary, the hostname is specified by the comouter itself and is thus fixed.

I asked about this because you may be able to specify the hostname rather than the IP address as the MQTT server (I have no idea if this will work for your Shelly).  
It's more usual though for the MQTT broker to have a static IP address, or at least a reserved address in the router.

Screenshots can sometimes help us understand how a system is set up.  
Not if they are a random photo from the internet though.

---

<div class="post-metadata">

### Author: ![onit](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@onit](https://discourse.nodered.org/u/onit)
#### Post date: [23 January 2025 16:28 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/10 "2025-01-23T16:28:18Z")

</div>

Hey @jbudd and @E1cid.

I understand your confusion about the content I provided as it always seems to be hard to think into an issue.  
Thanks for your inputs. I went back to the beginning and started off new.

I made it work and can state the following:

- there's no need to fix the IP
- something like hostname is not needed

Here's what does the trick.

**In the MacBook's Terminal:**

1. Properly setting up Mosquitto via brew on the Mac.
2. Starting Mosquitto, listening to port 1883 (default)

**In Shelly settings page**

1. Finding the Mac's IP address which (for now) is my (testing) server. Mine is 192.168.0.56
2. Navigating to Shelly setup via browser: My Shelly IP is 192.168.0.31, so [http://192.168.0.31/#/settings/mqtt](http://192.168.0.31/#/settings/mqtt) will bring me to the settings page for MQTT.
3. Tick the box for "Enable" at the top to start MQTT
4. Tick the box for "Enable 'MQTT Control'
5. Tick the box for "RPC over MQTT"
6. Tick the box for "RPC status notifications over MQTT"
7. Tick the box for "Generic status update over MQTT"
8. Set the Server to: "192.168.0.56:1883"
9. Set Client ID to: "{my-shelly-device\_ID}"

**In Node-RED**

1. Create an Inject-Node called "On"
2. Set msg.payload to

```auto
{
    "id": 1,
    "src": "mqtt",
    "method": "Switch.Set",
    "params": {
        "id": 0,
        "on": true
    }
}

```

1. Click "Done" to close the Inject node settings
2. Create another Inject-Node called "Off"
3. Set msg.payload to

```auto
{
    "id": 1,
    "src": "mqtt",
    "method": "Switch.Set",
    "params": {
        "id": 0,
        "on": false
    }
}

```

1. Click "Done" to close the Inject node settings
2. Create an mqtt-out-Node
3. Connect the On and Off Inject Nodes to the mqtt-out-Node
4. Open the mqtt-out-Node
5. Set the Topic to {my-shelly-device\_ID}/rpc
6. Under Server edit or create the following settings:
7. Server: 192.168.0.56 (that's my MacBooks IP address)
8. Port: 1883
9. Tick the box for "Connect automatically"
10. Click "Update" and "Done"

Now "Deploy" the flow and run a test.

Suddenly it worked without any issue.

**Summary:**

`{my-shelly-device_ID}/rpc`

followed by

```auto
{
    "id": 1,
    "src": "mqtt",
    "method": "Switch.Set",
    "params": {
        "id": 0,
        "on": false OR true
    }
}

```

Did the trick.

I hope that might help someone in the future.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [23 January 2025 16:55 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/11 "2025-01-23T16:55:04Z")

</div>

> [@onit](#):
>
> I made it work and can state the following:
> 
> - there's no need to fix the IP
> - something like hostname is not needed

Without the fixed IP of the mqtt broker or hostname, if the IP of the Mac Book changes (as router may give the Mac Book a new IP in the near future) Then node-red and the Shelly devices will not know what the new IP may be. So again i would advise to fix the IP or set a Hostname.

---

<div class="post-metadata">

### Author: ![onit](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@onit](https://discourse.nodered.org/u/onit)
#### Post date: [23 January 2025 17:06 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/12 "2025-01-23T17:06:30Z")

</div>

> [@E1cid](#):
>
> Without the fixed IP of the mqtt broker or hostname, if the IP of the Mac Book changes [...]

This is very true but was not part of my problem 🙂 And I also referred to my setup with:

> [@onit](#):
>
> Finding the Mac's IP address which (for now) is my ( **testing** ) server.

I will surely fix my IP address once I transfer it to production environment 🙂

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [23 January 2025 17:21 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/13 "2025-01-23T17:21:25Z")

</div>

> [@onit](#):
>
> This is very true but was not part of my problem 🙂 And I also referred to my setup with:

Your issue was you were using an incorrect IP (172.20.10.9) for the broker settings, if you had fixed the IP you would of been sure you where using the correct one.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [23 April 2025 17:21 UTC](https://discourse.nodered.org/t/shelly-integration-mqtt-via-macbook/94672/14 "2025-04-23T17:21:33Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
