Shellies Discovery Script

For my use case I don’t need the detached option. Here is what I want to achieve:

I want a motion sensor to turn on the relay of the shelly which will also be automatically turned off after 30 seconds if there is no longer a motion. I also have a physical switch that can turn on the light if I don’t want the motion sensor to turn off the light after 30 seconds.

For this to work I need an automation that looks for the input value of the shelly.
So after 30 seconds it should see if the input value is “on” and then the motion sensor won’t turn off the switch even if there is no motion.

This would all work, but the problem is that if I turn off the light using Alexa or the shelly button within HA, the input value won’t be affected. This way the switch shows the light is off whereas the input still shows on. It is only possible to change the input value using the actual light switch.

This is why I need to directly change the input value. So I wanted to make an automation that the input goes to “off” as soon as the switch (relay) goes from “on” to “off”. This way it doesn’t matter if I use the actual light switch to turn the light off or use Alexa or the shelly button within HA.

I hope my description isn’t too complicated too understand as it is actually very simple. :slight_smile:

OK, now I understand your problem. It seems to me that topic input informs about the state of the physical switch. It can’t be changed without using this physical switch. Only Shelly developers may change this.

1 Like

New version: 0.9.6

Changelog:

  • add binary_sensor for longpush topic (Shelly1, Shelly1 PM, Shelly2, Shelly2.5)
  • add expire_after flag for battery powered sensors
1 Like

New version: 0.9.7

Changelog:

  • add abbreviation for light template variable names [HA 0.95 required]

Shellies Discovery script is now available in HACS

Just bought myself a few Shellies. Because I already have some ESP8266 I wanted to flash them with ESPHome, before I came across this discovery script.

What are the pros and cons of this script compared to ESPHome?

I don’t use ESPHome with Shellies. Shellies stock firmware is very good in my opinion.

Shellies Discovery Script not showing up in HACS Version: 0.11.1 ??

I didn’t have

python_script: True

in configuration.yaml

Thanks for your Shellies Discovery Script

in the HACS version: 0.11.1 you have changed the name of the plugin? I can only find Shelly smart home to install

Script is still in HACS.


I had a similar problem with one component. It disappeared suddenly from HACS. I removed hacs file from .storage folder and restarted HA and component returned.

I have a problem with the discovery script, it never launches for some reason. I can see in Node red that my shelly is sending shellies.announce to the MQTT broker, but that’s it. How can I troubleshoot the problem? Couldn’t find anything in the logs…
Would appreciate any help!

  1. Set logger to log automations executions:
logger:
  logs:
  homeassistant.components.automation: info
  1. Check that MQTT Discovery is enabled.
  2. Check that discovery_prefix in script configuration is the same as in MQTT configuration.
  3. Show me your automation for script.

From my configuration.yaml

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

And the automation for the script:

- 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:
      fw_ver: '{{ trigger.payload_json.fw_ver }}'
      id: '{{ trigger.payload_json.id }}'
      mac: '{{ trigger.payload_json.mac }}'

Wanted to say thank you for creating this.

I’m new to the HA community and this was one of my first attempts at setting up Shelly’s.

This automation made it so much easier once I worked through getting it installed.

1 Like

Looks good. Do you have python_script: in your configuration.yaml?

Nice to hear that.

Yes I have.
I can see in the log that the first automation shellies_announce gets called on HASSIO start.

shellies_discovery automation doesn’t start while after shellies_announce?
What Shellies do you use?
They have updated firmware and correctly configured MQTT? Script works only if Shellies use default topics. Do you change topics in Shellies configuration?
Can you show topics that Shellies send to MQTT broker.