Shellies Discovery Script

Hi Bieniu

I would like to implement some templates to customize my shelly sensors, for example I would like to add birth_message and will_message overrides to a door sensor. Normally this goes into the configurations file, where and how do i do this for shelly devices that are being dynamically created using your discovery script?

example:

birth_message:
topic: xxx/xxx
payload: ‘’
will_message:
topic: xxx/xxx
payload: ‘’

Sorry, this is not supported.

Is it possible to manually define a device in the configuration file and have the discovery script ignore that device ?

Yes https://github.com/bieniu/ha-shellies-discovery#script-arguments

Very cool project, saves a lot of time. I know because I found it just after I build a proper setup for the shellyswitch25 roller mode.

Keep up the spirit!

1 Like

As suggested by Maciek I crafted a template sensor for the current_position attribute of a cover. It will display the shutter icon as closed when it is still 15% open, because the window is then already fully covered, but still some light will shine in through the shutter. Replace 15 with 0 or remove that condition if you don’t want that feature.

Now my question @Bieniu: is it feasible that your script generates such sensor code for each cover, so that we don’t need to copy /paste this code for each shutter?

If not, is it alternatively possible to display the current_position attribute in Lovelace without crafting such template sensor?

sensor:
  - platform: template
    sensors:
      shelly_2_5_XYZ_position:
        friendly_name: "Shelly 2.5 XYZ Position"
        entity_id:
          - cover.shelly_2_5_XYZ_roller_0
        unit_of_measurement: "%"
        availability_template: >-
          {{ not is_state('cover.shelly_2_5_XYZ_roller_0', 'unavailable') }}
        value_template: >-
          {{ state_attr('cover.shelly_2_5_XYZ_roller_0', 'current_position') }}
        icon_template: >-
          {% if is_state('cover.shelly_2_5_XYZ_roller_0', 'unavailable') %}
            mdi:window-shutter-alert
          {% elif state_attr('cover.shelly_2_5_XYZ_roller_0', 'current_position') < 15 
              or is_state('cover.shelly_2_5_XYZ_roller_0', 'closed') %}
            mdi:window-shutter
          {% else %}
            mdi:window-shutter-open
          {% endif %}

Nope, such a sensor duplicates data from a different entity so it will not be added.

is it alternatively possible to display the current_position attribute in Lovelace without crafting such template sensor? how?

I don’t know.

I’m trying to use this script for some shelly 2.5 running in rolling shutter mode.
However, all of my 2.5 are discovered as relays via mqtt.
Do I have to set e.g a custom
shellyswitch25-334455AA:
mode: “roller”
for each of them ?
Is this some kind of api limitation from the shellys, that kinda defeats the autodiscovery thing a bit :confused:

Yes, please read the script documentation.

Hi, For Shelly Button1, I can’t get the off_delay to work. I have this added:

shellybutton1-D8xxxxxxxxxx:
  push_off_delay: true 

but it doesn’t seem to work. The binary sensor will stay on until I push a different amount of times. So I can single press as many times as I want but nothing will change until I double or triple press, and only then I can single press again.
Thank you

Fixed via https://github.com/bieniu/ha-shellies-discovery/releases/tag/0.25.7

Hi, i have a problem with my shelly flood sensors. after a certain time (maybe 20 hours), all my sensors get the status unknown, and after a certain time again all is fine and so on. I have check the WLAN, but that is greate and i cant find any problems. Any idea or is that normaly? Many Thanks and Regards Frank

Hi All,
and many thanks @Bieniu for your job.

I’m trying to integrate a news shelly1pm device.

What I have done

  • setting a mosquito broker on my server,
  • configuring shelly device two publish on that broker,
  • check that connexion is ok:
    On my server:
 mosquitto_sub -h localhost -t shellies/announce
{"id":"shelly1pm-A4CF12F3D0EF","mac":"A4CF12F3D0EF","ip":"192.168.1.64","new_fw":false, "fw_ver":"20200601-123334/v1.7.0@d7961837"}
  • install shellies discovery through HACS
  • modify configuration.yaml file with following lines
python_script:

logger:
  default: warning
  logs:
    homeassistant.components.python_script: debug
    homeassistant.components.automation: info

mqtt:
  broker: localhost
  • modify automation.yaml file

- 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 }}'
  • checking that mqtt integration seems ok in Configuration > Integration
    image

  • restart several time HA

  • restart shelly device and check HA logs

2020-07-22 20:57:28 DEBUG (SyncWorker_4) [homeassistant.components.python_script.shellies_discovery.py] Sending to MQTT broker: homeassistant/binary_sensor/shelly1pm-A4CF12F3D0EF-firmware-update/config {"name": "Shelly 1PM A4CF12F3D0EF Firmware Update", "stat_t": "~announce", "uniq_id": "shelly1pm-a4cf12f3d0ef-firmware-update", "qos": 2, "dev": {"ids": ["a4cf12f3d0ef"], "name": "Shelly 1PM A4CF12F3D0EF", "mdl": "Shelly 1PM", "sw": "20200601-123334/v1.7.0@d7961837", "mf": "Allterco Robotics"}, "~": "shellies/", "val_tpl": "{% if value_json.id == 'shelly1pm-A4CF12F3D0EF' and value_json.new_fw == true %}ON{% else %}OFF{% endif %}", "avty_t": "shellies/shelly1pm-A4CF12F3D0EF/online", "pl_avail": "true", "pl_not_avail": "false"}
2020-07-22 20:57:28 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for shelly which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-07-22 20:57:35 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Shellies Announce
2020-07-22 20:57:44 INFO (MainThread) [homeassistant.components.automation] Executing Shellies Announce
2020-07-22 20:57:44 INFO (MainThread) [homeassistant.components.automation] Shellies Announce: Running script
2020-07-22 20:57:44 INFO (MainThread) [homeassistant.components.automation] Shellies Announce: Executing step call service

Device is seen correctly, automation is started.

The fact is that I don’t know what to do now. No new device or entity appear in Configuration > integration > mqtt.

I must miss something, but what?

Discovery MQTT - Home Assistant

Entities belonging to battery powered devices use the flag expire_after: 43200. This means that after 12h without communication from the device, the entities become unknown. 12h is the default value of sleep_mode_period option for Shelly H&T and Shelly Flood. Check that your device also has set 12h set for this option.

You are right.
Thanks a lot

1 Like

Hi Bieniu,

many thanks for your assistant. All my 3 flood shellys have the following setting.
“sleep_mode”:{“period”:24,“unit”:“h”}

Is that a problem and how can i change this setting on my shelly. I cant find any information for this.

Many thanks :slight_smile:

This means that default value of sleep_mode_period option has changed in the firmware. You can change this option via REST:

curl http://<SHELLY_DEVICE_IP>/settings?sleep_mode_period=12

or

curl http://<LOGIN>:<PASSWORD>@<SHELLY_DEVICE_IP>/settings?sleep_mode_period=12

if you have defined login/password.