Shellies Discovery Script

Look here: https://www.home-assistant.io/components/utility_meter/

I have been adding some more shellies to my HA using this script. Everything is working perfectly except very minor issues. Many thanks again for making this and put it publicly available for us to use it.

The minor things I have found are:

  • Sometimes you get duplicated devices related to firmware upgrades. I have solved this by upgrading Shelly firmware before setting up mqtt in them.
  • When trying to configure specific output as a “fan” or “light”, it is difficult to find out the name you need to use. For instance for a Shelly 2.5 it was “shellyswitch25-AABBCC-relay-0”. I had to view logs to get it, maybe it would be useful to list this in the readme for all shellies supported.
  • Setting the output to one relay of a Shelly2.5 automatically also sets the other relay to the same type. So for instance setting “shellyswitch25-AABBCC-relay-0: “light”” also sets relay 1 to light (I had to manually put it to switch again and was solved).
  • Setting a specific type as above creates zombie unavailable entities (with the previous type) that need to be deleted manually on the registry entries.

As I said very minor issues. Great work!!

yes I am!

sorry!

Yes, this is known issue. I’m not sure that this is a script issue. Sometimes after Shellies firmware upgrade HA generates new id for device registry entry. I don’t know why.

I know, documentation needs some work.

I just did a test and I changed the type of one relay in my Shelly2 to light. The second relay remained a switch.

When you change relay type script will automatically remove old config topic from MQTT broker but You have to start Shellies Announce automation and restart HA (or twice restart HA) to apply this change.

No problem.

Sorry my stupid question, but with this script is possible to keep the official app working?

Yes, but you cannot use the cloud, you need to activate MQTT on the web page of the Shelly you want to discover.

And there is any way to keep both of them working simultaneously?

I’ve been using StyraHem Shelly component for a while, with no issues so far. It uses CoAP and REST for communication. I see this script uses MQTT. Can anybody tell me if there’s any advantage to one or the other?

Tell me please,
After rebooting hassbian, Shelly sensors are in the “not available” state. After starting Shellies Announce automation, the system is updated and the sensors receive status.
initial_state: ‘on’ - enabled. What else can I see?

  • MQTT is very fast and good communication protocol for IoT. Shelly devices support MQTT. Why don’t use it?
  • Not every routers/acess points support CoAP.
  • ShellyforHASS is a custom component, personally, I try to use only official components.

Are You sure that Shellies Announce automation starts with Home Assistant start and Shellies answer for announce topic?

How to check it? I did not make any additional settings.
python_script: in configuration.yaml
shellies_discovery.py in / config / python_scripts
Automation rules in automations.yaml
Plus initial_state: ‘on’"

If You add to configuration.yaml this:

logger:
  logs:
    homeassistant.components.automation: info

there will be in log entries about automations start.

You can use mosquitto_sub (or any other MQTT app) to see MQTT topics at HA starts.

[quote=“Bieniu, post:316, topic:94048”]
homeassistant.components.automation: info
[/quote] As far as I understand Shellies Announce - launched.
https://pastebin.com/5vkQT67E
Shelley - Unavailable

What about MQTT topics?

Yes, I see “announce” from shellies / command with MQTT.fx
after 11 minutes I manually launch Shellies Announce. Shelley show up.
https://pastebin.com/gWadF8dA

Maybe add to actions of Announce Shellies delay 30 seconds and once again command/announce.

Can we/you do something to have all the date presented on the entity like ShellyforHASS presents them?

On MQTT this is all i have got

image

The Shelly discovery script is installed via hacs and this is the configuration in automations

- id: shellies_announce
  alias: 'Shellies Announce'
  trigger:
    - platform: homeassistant
      event: start
  action:
    service: mqtt.publish
    data:
      topic: shellies/command
      payload: announce

- id: 'shellies_discovery'
  alias: 'Shellies Discovery'
  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 }}'
      shellyswitch25-xxxxxxx-relay-0: 'light'
      shellyswitch25-xxxxxxx-relay-1: 'light'
      shelly1pm-xxxxxx-relay-0: 'light'

Attributes of the entity should shows informations about this entity, not about device.
In the future version of Shelly firmware there will be status topic with device data. I will add this data as sensor(s).