Shellies Discovery Script

It’s not possible. Only MQTT prefix is using by the script.

1 Like

Actually, custom MQTT prefix is set identically.
Unfortunately, Your script only picks up the last portion of the prefix to give it an ID.

MQTT-topics are like:
Shellies/15-01-Blind-Window

With Shelly Discovery scripts IDs in home assistant become:
cover.shelly_2_5_window

I would like to have cover.15_01_blind_window as device ID in home assistant such that all the entities use this as a prefix.

Is that possible?

I have 2 shellies 1 switch and only one is found by the HA shelly integration. This is the one connect to the wifi of my modem. The other one is in the garage and i am using a power plug wifi accesspoint.
I can connect to both by ip address. I was hoping your addon would solve this problem but it’s not found. I added python_script: to my configuration.yaml and shellies_discovery.py file in config/python_scripts folder.

This is my automation:

- id: '1643542991448'
  alias: Shelly Discovery
  description: ''
  trigger:
  - platform: homeassistant
    event: start
  condition: []
  action:
  - service: mqtt.publish
    data:
      payload: announce
      topic: shellies/command
- id: '1643544074521'
  alias: Shellies Discovery
  trigger:
  - platform: mqtt
    topic: shellies/announce
  action:
  - service: python_script.shellies_discovery
    data:
      id: '{{ trigger.payload_json.id }}'
      mac: '{{ trigger.payload_json.mac }}'
      fw_ver: '{{ trigger.payload_json.fw_ver }}'

Your automation is not up-to-date.

Yes, this limitation is related to Shelly ID (it contains - sign).

You can use device_name parameter or try to convince the Shelly team to send device/channel name in the announce topic payload.

Can you tell me what’s wrong in the automation code?

Dziękuje bardzo!

I will give device_name parameter a try.

@Bieniu
Feedback: The approach works for me. The entity IDs appear in a way how I would want them to be.

My configuration takes place in an automations.yaml file, is it somehow possible to externalize the config itself? I’m referring to the part that follows after the comment:

- id: 'shellies_discovery'
  alias: 'Shellies Discovery'
  mode: queued
  max: 999
  trigger:
    platform: mqtt
    topic: shellies/announce
  action:
    service: python_script.shellies_discovery
    data:
      id: '{{ trigger.payload_json.id }}'
      mac: '{{ trigger.payload_json.mac }}'
      fw_ver: '{{ trigger.payload_json.fw_ver }}'
      model: '{{ trigger.payload_json.model }}'
      mode: '{{ trigger.payload_json.mode | default }}'
      host: '{{ trigger.payload_json.ip }}'
      # Following allows for setting the device's entity ID in HA as per naming convention
      03-02-Licht-Decke:
        device_name: "03-02-Licht-Decke"
      13-01-Raffstore-FensterLinks:
        device_name: "13-01-Raffstore-FensterLinks"
      13-02-Raffstore-FensterRechts:
        device_name: "13-02-Raffstore-FensterRechts"
      ...

Some include-statement or something similar?

Where do you find the newest firmware ?
My shelly Plug S all said they had the newest firmware availible.
20190516-073020/master@ea1b23db
but the Discovery script Claimed I needed 220126 version
So I searched, and ended up at http://archive.shelly-tools.de/
There I find v 1.11.7, which seems to be the newest (but strange sorting on the version list)
I’ve upgraded 2 of my 4 devices, but the Discovery script still claims I need a newer firmware. Looking through the code, it seems I need version 1.11.8-rc2. But that one is not available from archive.shelly-tools.de, nor from shelly.cloud, where the newest version is 1.9

I Tried now to enable Cloud integration, and now it found version 1.11.7 on one of the plugs that I hadn’t already upgraded using archive.shelly-tools.de

Still unsure what to do.

Finally it’s working. There is one thing i can’t figure out. I have one Shelly in the garage connected to a wifi booster plug. It does not connect in the garage, but in the livingroom connected directly to my modem/router there is no problem at all. This is in my log:

Cannot connect to host 192.168.178.38:80 ssl:default [Connect call failed (‘192.168.178.38’, 80)

Why are you using the script from the master branch and not from the release?

Master branch contains the code with changes related to firmware that is available only for Shelly QA group.

The script uses only MQTT so this error is not related.

Not sure what you mean by master branch. I got the shellies last month, i think, and found that they had the latest firmware. Since then I’ve found this thread, and found that I had old hardware. but I was not able to find firmware dated from 20220126 or later. Activated Cloud integration on the shellies, and got the firmware updated to 20211109-130223/v1.11.7-g682a0db, then re-enabled mqtt. I also found the 20220126 firmware-date in the code, and reverted back to 20210720, and now the script works.

Still unsure where you get the newest (release candidate) firmware, but now the script works.

Those firmware iare available only for the members of Shelly QA group on FB.

You shuld not use the script from master branch on GitHub because it can be unstable or even doesn’t work at all. Install the script from releases Releases · bieniu/ha-shellies-discovery · GitHub
I recomend to use HACS to install/update the script.

Ahh, I just followed the link on the top of the page. The I get the master-branch. Did not think about checking for other versions.

I updated the script to 0.43.9 using HACS, and now I get the following in the logs:

Log Details (ERROR)

Logger: homeassistant.components.python_script.shellies_discovery.py
Source: components/python_script/__init__.py:224
Integration: Python Scripts ([documentation](https://www.home-assistant.io/integrations/python_script), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+python_script%22))
First occurred: 15:19:26 (2 occurrences)
Last logged: 15:19:27

* Error executing script: Firmware dated 20220209 is required, update your device shellydimmer-BC03EF
* Error executing script: Firmware dated 20220209 is required, update your device shellydimmer-BC0D4E

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 224, in execute exec(compiled.code, restricted_globals) File "shellies_discovery.py", line 1326, in <module> ValueError: Firmware dated 20220209 is required, update your device shellydimmer-BC03EF

These are both Shelly Dimmer (original version, not 2), and they report 1.11.7 as the latest available FW. According to the FB post for this release, the latest 1.11.8 FW was pulled for Dimmer v2, and I guess for Dimmer v1 as well. Should Shellies Discovery perhaps be reverted or updated to reflect this?

Firmware 1.11.8 is available for SHDM-1, you have to update your devices to use current version of the script.

Like I said, v1.11.8 is not available for my dimmers (yes, I have pressed the “check for new firmware” button multiple times, as well as rebooted the device. My other Shellies updated with no issues.):


I even updated manually to 1.11.8 from http://archive.shelly-tools.de. That worked, but it still claimed that 1.11.7 is the newest and I could “upgrade” from 1.11.8 to 1.11.7.

Regardless: Should the script really require 1.11.8 when the latest available FW version for one or more device types is 1.11.7?

Yes, the script really needs 1.11.8 firmware because of restart button, reboot command is not available on 1.11.7.