Shellies Discovery Script

New version: 0.8.7

Changelog:

  • Add some abbreviation topics to Shelly RGBW2 config topic

Please anyone with Shelly RGBW2 to check that everything works well.

New version: 0.8.8

Changelog:

  • Partialy remove abbreviation topics to Shelly RGBW2 config topic

Thanks for your component.
I am just using in the discovery automation:

data_template:
      id: '{{ trigger.payload_json.id }}'
      mac: '{{ trigger.payload_json.mac }}'
      fw_ver: '{{ trigger.payload_json.fw_ver }}'
      shelly1-XXXXXX-relay-0: 'light'

But my shelly1 is in any case in the switch group (switch.shelly1_XXXXXX_relay_0).
Is it correct?

If the letters are in the XXXXXX they should be upper case.

1 Like

Thanks.
It works nice!

New version: 0.8.9

Changelog:

  • lower case letters can be used in relays ID

New version: 0.8.10

Changelog:

  • Add abbreviation value for position_topic (HA 0.93 required)

New version: 0.9.0

Changelog:

  • Add support for Shelly Plug S

Could you add RGBW2 white mode?

RGBW2 white mode is on my “to-do” list.

New version: 0.9.1

Changelog:

  • Add support for white-mode for Shelly RGBW2
    shellyrgbw2-AABB22: 'white' - means that Shelly RGBW2 works in white-mode
    shellyrgbw2-CC2211: 'rgbw' - means that Shelly RGBW2 works in color-mode (default)
  • Change argument for Shelly2/Shelly2.5 roller mode [breaking change]
    shellyswitch-334455: 'cover' - means that Shelly2 works in roller mode and use
    cover component in Home Assistant
1 Like

Can you please advice what configuration settings I should add to automations.yaml to use Shelly 2.5 in roller mode?

I’ve tried: shellyswitch25-73C874: 'cover'
the Shelly is discovered however appears as Switch in HA and when I switch the relay id does nothing.
s6s5d65ip
Iam using your suggested template automations.yaml and Shelly 2.5 v1.4.9-shelly2.5-hotfix3

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

EDIT: I use your new version : 0.9.1

I tried a while ago and Shelly2.5 was added as a cover.
image
Your automation should look like this:

- 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-73C874: 'cover'

Did you restart HA? Sometimes you need two reboots or run twice an announce automation.

Yes, I’ve tried to restart and also remove Entity and run discovery again. But it does not help.
I also see some additional errors in the log related to power consumption

2019-05-18 20:52:30 ERROR

Summary

(MainThread) [homeassistant.components.mqtt.sensor] Exception in async_discover_sensor when dispatching ‘mqtt_discovery_new_sensor_mqtt’: ({‘name’: ‘Shelly2.5 73C874 Power 0’, ‘state_topic’: ‘shellies/shellyswitch25-73C874/relay/0/power’, ‘unit_of_measurement’: ‘W’, ‘device_class’: ‘power’, ‘value_template’: ‘{{ value | float | round(1) }}’, ‘availability_topic’: ‘shellies/shellyswitch25-73C874/online’, ‘payload_available’: ‘true’, ‘payload_not_available’: ‘false’, ‘unique_id’: ‘shellyswitch25-73C874-relay-power-0’, ‘device’: {‘identifiers’: [’######73C874’], ‘name’: ‘Shelly2.5 73C874’, ‘model’: ‘Shelly2.5’, ‘sw_version’: ‘20190416-151347/v1.4.9-shelly2.5-hotfix3@26ed6ef3’, ‘manufacturer’: ‘Shelly’}, ‘platform’: ‘mqtt’},)
Traceback (most recent call last):
File “/usr/src/app/homeassistant/helpers/config_validation.py”, line 658, in call
return super().call(data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 267, in call
return self._compiled([], data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 589, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 427, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: value is not allowed for dictionary value @ data[‘device_class’]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/app/homeassistant/components/mqtt/sensor.py”, line 70, in async_discover_sensor
config = PLATFORM_SCHEMA(discovery_payload)
File “/usr/src/app/homeassistant/helpers/config_validation.py”, line 670, in call
validated = super().call(data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 267, in call
return self._compiled([], data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 589, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 427, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: value is not allowed for dictionary value @ data[‘device_class’]

2019-05-18 20:52:30 ERROR (MainThread) [homeassistant.components.mqtt.sensor] Exception in async_discover_sensor when dispatching ‘mqtt_discovery_new_sensor_mqtt’: ({‘name’: ‘Shelly2.5 73C874 Energy 0’, ‘state_topic’: ‘shellies/shellyswitch25-73C874/relay/0/energy’, ‘unit_of_measurement’: ‘kWh’, ‘device_class’: ‘power’, ‘value_template’: ‘{{ (value | float / 60 / 1000) | round(2) }}’, ‘availability_topic’: ‘shellies/shellyswitch25-73C874/online’, ‘payload_available’: ‘true’, ‘payload_not_available’: ‘false’, ‘unique_id’: ‘shellyswitch25-73C874-relay-energy-0’, ‘device’: {‘identifiers’: [‘807D3A73C874’], ‘name’: ‘Shelly2.5 73C874’, ‘model’: ‘Shelly2.5’, ‘sw_version’: ‘20190416-151347/v1.4.9-shelly2.5-hotfix3@26ed6ef3’, ‘manufacturer’: ‘Shelly’}, ‘platform’: ‘mqtt’},)
Traceback (most recent call last):
File “/usr/src/app/homeassistant/helpers/config_validation.py”, line 658, in call
return super().call(data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 267, in call
return self._compiled([], data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 589, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 427, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: value is not allowed for dictionary value @ data[‘device_class’]

Which version of Home Assistant do you use?

I am using HA 0.91.4

Hi,

@Bieniu - thanks very much for this, I’ve successfully autodiscovered 8 shelly 2.5s using your script which saved me a lot of head scratching. I have a query you may know the answer to.

When I toggle one switch on a 2.5, both are marked as unavailable in HA until the switch transition is completed. So automations, e.g. turn on all kitchen lights, will fail sometimes on one relay, unless I add a delay between turning on relays in the same shelly.

Have you observed this? Any idea if this is solvable by config in HA?

Thanks very much, appreciate your efforts.

I’ve found adding the switches on each relay manually in configuration.xml works fine:

light:
  - platform: mqtt
    name: "Kitchen spotlights"
    state_topic: "shellies/shellyswitch25-740B37/relay/1"
    command_topic: "shellies/shellyswitch25-740B37/relay/1/command"
    qos: 2
    payload_on: "on"
    payload_off: "off"
  - platform: mqtt
    name: "Kitchen island strip"
    state_topic: "shellies/shellyswitch25-5DBAD1/relay/0"
    command_topic: "shellies/shellyswitch25-5DBAD1/relay/0/command"
    qos: 2
    payload_on: "on"
    payload_off: "off"

Like this I can add all switches to a group, and use homeassistant.turn_off on the group and all entities respond consistently straight away, whereas with the autodiscovery script entities i had to add a delay between the switching off entities in in the same 2.5. All good for me with manual config, just thought you’d want to know.

Cheers.

Script requires HA 0.93. You have to update HA or use version 0.8.1 of the script.

I had this issue when I updated Mosquitto to 1.6.x and I don’t know what is the reason of the issue. With Mosquitto 1.5.x there is no issue.