Skip to main content
Skip table of contents

Discovering Shelly Devices via mDNS

mDNS.png

Shelly devices (like many modern smart-home devices) advertise themselves on a local network using mDNS (Multicast DNS). In this article, we’ll explain:

 

  1. What mDNS is and how Shelly devices use it

  2. How to discover Shelly devices via mDNS (including command-line utilities)

  3. Automated discovery with Python (link to our example script)

  4. Troubleshooting & Tips

What Is mDNS?

 

mDNS (Multicast DNS) is a protocol defined in RFC 6762 that enables devices on a LAN (Local Area Network) to discover each other without a central DNS server. It accomplishes this by sending and receiving DNS-like queries over UDP port 5353 to a multicast group. Popular implementations of mDNS include Apple’s Bonjour and Avahi on Linux.

Why does this matter for Shelly devices? Because each Shelly device announces itself using the specific service type (_shelly._tcp.local.), allowing any mDNS-capable tool to detect these broadcasts and display details like IP addresses and firmware versions, and because mDNS is often paired with DNS-SD (sometimes called its “cousin”) to provide a structured method of advertising and browsing services by type (e.g., _shelly._tcp.local.), this functionality is particularly important for Shelly devices.

How to Discover Shelly Devices via mDNS

Shelly’s mDNS Service Type

Shelly devices broadcast under this service type:

CODE
_shelly._tcp.local.

 

By default, each Shelly device announces:

  • Instance Name (Service Name): Often looks like shelly2pmg4-7c2c67640b38._shelly._tcp.local.

  • Hostname (Server) (e.g., Shelly2PMG4-7C2C67640B38.local.)

  • IP Address(es)

  • Port (80)

  • TXT Records containing key properties:

    • gen: Generation (e.g., 4)

    • app: Device name/model (e.g., S2PMG4)

    • ver: Firmware version (e.g., 1.5.99)

 

Command-Line Discovery Tools

 

macOS: dns-sd

  1. Browse for Shelly services:

CODE
dns-sd -B _shelly._tcp

You’ll see Shelly devices as they appear.

  1. Resolve a specific device to see detailed TXT records:

CODE
dns-sd -L "shelly2pmg4-7c2c67640b38" _shelly._tcp local

You’ll see something like:

CODE
Lookup shelly2pmg4-7c2c67640b38._shelly._tcp.local
DATE: ---Fri 21 Feb 2025---
10:38:08.309  ...STARTING...
10:38:08.611  shelly2pmg4-7c2c67640b38._shelly._tcp.local. can be reached at Shelly2PMG4-7C2C67640B38.local.:80 (interface 24)
 gen=4 app=S2PMG4 ver=1.5.99

 

Linux: avahi-browse

  1. Install if necessary:

CODE
sudo apt-get update
sudo apt-get install avahi-utils
  1. Browse for _shelly._tcp services:

CODE
avahi-browse --resolve --terminate --parsable _shelly._tcp | grep "^="

This displays each Shelly device’s IP, port, and TXT data (including gen, app, ver) in a table. You’ll see something like:

CODE
=;eth0;IPv4;ShellyWallDisplay-00A90BA7352B;_shelly._tcp;local;ShellyWallDisplay-00A90BA7352B.local;192.168.1.134;80;"discoverable=false" "ver=2.3.1" "gen=2" "app=WallDisplay"
=;eth0;IPv4;ShellyWallDisplay-000822858F3D;_shelly._tcp;local;ShellyWallDisplay-000822858F3D.local;192.168.7.208;80;"discoverable=false" "ver=2.3.2" "gen=2" "app=WallDisplay"
=;eth0;IPv6;shellypstripg4-7c2c67642200;_shelly._tcp;local;ShellyPStripG4-7C2C67642200.local;fd62:7244:6b44:daec:7e2c:67ff:fe64:2200;80;"ver=1.5.99-dev113814" "app=PowerStrip" "gen=4"
=;eth0;IPv6;shelly2pmg4-7c2c677a0220;_shelly._tcp;local;Shelly2PMG4-7C2C677A0220.local;fd62:7244:6b44:daec:7e2c:67ff:fe7a:220;80;"ver=1.5.99-dev114895" "app=S2PMG4" "gen=4"
=;eth0;IPv4;shelly2pmg4-7c2c677a0220;_shelly._tcp;local;Shelly2PMG4-7C2C677A0220.local;192.168.9.14;80;"ver=1.5.99-dev114895" "app=S2PMG4" "gen=4"
=;eth0;IPv4;shellyhtg3-84fce63f8908;_shelly._tcp;local;ShellyHTG3-84FCE63F8908.local;192.168.9.209;80;"ver=1.1.0" "app=HTG3" "gen=3"
=;eth0;IPv4;ShellyWallDisplay-00A90BA735AC;_shelly._tcp;local;ShellyWallDisplay-00A90BA735AC.local;192.168.2.7;80;"discoverable=false" "ver=2.3.0" "gen=2" "app=WallDisplay"

Automated Discovery with Python

For a fully automated approach, try our example Python script which uses the zeroconf library and the rich library:

  1. Scans for _shelly._tcp.local. over a configurable time window.

  2. Collects each device’s hostname, IP addresses, TXT records, etc.

  3. Sorts them (optional) by generation, firmware version, device name, etc.

  4. Prints a colorized table with all discovered Shelly devices.

Example usage:

CODE
python find_shelly_mdns_devices.py --scan-time 15 --sort gen
  • --scan-time 15 runs the scan for 15 seconds.

  • --sort gen sorts results by the gen field in the TXT record.

You’ll see output like:

CODE
Service Name             Server                       IP Address(es)     Port  Device Name  Version   Gen  Other Properties
-----------------------  ---------------------------  -----------------  ----  -----------  --------  ---  -----------------
shelly2pmg4-7c2c67640b38 Shelly2PMG4-7C2C67640B38.local. 192.168.1.15     80    S2PMG4       1.5.99    4    N/A
...
Total Devices Discovered: 1

Troubleshooting & Tips

 

  1. Check Multicast Traffic

  • Some routers or firewalls block UDP port 5353 (used by mDNS). Ensure your firewall and network settings allow multicast traffic.

  1. Same Network Segment

  • Make sure the resolver (your computer or script) and the Shelly devices are on the same Layer‑2 subnet. Multicast packets typically won’t traverse VPNs or network segments unless specifically configured.

  1. Test Other Tools

  • If the Python script can’t find devices or you want to test with other tools, try dns-sd (macOS) or avahi-browse (Linux) to confirm that Shelly devices are actually announcing themselves via mDNS.

  1. Give It Time

  • Shelly devices may take a few seconds to respond. If you suspect something’s missing, scan for a longer duration (e.g., 15–30 seconds).

We Value Your Feedback!

Thank you for taking the time to read our article! Was it helpful or interesting?

Your insights can help us improve. We’d be grateful for any feedback. If you have a moment,

please share it with us at the following email:

Integration@shelly.com

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.