Shellies Discovery Script

New version: 0.27.0

Changelog:

  • add minimal firmware version check
  • add RSSI sensor for AC powered devices, firmware 1.8.0 required
  • add SSID sensor for AC powered devices, firmware 1.8.0 required
  • firmware update sensor uses data from info topic for AC powered devices, firmware 1.8.0 required

I’m getting errors while automations is running:

2020-08-15 17:29:05 INFO (MainThread) [homeassistant.components.automation.shellies_announce] Executing Shellies Announce
2020-08-15 17:29:05 INFO (MainThread) [homeassistant.components.automation.shellies_announce] Shellies Announce: Running script
2020-08-15 17:29:05 INFO (MainThread) [homeassistant.components.automation.shellies_announce] Shellies Announce: Executing step call service
2020-08-15 17:29:06 INFO (MainThread) [homeassistant.components.automation.shellies_discovery] Executing Shellies Discovery
2020-08-15 17:29:06 INFO (MainThread) [homeassistant.components.automation.shellies_discovery] Shellies Discovery: Running script
2020-08-15 17:29:06 INFO (MainThread) [homeassistant.components.automation.shellies_discovery] Shellies Discovery: Executing step call service
2020-08-15 17:29:06 INFO (SyncWorker_5) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'shellyswitch25-68C63AFA534D', 'mac': '68C63AFA534D', 'fw_ver': '20200812-091015/v1.8.0@8acf41b0'}
2020-08-15 17:29:06 ERROR (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Error executing script: None is wrong dev_id argument
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 205, in execute
    exec(compiled.code, restricted_globals)
  File "shellies_discovery.py", line 332, in <module>
ValueError: None is wrong dev_id argument

my mqtt config is

mqtt:
  broker: core-mosquitto
  discovery: true
  discovery_prefix: homeassistant

the automation:

- id: shellies_announce
  alias: 'Shellies Announce'
  trigger:
    - platform: homeassistant
      event: start
    - platform: time_pattern
      hours: "/6"
  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 }}'

what am I missing?

1 Like

Update:
I found that changing the script line 19 to CONF_ID = "id" instead of CONF_ID = "id" solves this issue, but I’m not sure why my device return id and not dev_id

Please update the script to version 0.27.2. I made a stupid mistake in 0.27.1.

1 Like

@Bieniu

Can u please tell me how ur script can help with my issue ?

The script will add cover entities to your HA without manually configuring YAML.

I add ur script in the python script folder then i restart twice but i cant see just 2 entities the announce and discovery entities i can see my shellys .

Can u help me with the custom script config. How i can add my shellys , see my shellys topics in the link i sent before :slight_smile:

Have you read the documentation? You have to add automations and script configuration.

This the code I add in the automation.yaml

- 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 }}'
      discovery_prefix: 'hass'
      qos: 2
      shellyswitch25-68EF11:
        mode: "roller"
        roller-0-name: "Room Door"
        roller-0-class: "door"
      shellyswitch25-693FA7:
        mode: "roller"
        roller-0-name: "Room Window"
        roller-0-class: "window"

Looks good. If it’s not working check https://github.com/bieniu/ha-shellies-discovery#troubleshooting-checklist and enable logging https://github.com/bieniu/ha-shellies-discovery#how-to-debug
I assume you have the python_script component enabled in configuration.yaml.

I just update my mqtt config like this , any comment ?

mqtt:
  broker: 192.168.1.101
  port: 1883
  username: mqtt_admin
  password: ******
  discovery: true
  discovery_prefix: homeassistant

logger:
  default: warning
  logs:
    homeassistant.components.python_script: debug
    homeassistant.components.automation: info

python_script:

You have a different discovery_prefix in your MQTT configuration and in your script configuration.

I will change it , where u see my discovery_prefix ?

Here Shellies Discovery Script - #759 by wmashal

1 Like

Still cant see my shelly’s , do I need any configurations through the shelly web ui ? on the device ?

I see this in mosquitto

1597657881: Warning: Mosquitto should not be run as root/administrator.
1597657882: New connection from 192.168.1.100 on port 1883.
[INFO] found mqtt_admin on local database
1597657883: New client connected from 192.168.1.100 as shellyswitch25-693FA7 (p2, c1, k60, u'mqtt_admin').
1597657883: New connection from 172.30.32.1 on port 1883.
[INFO] found homeassistant on local database
1597657883: New client connected from 172.30.32.1 as auto-FE235D0D-7E2F-EFBE-FC90-2E473C17D963 (p2, c1, k60, u'homeassistant').
1597657888: New connection from 192.168.1.100 on port 1883.
1597657888: New client connected from 192.168.1.100 as DVES_C69844 (p2, c1, k15, u'mqtt_admin').
1597657939: New connection from 192.168.1.100 on port 1883.
1597657939: Socket error on client <unknown>, disconnecting.
1597657998: New connection from 192.168.1.100 on port 1883.
1597657998: Socket error on client <unknown>, disconnecting.
1597658063: New connection from 192.168.1.100 on port 1883.
1597658063: Socket error on client <unknown>, disconnecting.
1597658117: New connection from 192.168.1.100 on port 1883.
1597658117: Socket error on client <unknown>, disconnecting.
1597658181: New connection from 192.168.1.100 on port 1883.
1597658181: Socket error on client <unknown>, disconnecting.

What about HA log? You should see entries for python_script.

2020-08-17 13:00:00 INFO (SyncWorker_2) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'shellyswitch25-693FA7', 'mac': '2EF432693FA7', 'fw_ver': '20190329-124426/master@854171ac', 'discovery_prefix': 'hass', 'qos': 2, 'shellyswitch25-68EF11': {'mode': 'roller', 'roller-0-name': 'Room Door', 'roller-0-class': 'door'}, 'shellyswitch25-693FA7': {'mode': 'roller', 'roller-0-name': 'Room Window', 'roller-0-class': 'window'}}
2020-08-17 13:00:00 ERROR (SyncWorker_2) [homeassistant.components.python_script.shellies_discovery.py] Error executing script: list index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 205, in execute
    exec(compiled.code, restricted_globals)
  File "shellies_discovery.py", line 353, in <module>
  File "/usr/local/lib/python3.8/site-packages/RestrictedPython/Eval.py", line 35, in default_guarded_getitem
    return ob[index]
IndexError: list index out of range

Your Shellies firmware is out of date. The script only works only with the current version.

You the Best Man , work as a charm :slight_smile:

1 Like

I’m glad You found the script useful.