And my automation on Home Assistant startup:
# Shellies Announce
- id: '010'
alias: Shellies Announce
trigger:
- platform: homeassistant
event: start
- platform: time_pattern
hours: "/12" # Modifying this if you are using Shelly Motion can drain your device's battery quickly.
action:
service: mqtt.publish
data:
topic: shellies/command
payload: announce
mode: single
# Shellies Discovery
- id: '011'
alias: Shellies Discovery
max: 999
trigger:
platform: mqtt
topic: shellies/announce
action:
service: python_script.shellies_discovery
data:
id: '{{ trigger.payload_json.id }}'
mac: '{{ trigger.payload_json.mac }}'
fw_ver: '{{ trigger.payload_json.fw_ver }}'
model: '{{ trigger.payload_json.model }}'
mode: '{{ trigger.payload_json.mode | default }}'
host: '{{ trigger.payload_json.ip }}'
mode: queued
- id: '014'
alias: Shellies Announce Gen2
trigger:
- platform: homeassistant
event: start
variables:
device_info_payload: "{{ {'id': 1, 'src':'shellies_discovery', 'method':'Shelly.GetConfig'} | to_json }}"
action:
- service: mqtt.publish
data:
topic: "shellypro4pm-kabinet/rpc" # shellypro4pm-aabbccddeeff is a device ID
payload: "{{ device_info_payload }}"
- id: '015'
alias: "Shellies Discovery Gen2"
mode: queued
max: 999
trigger:
- platform: mqtt
topic: shellies_discovery/rpc
action:
- service: python_script.shellies_discovery_gen2
data:
id: "{{ trigger.payload_json.src }}"
device_config: "{{ trigger.payload_json.result }}"
- id: '016'
alias: "Shellies Status Gen2"
trigger:
- platform: time_pattern
minutes: "/15"
- platform: homeassistant
event: start
action:
- service: mqtt.publish
data:
topic: shellypro4pm-kabinet/rpc
payload: "{{ {'id': 1, 'src':'shellypro4pm-kabinet/status', 'method':'Shelly.GetStatus'} | to_json }}" # shellypro4pm-aabbccddeeff is a device ID