was very amazed, that HA now supports updating Shellies directly. What i’d like to do now is to create a script (to e.g. use in an automation) that updates all shellies (and WLED devices) at once. What i’m trying to do is create a data template, look for all button-entities and filter those whose devices class is “update”. These devices entity-id should be then put one after into a service call.
What i have so far:
alias: ShellyUpdate-Testscript
sequence:
- service: button.press
data_template:
entity_id: >
{%- for shellyupdate in states.button -%}
{%- if state_attr(shellyupdate.entity_id,'device_class') == 'update' -%}
- {{ shellyupdate.entity_id +"\n"}}
{%- endif -%}
{%- endfor -%}
mode: single
of course, i did the coding of the loop in the developer tools, there it works as expected:
I don’t have any buttons, so I can’t test it fully, but I believe the tiny detail is that your YAML should look a little different. Specifically, data_template should be replaced with target.
Also, a couple notes on the template: entity_id accepts any form of a list object and, personally, I prefer the existing filters over Jinja logic.
Huh, all of my templates in the template editor just broke with similar errors… They all worked yesterday, I swear! I only have one template in my editor, and I know it was working yesterday, and today it is giving me TypeError: unhashable type: 'TemplateState'.
I’m at a bit of a loss. I can’t find any info related to this and all I did in that time was update the HA OS. I didn’t see any changes in the release notes related to the template editor, and I don’t think the OS would affect that anyway. Hopefully someone comes along who knows what happened.
After i have played around with it a little bit more yesterday, this is my working code now for the script.
service: button.press
target:
entity_id: >
{% for state in states.button %} {% if 'update' in state.entity_id %} {{
state.entity_id }} {% if not loop.last %}, {% endif %} {% endif %} {% endfor
%}
@tom_l that also looks interesting, although it requires a lovelace plugin. but: a good starting point to now put this script into some automation, do auto-updates every week or show a button (which triggers al updates) once an update is available
Doesn’t really matter now, but I just got around to “fixing” my template editor and could figure out why you saw that error: a simple typo it should be attributes, not attribute.
I am 100% sure this template works, copied directly from my template editor:
Now that both entities; firmware_update and OTA_update are deprecated and they’ve been replaced with update.entity_id_firmware_update (which is one of the hidden entities in the top pane now shown with a Shelly icon), is there an update to the scrip above that would still work to update all?
Is there a way to filter only for shelly devices? When I run your script i get an error that “fritz_box_update_…” is not a valid id and i tried a “and not “fritz” in state.entity_id” filter but that doesnt work for me.
I played with the service call and if you don’t want to autoupdate but you would decide when you would install the updates for all your shelly devices it worked for me:
service: update.install
target:
entity_id: >
{%- for shellyupdate in states.update -%}
{%- if state_attr(shellyupdate.entity_id, 'device_class') == 'firmware' -%}
{%- set release_url = state_attr(shellyupdate.entity_id, 'release_url') -%}
{%- if release_url is not none and 'shelly' in release_url and is_state(shellyupdate.entity_id, 'on') -%}
{{ "\n" + " - " + shellyupdate.entity_id }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}