Shellies Discovery Script

This script will not support gen2 devices. I’ll create a new script for them but this will take some time.

Unfortunately, I’m still a beginner with Home Assistant, but I’ve seen in various conversations an example of creating a full consumption sensor by adding up the consumption of the 3 phases. For example, it would be possible to make 3-3 extra sensors without rounding for per-phase consumption and returned-energy.
I would try to see what happens without rounding, but I don’t know how to turn it off. I would be grateful if you could help me! Based on the results, you will be able to decide if you need to fix or add to the script.

I thought there would be a few lines in the script settings that would allow the user to control rounding (default is 2, but could be 3-8) and unit of measure (default is kWh, but could be Wh, Wm, kWm).

What do you think?

Hello

Any idea how to solve the goofy numbers in my solar results after restart HA please?
I know there are already some topics about the template availability. But I do not know how to solve this in the Shellies Discovery Script.

Thanks for helping

Marijn

Solve what? I don’t understand your question.

I think I can add an option for devices that force to use Wmin for energy sensors.

I have some issues with the utility meter when I reboot my HA.
My utility meter looks like this in my configuration.yml:

utility_meter:
  daily_solar_energy:
    name: Solar Total Energy Daily
    source: sensor.shelly_em_solar_meter_total_returned_0
    cycle: daily

It gives me a peak number when I want to check the Energy panel when I rebooted my HA.
I think there might be a problem described like here:

So a availability_template with a check on the is_state (as described in the article in te link) should resolve the problem (I hope). But I do not know how to the availability_template to the template of the sensor (for example: sensor.shelly_em_solar_meter_total_returned_0)

Any idea how to solve this please?

Thanks a lot

Marijn

You can’t add availability_template to an existing sensor, you have to create a new one (template sensor).

Can you help me with a sample code of a new template sensor pls?

It would help me a lot…

Thank you

If you do, I will try and share the results with you. But you may have to help because I’m a beginner here.

Can someone help me: get this error on startup`

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

Show me configuration of the 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.