Shellies Discovery Script

Hi

I’m trying to configure discovery script. I’m using 0.101.3 (and I tried it with 0.99.3 - the same error).

When I’m triggering shellies_discovery I get error:
ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘trigger’ is undefined

Automations config is copypasted from script

Please, help

Show me your config.

I need some yaml help to extract the “consumption” value from my Shelly1PM


What entries do I need in my sensors.yaml file so I can use this figure in some automations?

You are using ShellyForHass component. This thread is about Shellies Discovery script.

{{ state_attr('switch.shelly_shsw_pm_76bed9', 'consumption') }}

Look here: https://www.home-assistant.io/docs/configuration/templating/

I appreciate my query is not specific to the discovery script, my apologies but I was certain I am in company that would be able to help. I was hoping that it was possiblet to extract the figure into a sensor and thanks to the extensive documentation I have managed it.

  • platform: shelly
    sensors:
    • all

All the data is now available as sensors and easily dropped into automations.

Just to remind. When I’m triggering shellies_discovery I get error:
ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘trigger’ is undefined

configuration.yaml:

python_script:

automation: !include automations.yaml



File: automations.yaml:
- 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 }}'

Configuration looks good. Validation of the configuration in HA passed? Show me your MQTT topics log.

I don’t know how to get MQTT topics log.
But it works.

Whe I trigger “Shellies announce”:

2019-11-19 17:13:12 INFO (MainThread) [homeassistant.components.automation] Executing Shellies Announce
2019-11-19 17:13:12 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Announce: Running script
2019-11-19 17:13:12 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Announce: Executing step call service
2019-11-19 17:13:12 INFO (MainThread) [homeassistant.components.automation] Executing Shellies Discovery
2019-11-19 17:13:12 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Running script
2019-11-19 17:13:12 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Executing step call service
2019-11-19 17:13:12 INFO (SyncWorker_0) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'shellyplug-s-040B47', 'mac': '4C11AE040B47', 'fw_ver': '20190821-095311/v1.5.2@4148d2b7'}
2019-11-19 17:13:12 INFO (MainThread) [homeassistant.components.automation] Executing Shellies Discovery
2019-11-19 17:13:12 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Running script
2019-11-19 17:13:12 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Executing step call service
2019-11-19 17:13:12 INFO (SyncWorker_19) [homeassistant.components.python_script] Executing shellies_discovery.py: {'id': 'shelly4pro-F61717', 'mac': '780473F61717', 'fw_ver': '20190821-095050/v1.5.2@4148d2b7'}

and then “Shellies Discovery”:

2019-11-19 17:13:28 INFO (MainThread) [homeassistant.components.automation] Executing Shellies Discovery
2019-11-19 17:13:28 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Running script
2019-11-19 17:13:28 INFO (MainThread) [homeassistant.helpers.script] Script Shellies Discovery: Executing step call service
2019-11-19 17:13:28 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: 'trigger' is undefined

There are no Entities and Devices in Configuration

Use mosquitto_sub or MQTT Explorer.

Validation of the configuration in HA passed?

I don’t use HASS, so I have no buttons to check configuration here.
But there are no errors in log.
And everything else works as usual (including manually added MQTT devices).

Please, describe what do I need to look at MQTT.
As I understand logs, it found some error in configuration, not in MQTT or its messages.

I found many treads on UndefinedError: ‘trigger’ is undefined, but I don’t understand what is wrong here

mosquitto_sub -t 'shellies/command' -t 'shellies/announce'  -v




shellies/command announce
shellies/announce {"id":"shellyplug-s-040B47","mac":"4C11AE040B47","ip":"192.168.3.116","new_fw":false, "fw_ver":"20190821-095311/v1.5.2@4148d2b7"}
shellies/announce {"id":"shelly4pro-F61717","mac":"780473F61717","ip":"192.168.3.115","new_fw":false, "fw_ver":"20190821-095050/v1.5.2@4148d2b7"}

To show that it works using manual config (not auto discovery):

mosquitto_sub -t 'shellies/command' -t 'shellies/announce' -t 'shellies/shellyplug-s-040B47/relay/0' -v

shellies/shellyplug-s-040B47/relay/0 off
shellies/shellyplug-s-040B47/relay/0 on

If you are using Home Assistant you can validate configuration. Please read the documentation.

Script sends topics similar for this `homeassistant/switch/shellyswitch-5B2604-relay-0/config’

I used your automations and they work on my system.

hass --script check_config --config /config

**Testing configuration at /config**

This is MQTT log after “Shellies announce”:

shellies/command announce
shellies/shellyplug-s-040B47/online true
shellies/announce {"id":"shellyplug-s-040B47","mac":"4C11AE040B47","ip":"192.168.3.116","new_fw":false, "fw_ver":"20190821-095311/v1.5.2@4148d2b7"}
homeassistant/switch/shellyplug-s-040B47-relay-0/config {"name":"Shelly Plug S 040B47 Relay 0","cmd_t":"~relay/0/command","stat_t":"~relay/0","pl_off":"off","pl_on":"on","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyplug-s-040B47-relay-0","qos":"0","dev": {"ids": ["4C11AE040B47"],"name":"Shelly Plug S 040B47","mdl":"Shelly Plug S","sw":"20190821-095311/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shellyplug-s-040B47/"}
homeassistant/light/shellyplug-s-040B47-relay-0/config (null)
homeassistant/fan/shellyplug-s-040B47-relay-0/config (null)
homeassistant/sensor/shellyplug-s-040B47-power/config (null)
homeassistant/sensor/shellyplug-s-040B47-energy/config (null)
homeassistant/sensor/shellyplug-s-040B47-power-0/config {"name":"Shelly Plug S 040B47 Power 0","stat_t":"~relay/0/power","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{ value | float | round(1) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyplug-s-040B47-relay-power-0","qos":"0","dev": {"ids": ["4C11AE040B47"],"name":"Shelly Plug S 040B47","mdl":"Shelly Plug S","sw":"20190821-095311/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shellyplug-s-040B47/"}
homeassistant/sensor/shellyplug-s-040B47-energy-0/config {"name":"Shelly Plug S 040B47 Energy 0","stat_t":"~relay/0/energy","unit_of_meas":"kWh","dev_cla":"power","val_tpl":"{{ (value | float / 60 / 1000) | round(2) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyplug-s-040B47-relay-energy-0","qos":"0","dev": {"ids": ["4C11AE040B47"],"name":"Shelly Plug S 040B47","mdl":"Shelly Plug S","sw":"20190821-095311/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shellyplug-s-040B47/"}
homeassistant/sensor/shellyplug-s-040B47-temperature/config {"name":"Shelly Plug S 040B47 Temperature","stat_t":"~temperature","unit_of_meas":"°C","dev_cla":"temperature","val_tpl":"{{ value | float | round(1) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyplug-s-040B47-temperature","qos":"0","dev": {"ids": ["4C11AE040B47"],"name":"Shelly Plug S 040B47","mdl":"Shelly Plug S","sw":"20190821-095311/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shellyplug-s-040B47/"}
homeassistant/binary_sensor/shellyplug-s-040B47-overtemperature/config {"name":"Shelly Plug S 040B47 Overtemperature","stat_t":"~overtemperature","pl_on":"1","pl_off":"0","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","dev_cla":"heat","uniq_id":"shellyplug-s-040B47-overtemperature","qos":"0","dev": {"ids": ["4C11AE040B47"],"name":"Shelly Plug S 040B47","mdl":"Shelly Plug S","sw":"20190821-095311/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shellyplug-s-040B47/"}
shellies/shelly4pro-F61717/online true
shellies/announce {"id":"shelly4pro-F61717","mac":"780473F61717","ip":"192.168.3.115","new_fw":false, "fw_ver":"20190821-095050/v1.5.2@4148d2b7"}
homeassistant/switch/shelly4pro-F61717-relay-0/config {"name":"Shelly4Pro F61717 Relay 0","cmd_t":"~relay/0/command","stat_t":"~relay/0","pl_off":"off","pl_on":"on","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-0","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/light/shelly4pro-F61717-relay-0/config (null)
homeassistant/fan/shelly4pro-F61717-relay-0/config (null)
homeassistant/sensor/shelly4pro-F61717-power-0/config {"name":"Shelly4Pro F61717 Power 0","stat_t":"~relay/0/power","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{ value | float | round(1) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-power-0","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/sensor/shelly4pro-F61717-energy-0/config {"name":"Shelly4Pro F61717 Energy 0","stat_t":"~relay/0/energy","unit_of_meas":"kWh","dev_cla":"power","val_tpl":"{{ (value | float / 60 / 1000) | round(2) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-energy-0","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/switch/shelly4pro-F61717-relay-1/config {"name":"Shelly4Pro F61717 Relay 1","cmd_t":"~relay/1/command","stat_t":"~relay/1","pl_off":"off","pl_on":"on","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-1","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/light/shelly4pro-F61717-relay-1/config (null)
homeassistant/fan/shelly4pro-F61717-relay-1/config (null)
homeassistant/sensor/shelly4pro-F61717-power-1/config {"name":"Shelly4Pro F61717 Power 1","stat_t":"~relay/1/power","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{ value | float | round(1) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-power-1","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/sensor/shelly4pro-F61717-energy-1/config {"name":"Shelly4Pro F61717 Energy 1","stat_t":"~relay/1/energy","unit_of_meas":"kWh","dev_cla":"power","val_tpl":"{{ (value | float / 60 / 1000) | round(2) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-energy-1","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/switch/shelly4pro-F61717-relay-2/config {"name":"Shelly4Pro F61717 Relay 2","cmd_t":"~relay/2/command","stat_t":"~relay/2","pl_off":"off","pl_on":"on","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-2","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/light/shelly4pro-F61717-relay-2/config (null)
homeassistant/fan/shelly4pro-F61717-relay-2/config (null)
homeassistant/sensor/shelly4pro-F61717-power-2/config {"name":"Shelly4Pro F61717 Power 2","stat_t":"~relay/2/power","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{ value | float | round(1) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-power-2","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/sensor/shelly4pro-F61717-energy-2/config {"name":"Shelly4Pro F61717 Energy 2","stat_t":"~relay/2/energy","unit_of_meas":"kWh","dev_cla":"power","val_tpl":"{{ (value | float / 60 / 1000) | round(2) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-energy-2","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/switch/shelly4pro-F61717-relay-3/config {"name":"Shelly4Pro F61717 Relay 3","cmd_t":"~relay/3/command","stat_t":"~relay/3","pl_off":"off","pl_on":"on","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-3","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/light/shelly4pro-F61717-relay-3/config (null)
homeassistant/fan/shelly4pro-F61717-relay-3/config (null)
homeassistant/sensor/shelly4pro-F61717-power/config (null)
homeassistant/sensor/shelly4pro-F61717-energy/config (null)
homeassistant/sensor/shelly4pro-F61717-power-3/config {"name":"Shelly4Pro F61717 Power 3","stat_t":"~relay/3/power","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{ value | float | round(1) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-power-3","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}
homeassistant/sensor/shelly4pro-F61717-energy-3/config {"name":"Shelly4Pro F61717 Energy 3","stat_t":"~relay/3/energy","unit_of_meas":"kWh","dev_cla":"power","val_tpl":"{{ (value | float / 60 / 1000) | round(2) }}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shelly4pro-F61717-relay-energy-3","qos":"0","dev": {"ids": ["780473F61717"],"name":"Shelly4Pro F61717","mdl":"Shelly4Pro","sw":"20190821-095050/v1.5.2@4148d2b7","mf":"Allterco Robotics"},"~":"shellies/shelly4pro-F61717/"}

There is nothing after “Shellies Discovery” triggered.

Script works so I don’t understand what is the problem.

Thank you for your responses.
I’ve installed new docker with home assistant (and clean config directory) and it discovered new devices even without python scripts for auto discovery installed.

I’ll try to find what is wrong with my old installation

I found my stupid error!

  1. I do not need to manually start “Shellies Discovery” automation! It is called my MQTT when I trigger “Shellies announce” automation.

  2. I had discovery disabled for MQTT. I had to add “discovery: true” to configuration.yaml (it is false by default)

@Bieniu Thank you for your help

1 Like

Always read the documentation https://github.com/bieniu/ha-shellies-discovery#troubleshooting-checklist

New version: 0.13.0

Changelog:

  • add support for Shelly Dimmer
  • remove color variables from Shelly RGBW2 in white mode

I just got this working and it discovered all my Shelly devices.
Is there a way to extract the configuration from the entities so I can add them manually if I wanted to?

You can check configuration topics on MQTT broker. You have to search topics like this: homeassistant/light/shelly1-328900-relay-0/config. Payload of this topic contains configuration for this light.

1 Like

New version: 0.13.1

Changelog:

  • add loaderror and overload for Shelly Dimmer
  • remove temp_unit argument BREAKING CHANGE