Shellies Discovery Script

I don’t know. Show me your MQTT broker, script and Shelly configuration.

Thanks for your help Maciek, hope this info will help

log form MQTT

Log
[16:25:01] INFO: Setup mosquitto configuration
[16:25:01] WARNING: SSL not enabled - No valid certs found!
[16:25:01] INFO: No local user available
[16:25:01] INFO: Initialize Hass.io Add-on services
[16:25:02] INFO: Initialize Home Assistant discovery
[16:25:02] INFO: Start Mosquitto daemon
1570717502: mosquitto version 1.6.3 starting
1570717502: Config loaded from /etc/mosquitto.conf.
1570717502: Loading plugin: /usr/share/mosquitto/auth-plug.so
1570717502: |-- *** auth-plug: startup
1570717502: ├── Username/password checking enabled.
1570717502: ├── TLS-PSK checking enabled.
1570717502: └── Extended authentication not enabled.
1570717502: Opening ipv4 listen socket on port 1883.
1570717502: Opening ipv6 listen socket on port 1883.
1570717502: Opening websockets listen socket on port 1884.
1570717502: Warning: Mosquitto should not be run as root/administrator.
1570717556: New connection from 172.30.32.1 on port 1883.
[INFO] found homeassistant on local database
1570717556: New client connected from 172.30.32.1 as auto-077A18D0-B00C-3583-4B3B-A3122E477AD9 (p2, c1, k60, u’homeassistant’).
1570719333: Saving in-memory database to /data/mosquitto.db.
1570719556: Client auto-077A18D0-B00C-3583-4B3B-A3122E477AD9 disconnected.
1570719575: New connection from 172.30.32.1 on port 1883.
[INFO] found homeassistant on local database
1570719575: New client connected from 172.30.32.1 as auto-95D77C08-7F1D-FB1F-34BA-04996D298800 (p2, c1, k60, u’homeassistant’).

############################
from /config/automations.yaml (identical to your spec’s)

  • 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 }}’

####################################
from /config/configuration.yaml

python_script:

####################################
in /config/python_scripts a copie off shellies_discovery.py

Is Shelly’s topic configuration default? What is your discovery_prefix in MQTT broker configuration?

from MQTT Mosquitto broker addon

{
“logins”: [],
“anonymous”: true,
“customize”: {
“active”: false,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”,
“require_certificate”: false
}

can you tell me where tot find the Shelly topic configuration :blush:

On device website: http://ip_address/

Do you mean the ip address of the shelly device. Yes that is default … it works okay (switch on/off a lamp I have configured for testing) with the Shelly app on my tablet. And I can see the device when check the connected devices on the router.

Announce and discovery automations are enabled in HA?
Show me mqtt topics log after run announce automation.

de logging van MQTT broker - after clicking announce en discovery automations a few time logging is
Log

1570728338: Saving in-memory database to /data/mosquitto.db. 1570730139: Saving in-memory database to /data/mosquitto.db. 1570731940: Saving in-memory database to /data/mosquitto.db. 1570733741: Saving in-memory database to /data/mosquitto.db. 1570735542: Saving in-memory database to /data/mosquitto.db.

or is there another place to check for logging info?

You need mosquitto_sub or MQTT Explorer to make topics log.

Good news! problem solved!!!

after re-checking the shelly device by IP address (idea Maciek; thanks for that!) I noticed that under advance developer settings the option “enable action execution via MQTT” was not checked. After checking this and starting discovery / announce on HASSIO, switch was known as integration / Mosquitto broker.

THANKS MACIEK!!

1 Like

If anyone using Shelly RGBW2 can tests this version of the script? Mostly light effects.

New version: 0.12.4

Changelog:

  • change names of effects for Shelly RGBW2

Hi @Bieniu,

Nice work. I do have a Shelly RGBW2 among other Shelly devices and I followed your script evolution over time.
Good addition for effect names instead of numbers, however I would like to inform you that Shelly documentation is a little bit inacurate (not a surprise :wink:) regarding the available effects for Shelly RGBW2. On the device’s web interface we only have Off, Meteor Shower, Gradual Change and Flash (in this order).
Using your script makes the led string behave like Meteor Shower for the rest of the effects, including script’s Flash effect.
Therefore, for the script version 0.12.4, I propose to change line 759 from

'"fx_list":["Off", "Meteor Shower", "Gradual Change", "Breath", "Flash", "On/Off Gradual", "Red/Green Change"],'

to

'"fx_list":["Off", "Meteor Shower", "Gradual Change", "Flash"],'

and line 768 from

'"fx_tpl":"{% if value_json.effect == 1 %}Meteor Shower{% elif value_json.effect == 2 %}Gradual Change{% elif value_json.effect == 3 %}Breath{% elif value_json.effect == 4 %}Flash{% elif value_json.effect == 5 %}On/Off Gradual{% elif value_json.effect == 6 %}Red/Green Change{% else %}Off{% endif %}",'

to

'"fx_tpl":"{% if value_json.effect == 1 %}Meteor Shower{% elif value_json.effect == 2 %}Gradual Change{% elif value_json.effect == 3 %}Flash{% else %}Off{% endif %}",'.

For the same Shelly RGBW2 I also successfully use a separate MQTT sensor for power consumption and I think it would be nice to have it included in your script (much like overpower). I would do it myself but I’m a verry beginer regarding Python language.

Could you show me MQTT topic for power consumption sensor?

Sure.

sensor:
  - platform: mqtt
    name: Bed RGB String Power
    unique_id: shellyrgbw2-5A3A8A-power
    device_class: power
    icon: mdi:gauge
    state_topic: shellies/shellyrgbw2-5A3A8A/color/0/status
    unit_of_measurement: 'W'
    value_template: "{{ value_json.power }}"

See also this post in this thread:

Notice the parameter "power": 0? When I turn on the light this value changes to whatever the instant power consumption is. It increases if I increase the brightness and decreases if I decrease the brightness. It seems to update itself (my sensor) on a ~ 5 seconds delay interval.

Shelly Cloud did not took this into consideration when they report back the consumption history on their Android App (if you enable cloud, of course).

And I just noticed: in white mode you get power consumption reported for each of the white bulbs. :partying_face:

New version: 0.12.5

Changelog:

  • remove unused light effects for RGBW2
  • add power sensor for RGBW2

Thank you @Bieniu for your super fast fix.

I’ve tested the new version of shelly_discovery script and now I have the new power sensor in place.

Here’s what I did:
I have last version of Home Assistant (0.100.2) installed on a Raspberry Pi 3B with the following add-ons: Samba, SSH, Mosquitto broker (I know it’s deprecated) and HACS. I’ve made a snapshot here so it won’t be necessary to reinstall everything.
I have a Shelly RGBW2 and a RGB led string connected to it. Shelly was configured as White and the shelly_discovery.yaml automation script in auto mode (without specifying the shelly type as in shellyrgbw2-AABB22: 'white').
At this point, shelly_discovery script registered my device as one light, one overpower sensor and one power sensor.
I restored the snapshot and tried again but this time I added shellyrgbw2-AABB22: 'white' to the shelly_discovery.yaml automation script prior to the instalation of shelly_discovery script. Now it worked like a charm.
The bottom line is: we need to specify the shelly type in automation script prior to installation. Or maybe you can tune the discovery part of shelly_discovery script.

Thank you for your great work.

As a side note:
Although I have a RGB strip connected to a Shelly RGBW2, as I mentioned above, when I switch to White mode in their web interface I get power consumption on the fourth channel as well if I turn that channel on (remember: nothing connected to this channel). Weird or what. But this I will take it to the Shelly developers to sort it out.

You don’t have to make snapshots. When will you add shellyrgbw2-AABB22: 'white' parameter the script will remove from MQTT broker config topics for color entities. After restart HA these entities dissapear from Integrations.

The value of mode in status topic is changing to white when you change to “White mode”?

Could you show me status topic and its payload when you have enabled “White mode”?

If someone wants to help put pressure on Shelly developers to update the documentation this is the right place :wink: