Yes, just use custom MQTT prefix in the script configuration.
Thanks. Tested before will test again, suspect I did something else wrong.
I’ve been following this thread trying to double-check my setup, etc. I am still unable to add one Shelly Plus H&T to Home Assistant. I’ve attached my logs and my configuration. I’ve enabled logging for the script, and I am getting a “Template variable warning: ‘dict object’ has no attribute ‘result’ when rendering ‘{{ trigger.payload_json.result }}’”
I’ve seen where you cannot execute the automation manually (I think), so I’ve restarted Home Assistant twice. I’ve also executed the Announce Automation twice manually after waking up the device.
I’ve also tried adding MQTT support on a ShelluPlugUS to see if the process I am using works on another device, but it says it is not supported.
Any help would be greatly appreciated.
Home Assistant 2023.2.5
Supervisor 2023.01.1
Operating System 9.5
Frontend 20130202.0
Config:
- 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: # enter the list of device IDs (MQTT prefixes) here
- shellyplusht-c049ef8adf34
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/shellyplusht-office/events/rpc
action:
- service: python_script.shellies_discovery_gen2
data:
id: "{{ trigger.payload_json.src }}"
device_config: "{{ trigger.payload_json.result }}"[Processing: scriptlog.txt...]()
Log:
2023-02-17 10:59:42.282 INFO (MainThread) [homeassistant.components.automation.shellies_announce_gen2] Shellies Announce Gen2: Running automation actions
2023-02-17 10:59:42.282 INFO (MainThread) [homeassistant.components.automation.shellies_announce_gen2] Shellies Announce Gen2: Repeating sequence: Iteration 1 of 1 with item: ‘shellyplusht-c049ef8adf34’
2023-02-17 10:59:42.283 INFO (MainThread) [homeassistant.components.automation.shellies_announce_gen2] Initialized trigger Shellies Announce Gen2
2023-02-17 10:59:42.301 INFO (MainThread) [homeassistant.components.automation.shellies_announce_gen2] Shellies Announce Gen2: Repeat at step 1: Running automation actions
2023-02-17 10:59:42.301 INFO (MainThread) [homeassistant.components.automation.shellies_announce_gen2] Shellies Announce Gen2: Repeat at step 1: Executing step call service
2023-02-17 10:59:42.798 INFO (MainThread) [homeassistant.components.automation.shellies_discovery_gen2] Initialized trigger Shellies Discovery Gen2
2023-02-17 11:01:11.727 DEBUG (MainThread) [homeassistant.components.automation.shellies_discovery_gen2] Automation trigger ‘None’ triggered by mqtt topic shellies/shellyplusht-office/events/rpc
2023-02-17 11:01:11.735 INFO (MainThread) [homeassistant.components.automation.shellies_discovery_gen2] Shellies Discovery Gen2: Running automation actions
2023-02-17 11:01:11.735 INFO (MainThread) [homeassistant.components.automation.shellies_discovery_gen2] Shellies Discovery Gen2: Executing step call service
2023-02-17 11:01:11.736 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: ‘dict object’ has no attribute ‘result’ when rendering ‘{{ trigger.payload_json.result }}’
2023-02-17 11:01:11.823 INFO (SyncWorker_2) [homeassistant.components.python_script] Executing shellies_discovery_gen2.py: {‘id’: ‘shellyplusht-c049ef8adf34’, ‘device_config’: ‘’}
2023-02-17 11:01:11.824 ERROR (SyncWorker_2) [homeassistant.components.python_script.shellies_discovery_gen2.py] Error executing script: string indices must be integers
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/python_script/init.py”, line 224, in execute
exec(compiled.code, restricted_globals)
File “shellies_discovery_gen2.py”, line 1933, in
File “/usr/local/lib/python3.10/site-packages/RestrictedPython/Eval.py”, line 28, in default_guarded_getitem
return ob[index]
TypeError: string indices must be integers
What’s that?
And that?
Plug US or Plug Plus US?
Thank you so much for the help. I think I messed up the copy and paste into the forum for the first issue. I just looked at the config and see this line device_config: '{{ trigger.payload_json.result }}'
For the second issue, I was checking the topics being published from the device in MQTT Explorer (I am new to this), and I thought that was the topic that would trigger the process. I assume the topic in the automation should be “shellies_discovery/rpc”
I have a “Shelly Plus Plug US” for the last issue. I was using the plug device to see if I could get this working as I don’t have to wake up the device all the time.
Jim
Shelly Plus Plug US has been supported for a long time.
If you still need help please open an issue here Issues · bieniu/ha-shellies-discovery-gen2 · GitHub
Hi all,
I have installed the script for testing purpose on my HA. It works for my shelly plus 2pm. First I was thinking about to implement the Shelly-Devices from scatch without using the script, but it is a lot of work and it looks not so nice.
But I did not find the file whre I can find the mqtt configuration of the shelly. For my other mqtt devices I have separte files for sensors, switches and cover but were can I find the auto-discovery devices?
Thx,
Spartacus
What file? YAML?
Hi,
yes. If I configure a mqtt device without the script, the configuration is in the xxx.yaml and looks like this example:
mqtt:
sensor: !include_dir_merge_list ../entities/mqtt/sensor
binary_sensor: !include_dir_merge_list ../entities/mqtt/binary_sensor
switch: !include_dir_merge_list ../entities/mqtt/switch
cover: !include_dir_merge_list ../entities/mqtt/cover
and the code:
- unique_id: rollo_schlafen
name: "Rollo Schlafen"
availability:
topic: "rollo.schlafzimmer/online"
payload_available: "true"
state_topic: "rollo.schlafzimmer/status/cover:0"
value_template: "{{ value_json.state }}"
state_open: "open"
state_closed: "close"
position_topic: "rollo.schlafzimmer/status/cover:0"
position_template: "{{ value_json.current_pos | int }}"
position_open: 100
position_closed: 0
command_topic: "rollo.schlafzimmer/rpc"
payload_open: '{"id":0,"src":"admin","method":"Cover.Open","params":{"id":0}}'
payload_close: '{"id":0,"src":"admin","method":"Cover.Close","params":{"id":0}}'
# qos: 1
retain: false
It seems to be that auto discovery will use different files to build the device specific configuration. So it would be nice, if it is possible to modify the device configuration once it is auto-discovered.
But not sure, if this is possible…
Spartacus
Auto-discovery is, as the name suggests, automatic device discovery and configuration is not stored in any file available to the user and cannot be edited by the user.
Hello again,
ok, I understnd. I have setup the script on my test ebvironment with the Shelly Plus 2Pm as a cover. It worked so far, but I miss some sensor values (grey)
I get all values when I configure it like sensors in HA. Is this currently not supported by the discovery?
They are disabled by default, you need to enable the ones you need.
Hi ,
thank you very much for your support. It works and I will discover all values! Very cool integration…
One question:
I installed the python script on my test environment and also the automations. The shelly was auto discovered. I also noticed, that it was also autodiscovered on my prod environment without having the python script and the automations. Does it mean that I can use the auto discovery for new devices on the test env. and after the script was copied to the shelly it will also run in the prod?
Spartacus
The script creates the configuration and sends it to the MQTT broker. Every HA instance that use this MQTT broker will get configured device.
Great script, however i don’t think it finds all entities for my shelly smoke plus, if i poll the mqtt publishes manually i get alot more entites.
Manual silence is “unavailable” and if i manually test trigger the smoke alarm i get a mqtt trigger however the entity still says “clear”, any ides?
Entities, entities everywhere What do you mean?
The alarm mute button will be available when the alarm is active.
Maybe its working correctly afterall in that case.
These are the entities it finds.
Battery
Firmware
Mute
Smoke
Last update was the last time i pressed the setup button, 17 hours ago, any ides how often it sends data on it’s own?
Yes, same exact entities i have i think, my polish (?) isn’t that great.
10 in total together with the diagnostics.
Thanks!
So what is missing?