Shellies Discovery Script

Guys, what do you think about device automation triggers? Will it be useful?

1 Like

I think so! It is just a little bit easier to create automations with them…

@Bieniu
I have a DW2 and 3x H&T on battery (all on 1.9.0) and I left MQTT explorer open for the last 15 hours and still no Info topic for any of them…other topics updated

Will keep it on for a bit longer to see if it pops up but I’m not sure if I’ve ever seen it before.

This confirms my tests, I had no info topic from Flood and HT for 24 hours. Thanks for help.

Should there be an info Topic for the rest of them? I haven’t seen those for my 2.5 and i3’s either.

According to the documentation all devices with firmware 1.8.0 or later should send this topic.

My mains powered devices send it but very rarely.

Aha! I’ve had MQTT Explorer Running for too short a time. It seems my mains-powered devices send the info topic every full hour. I’ve seen them twice since my first message. So - all good!

New version: 0.37.0

Changelog:

  • add device automation trigger for inputs
  • add ssid and uptime sensors for Shelly Motion
  • add input sensors for Shelly 4Pro

How to use device automation triggers?

You have a Shelly 4 Pro?:slight_smile:

No, I don’t have.

Hi Bieniu,

I try to install but hit some trouble with your link
if I paste “https://github.com/bieniu/ha-shellies-discovery” into hacs custom repo url with category integration, I got the following message : “Repository structure for 0.37.0 is not compliant” … ???
My HA Version is |2021.1.4| & Installation Type|Home Assistant OS|
HACS 1.10.0

Shellies Discovery is not a custom component. Please read the docs.

please could you provide a link to the doc you mean (github is the same as your first post here). I have read hundreds of pages already including those 1090 posts) and spent months to have my shellly 2.5 running (still not) (all other shelly are auto discovered since 0.118, the 2.5 are not, I already have some sonoff/tasmota running without problem with MQTT for many months, all my 2.5 are also set with MQTT but not discovered by HA, this is why I would love to install your script (yes script, not component, addon, integration, …)

Sorry to cut hair in 4, but let start slowly with your installation instruction.(maybe you will understand why a “newbee” like me is failling)

Installation

"You can install this script via HACS BROKEN LINK but went for this one instead or just download shellies_discovery.py file this is a web page so copy/paste in a text editor and save as “shellies_discovery.py” file name and save it in /config/python_scripts folder. I use File editor addon to navigate in the directory and I cannot find python_scripts into config
You have to add python_script component to your configuration.yaml file:

Copy to clipboard

# configuration.yaml file
python_script:

Repository : https://github.com/bieniu/ha-shellies-discovery

-> from your previous comments this not the repository for HACS, so what kind of repository is it ? I start to be very confused with repository. where to you add it into HACS if not in repository url (despite being introduce as a script and not a custom component), confusing isn’t it ?).
So both sides of the installation path are not taking me anywhere …

Really your “script” should be built-in HA official release like Tasmota beta is. (if Mqtt is on don’t bother with coap autodiscovery)
it’s so enraging to be so close and so far at the same time … starting all over again and again and again. (if you remember I did offer you a 1 to 1 paid session few months ago)

a good youtube video is worth millions words (write or read)

It is a repository for HACS but not a integration and not a custom repository.

Today I’m at home so I can help you.

Link fixed, thanks.

Where does the script documentation says that you have to add a repository to HACS? Nowhere because you don’t have to do this.


Do you have python_script component configured and running?

It’s not possible.

Sorry, but I have a life, a family, a job, and I don’t have time to help anyone, even if they want to pay me for it. If I have time, I try to help and I don’t take any money for it. If someone decides that I helped him, he can buy me a beer/coffee with a donation.

Good Morning Bieniu !
Thank you so much for your goodwill assistance.
my morning progress:
My mistake was ignoring the prerequiste (Humble Sorry), I did that and install shellies_discovery.py into /config/python_scripts folder.
modify configuration.yaml file accordingly your instruction (1st time I touch configuration.yaml up to now everything was autodiscovered for me, it could have stay like that if only those damn Shelly2.5 needed MQTT to work), reboot twice. It take me some time to find out that “calling service” mean you have to go to -> developper tools->service (choose python_script.shellies_discovery) and click call service button. then in the log it show this error :

2021-01-19 11:40:48 WARNING (MainThread) [homeassistant.config_entries] Config entry for shelly not ready yet. Retrying in 80 seconds

2021-01-19 11:41:53 INFO (SyncWorker_5) [homeassistant.components.python_script] Executing shellies_discovery.py: {}

2021-01-19 11:41:53 ERROR (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Error executing script: None is wrong id argument

Traceback (most recent call last):

File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 217, in execute

exec(compiled.code, restricted_globals)

File "shellies_discovery.py", line 482, in <module>

ValueError: None is wrong id argument

2021-01-19 11:42:11 WARNING (MainThread) [homeassistant.config_entries] Config entry for ipp not ready yet. Retrying in 80 seconds
```


Thank you for your help!

Also going the python way, can I delete HACS ? (with those alarming security bulletin you never now)
and I rather stay as simple as possible.

when discovery will be sorted, extra question what the best lovelace card for roller shutter ?

You can’t manually run the shellies_discovery.py script. You have to add automations to your configuration GitHub - bieniu/ha-shellies-discovery: Script that adds MQTT discovery support for Shellies devices

HACS is a very secure component. You can trust it. The advantage of HACS is that you can easily update the script. Updates are released frequently.

another 3h of fight and I got some good results and still some questions.

When I come back from lunch magically (mistery) I found HACS automation add a Python Script tick and that page which was empty before (just AppDaemon and NetDeamon tick) was displaying your Script.


So I installed it (and see shellies_discovery.py was also updated with this time). so far so good.
I added the following code into automations.yaml

# automations.yaml file
- id: shellies_announce
  alias: 'Shellies Announce'
  trigger:
    - platform: homeassistant
      event: start
    - platform: time_pattern
      hours: "/1"
  action:
    service: mqtt.publish
    data:
      topic: shellies/command
      payload: announce

- id: 'shellies_discovery'
  alias: 'Shellies Discovery'
  mode: queued
  max: 999
  trigger:
    platform: mqtt
    topic: shellies/announce
  action:
    service: python_script.shellies_discovery
    data_template:
      id: '{{ trigger.payload_json.id }}'
      mac: '{{ trigger.payload_json.mac }}'
      fw_ver: '{{ trigger.payload_json.fw_ver }}'
      model: '{{ trigger.payload_json.model }}'
      
      shellyswitch25-C4D816:
        mode: "roller"
        roller-0-name: "Garage"
        roller-0-class: "garage"
        position_template: "{{ '{% if value | float < 30 %}0{% else %}{{ value }}{% endif %}' }}"
        set_position_template: "{{ '{%if position | float < 30 %}0{% else %}{{ position }}{% endif %}' }}"
        
      shellyem-B9E21E:
        force_update_sensors: true

reboot twice;
I am able to see my ShellyEM (1 with coap) and also with MQTT. I have them both in lovelace ;-)) I will take care of the coap to get rid of it soon.
My Shelly 2.5 finally show up after firmware update (minimum no more 1.8 but ok with 1.9.4).

Finally Victory after a lot of perseverence, and yes MQTT is the way to go for Shelly 2.5 who resist Coap installation (detected but “Failed to connect” due to response time too slow), with MQTT it just work instantly on button click, GREAT !

@Bieniu Beers on it’s way before tonight !!!

More questions:
do I need to modify automations.yaml manually each time I add a shelly ?
(still need to understand -> roller-0-name: “Garage” roller-0-class: “garage” -> could i just set the Area into HA ?)
do you know a nice lovelace card for roller shutter ?

1 Like

Thanks, cheers :beers:

No, the new device will be detected and added to the HA automatically.

This is friendly_name and device_class of cover entity Cover - Home Assistant You can ignore roller-x-name and change entity name in HA.

Yes, you can set area for the device.