Shellies Discovery Script

I have problem that Shelly Valve is not discovered by the script… probably not problem in the script but somewhere in configuration…

Can you please share me mqtt sensor configuration for shelly valve (TRV) so that I try to configure in old fashion way…

Thank you…

I mean to add mqtt sensors manually as I am used to do with Tasmota…

I get the same error. Just installed the script and the two default automations like discribed in the docs.

And I have another issue with hacs. I am able to update using HACS but when open the automations tab I even cant find the discovery script and it is not even listed.
Maybe anyone knows this issue. Is there away to force hacs clearing cache and scan for installed components again? The python_script integration is enabled for a long time in my configuration.

Please post a debug log for python_script component.

Which sensor?

If you want I can help with Shellies Discovery, post here a debug log for python_script component.

I set this in the configuration-file:

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

After restart, I here is the log. I get an info message and this:

2022-01-12 08:06:30 ERROR (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Error executing script: host value None is not valid, update shellies_discovery automation
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 222, in execute
exec(compiled.code, restricted_globals)
File "shellies_discovery.py", line 1207, in <module>
ValueError: host value None is not valid, update shellies_discovery automation

Discovery automation

- 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 }}'

So, I renew python script (re-download it from HACS).

I set:

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

I also set mqtt discovery and prefix:

  broker: 192.168.XX.XX
  port: 1883
  username: XXXX
  password: XXXX
  discovery: true
  discovery_prefix: homeassistant

I also renew discovery script and announce in automation…

- id: '010'
  alias: 'Shellies Announce'
  trigger:
    - platform: homeassistant
      event: start
    - platform: time_pattern
      hours: "/1"  # Modifying this if you are using Shelly Motion can drain your device's battery quickly.
  action:
    service: mqtt.publish
    data:
      topic: shellies/command
      payload: announce
  mode: single

- id: '011'
  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 }}'
  mode: single

In MQTT HA finds new “already” added device… so discovery is working… but I do not get Shelly Valve (I have 6 devices), every valve has name shellytrv-DIFFERENT_NAME…

So, I’m a little lost…

Which logs do you need to find what is happening… Because in “home-assistant.log” I do not get any info of valve…

Also… script do detect shelly rgbw2… so it’s working… it seems that something is wrong regarding valve detection…

Show me please the log.

And where is the log? :slight_smile:

2022-01-12 18:00:00 WARNING (MainThread) [homeassistant.components.automation.shellies_discovery] Shellies Discovery: Already running

2022-01-12 18:00:00 WARNING (MainThread) [homeassistant.components.automation.shellies_discovery] Shellies Discovery: Already running

2022-01-12 18:00:00 INFO (SyncWorker_0) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'shellyrgbw2-hodnik', 'mac': 'XXXXXXXX', 'fw_ver': '20211109-130054/v1.11.7-g682a0db', 'model': 'SHRGBW2', 'mode': 'color', 'host': '192.168.XXX.XXX', 'discovery_prefix': 'homeassistant', 'qos': 2}

2022-01-12 18:00:00 DEBUG (SyncWorker_0) [homeassistant.components.python_script.shellies_discovery.py] id: shellyrgbw2-hodnik, mac: XXXXXXXX, fw_ver: 20211109-130054/v1.11.7-g682a0db, model: SHRGBW2

2022-01-12 18:00:00 DEBUG (SyncWorker_0) [homeassistant.components.python_script.shellies_discovery.py] {'topic': 'homeassistant/button/shellyrgbw2-hodnik-update_firmware/config', 'payload': '{"name": "Shelly RGBW2 hodnik Update Firmware", "cmd_t": "~command", "payload_press": "update_fw", "en": "true", "uniq_id": "shellyrgbw2-hodnik-update_firmware", "qos": 2, "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "dev": {"cns": [["mac", "XXXXXXXX"]], "name": "Shelly RGBW2 hodnik", "mdl": "Shelly RGBW2", "sw": "20211109-130054/v1.11.7-g682a0db", "mf": "Allterco Robotics", "cu": "http://192.168.XXX.XXX/"}, "~": "shellies/shellyrgbw2-hodnik/", "entity_category": "config", "dev_cla": "update"}', 'retain': True, 'qos': 0}

This?
No single line regarding Shelly TRV (valve)…

PS. I reduced sensitive inf. with XXX

Don’t know how this will help you? :roll_eyes:

- id: shellies_announce
  alias: Shellies Announce
  trigger:
  - platform: homeassistant
    event: start
  - platform: time_pattern
    hours: /3
  action:
  - service: mqtt.publish
    data:
      topic: shellies/command
      payload: announce
  mode: single
- 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 }}'
      qos: 0
      shellyplug-s-DBED15:
        relay-0: switch
        force_update_sensors: true
      shellyplug-s-9A34D0:
        relay-0: switch
        force_update_sensors: true
      shellyplug-s-9A3DA7:
        relay-0: switch
        force_update_sensors: true
      shellyplug-s-B52B86:
        relay-0: switch
        force_update_sensors: true
      shellyswitch25-E0980695937D:
        roller-0-name: ROL_LIVING_TUIN
        roller-0-class: shutter
      shellyswitch25-40F5202A441B:
        roller-0-name: ROL_LIVING_ZIJKANT
        roller-0-class: shutter
      shellyswitch25-40F520002101:
        roller-0-name: ROL_LIVING_STRAAT
        roller-0-class: shutter
      shellyswitch25-40F5202A9946:
        roller-0-name: ROL_KEUKEN
        roller-0-class: shutter
      shellyswitch25-40F5202A9639:
        roller-0-name: ROL_ACHTERDEUR
        roller-0-class: shutter
      shellyswitch25-40F520018AD2:
        roller-0-name: ROL_BADKAMER
        roller-0-class: shutter
      shelly1-40F5200110A5:
        relay-0: switch
        relay-0-name: L_TUIN
      shelly1-40F520003F14:
        relay-0: switch
        relay-0-name: L_INKOM
      shelly1-40F5200045E7:
        relay-0: switch
        relay-0-name: L_OVERLOOP
      shelly1-F4CFA2E5EA4B:
        relay-0: switch
        relay-0-name: L_WC_GLV
      shellyswitch25-40F5202A97A2:
        relay-0: switch
        relay-0-name: L_LIVING_TAFEL1
        relay-1: switch
        relay-1-name: L_LIVING_TAFEL2
      shellyswitch25-40F5202A44B4:
        relay-0: switch
        relay-0-name: L_BERGING
        relay-1: switch
        relay-1-name: L_KEUKEN
      shellyswitch25-3C6105E55F21:
        relay-0: switch
        relay-0-name: L_TUIN1
        relay-1: switch
        relay-1-name: L_TUIN2
      shelly1-40F52000E397:
        relay-0: switch
        relay-0-name: BWM_1_INKOM
      shelly1-40F520000EFE:
        relay-0: switch
        relay-0-name: BWM_2_KEUKEN
      shelly1-40F5200103D3:
        relay-0: switch
        relay-0-name: BWM_3_BERGING
      shelly1-F4CFA2ECE8FD:
        relay-0: switch
        relay-0-name: BWM_4_OVERLOOP
      shelly1-F4CFA2E5E63B:
        relay-0: switch
        relay-0-name: BRANDDET_BERGING
      shelly1-E8DB84D23A8D:
        relay-0: switch
        relay-0-name: BRANDDET_OVERLOOP
      shelly1-40F520008262:
        relay-0: switch
        relay-0-name: SIRENE
      shelly1-F4CFA2ECE900:
        relay-0: switch
        relay-0-name: CV-KETEL
      shellydimmer2-F4CFA2E1041B:
        light-0-name: L_LIVING_ZETEL
      shellydimmer2-40F520014879:
        light-0-name: L_SLPK1
      shellymotionsensor-60A423992EAC:
        force_update_sensors: true
      shellymotionsensor-60A42399345E:
        force_update_sensors: true
      shellyht-956332:
        powered: ac
      shellyht-955170:
        powered: ac
      shellyht-AC4EBD:
        powered: ac
      shellyswitch25-40F5202A2CFB:
        relay-0: switch
        relay-0-name: BP_S1
        relay-1: switch
        relay-1-name: BP_S2
      shellyix3-8CAAB542EB07:
        relay-0-name: BP_B1
        relay-1-name: BP_B2
        relay-2-name: BP_B3
      shellybutton1-A4CF12F44C5C:
        powered: ac
      shellyem-B043BE:
        force_update_sensors: true
      shelly1pm-40F52000C59B:
        force_update_sensors: true

Posted it. There aren’t many log entries or am I missing something?

2022-01-12 20:10:27 INFO (SyncWorker_0) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'wohnzimmer_deckenlicht', 'mac': 'XXXXXXXXXXXX', 'fw_ver': '20211109-124958/v1.11.7-g682a0db', 'model': 'SHSW-1'}
2022-01-12 20:10:27 ERROR (SyncWorker_0) [homeassistant.components.python_script.shellies_discovery.py] Error executing script: host value None is not valid, update shellies_discovery automation
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 222, in execute
    exec(compiled.code, restricted_globals)
  File "shellies_discovery.py", line 1207, in <module>
ValueError: host value None is not valid, update shellies_discovery automation

log output:

2022-01-10 17:34:18 ERROR (SyncWorker_1) [homeassistant.components.python_script.shellies_discovery.py] Error executing script: expire_after value None is not an integer, check script configuration
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 222, in execute
exec(compiled.code, restricted_globals)
File "shellies_discovery.py", line 2660, in <module>
TypeError: expire_after value None is not an integer, check script configuration

Please read the changelog Release Version 0.41.0 · bieniu/ha-shellies-discovery · GitHub

Now I know that the script is working. Check your MQTT broker with MQTT-Explorer. Do you see there topics from TRV?

This is not a log, this is a small part of the log.

I checked again and nothing regarding trv in shellies in MQTT explorer… so don’t know what’s the real problem… other shellies do normal popup in logs… a little frustrating…

Yes, I’ve read it and this is exact the automation I use: Shellies Discovery Script - #1435 by panhans
Before I posted here I’ve checked the latest docs and refreshed the two automations. :wink:

2022-01-12 20:10:27 INFO (SyncWorker_0) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'wohnzimmer_deckenlicht', 'mac': 'XXXXXXXXXXXX', 'fw_ver': '20211109-124958/v1.11.7-g682a0db', 'model': 'SHSW-1'}

As you can see in the info log entry no host is given in the json data. Maybe thats why the script generates that error.

So, I’m stuck…
slika

It seems as that TRV do not send any MQTT notification…

Maybe should I try somehow to direct communicate to TRV (name: shellytrv-kuhinja)…
Is that possible… Maybe to make sensors manually…