Shellies Discovery Gen2 Script

You need to press the button on the device to wake it up.

U’re right! The device is not propertly configurated in mqtt, I’ve installed emqx add on and reconfigured the shelly h&t and now the device is showed in the entity. Thank you for the support

1 Like

Just another one question: if I press the button and the words “Set” showed on the screen, in the MQTT connection I can view the Shelly H&T, but when after a few minutes when the temperature appears, I lost the MQTT connection. Why?

Plus HT is a sleeping device, it doesn’t maintain WiFi connection. It wakes up from time to time, sends data and goes to sleep again.

Hi David,

Did you ever get a solution to your/this problem? I’m experiencing the same behaviour.

Kind regards

Hi,

Yes I have. Before the issue, I upgraded Hass from a pretty old version.
In the MQTT broker, I guess some old discovery info was retained by the broker.
I used MQTT Explorer to connect to the broker and manually removed all data from the affected Shellies:
Schermafbeelding 2024-06-24 151148

Topic that helped me: How to purge the retained MQTT messages?

  1. Which devices should be specifically specified in the device_ids section of the sheelies_announce_gen2 automation? Currently, I only specify 1PM devices and not i3 and dimmer, yet the dimmer and i3 are recognized by home assistant/MQTT and are operational
  2. two 1PM devices are listed by the MQTT integration but are not operational (grayed out). How can I activate them

All gen2/gen3 devices that you want to configure with Shellies Discovery Gen2. i3, dimmer and 1PM are gen1 devices.

The relays are “Plus 1PM” devices. I think they are gen2, but I’m not sure.
How can I find the generation of the device?
And in any case, the important issue is how to get the “plus 1pm” devices to be active in home assistant?

All Plus/Pro devices are gen2.

Something is probably configured incorrectly and configuration needs to be improved :man_shrugging:

I agree. can you please help me debug this issue or instruct me how to “start fresh” - what are the exact settings in the “plus 1pm” that are required to get it to work with MQTT, and what are the settings in your script/automations? (according to the documentation, other than adding them to the device_ids I don’t see anything else that has to be done)

There is no extra/hidden/secret settings. All needed settings are described in the docs.
You need to show us your Shellies Discovery Gen2 automations, MQTT configuration for devices and a debug log.

log file

gen discovery and announce automation:

- id: shellies_announce_gen2
  alias: Shellies Announce Gen2
  trigger:
  - platform: homeassistant
    event: start
  variables:
    device_info_payload: '{{ {''id'': 1, ''src'':''shellies_discovery'', ''method'':''Shelly.GetConfig''}
      | to_json }}'
    device_ids:
    - shellies/shellyplus1pm-80646fe5d2c8
    - shellies/shellyplus1pm-80646fe58f94
  action:
  - repeat:
      for_each: '{{ device_ids }}'
      sequence:
      - service: mqtt.publish
        data:
          topic: '{{ repeat.item }}/rpc'
          payload: '{{ device_info_payload }}'
- id: shellies_discovery_gen2
  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 }}'
  - service: mqtt.publish
    data:
      topic: '{{ trigger.payload_json.result.mqtt.topic_prefix }}/command'
      payload: status_update

MQTT settings for the “plus 1PM” devices:

Device IDs don’t match

thanks!
should I remove the “shellies/” prefix in the automation, or add it in the device’s settings?
and in any case, after the device IDs match, what else do I have to do to enable them in home assistant?
currently, I removed the “shellies/” prefix from the automation, and after rebooting home assistant and running the “discovery gen2” (twice), one of the devices is still not enabled
the setting of the enabled device:


the setting of the device that is not enabled:

the IDs in the automation:

    device_ids:
    - shellyplus1pm-80646fe5d2c8
    - shellyplus1pm-80646fe58f94

another thing which might help is the number of messages for the devices in MQTT explorer
image
you can see that the working device has many more topics and messages

It’s up to you.

It looks that the device is not connected to the MQTT broker. This one topic comes from announce automation, not from the device.

thanks so much!
I changed the MQTT prefix to “shellies/…”
the new device is now operational, but the older device which used to work doesn’t work now
I see in the list of MQTT devices in home assistant another device, a Shelly 1PM device, which I don’t have in my home (maybe, I had it in the past) and it does not show in MQTT explorer

Just remove it.

obraz

my local menu is slighlty different
image
instead of “Remove device from MQTT”, I see “Delete”
I can delete the extra device, but after restarting home assistant it back
btw, I don’t see this device in MQTT explorer

I also deleted the plus-1pm device that is not enabled in home assistant, it came back, along with the (ghost) 1PM device, and is still not enabled

This means that you need to manually delete configuration topics from MQTT broker.
All topics homeassistant/<PLATFORM>/<DEVICE_ID>/config should be removed where:
<PLATFORM> could be switch, light, sensor, binary_sensor, button, device_automation, update, event