]> git.giorgioravera.it Git - homeassistant.git/commitdiff
Updated shelly scripts
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Tue, 23 May 2023 02:18:14 +0000 (04:18 +0200)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Tue, 23 May 2023 02:18:14 +0000 (04:18 +0200)
packages/shelly/shelly_operations.yaml

index 0d34129c0159cea9a854e819b59dad0b22816024..b6b942ac3df6c108837975fb9c6778f77cf21968 100644 (file)
@@ -8,17 +8,24 @@ script:
   ######################################################################
   shelly_upgrade:
     alias: "Shelly: Aggiornamento Firmware Collettivo"
+    variables:
+      pending_update_list: >
+        {{ states.update
+          | selectattr('state','eq','on')
+          | selectattr('entity_id', 'in', states.group.shelly.attributes.entity_id)
+          | map(attribute='entity_id')
+          | list
+        }}
     sequence:
-      - service: mqtt.publish
-        data:
-          topic: 'shellies/command'
-          payload: 'update_fw'
-          qos: 0
-          retain: false
-    #  - service: update.install
-    #    target:
-    #      entity_id:
-    #        - group.shelly
+    #  - service: mqtt.publish
+    #    data:
+    #      topic: 'shellies/command'
+    #      payload: 'update_fw'
+    #      qos: 0
+    #      retain: false
+      - service: update.install
+        target:
+          entity_id: '{{ pending_update_list }}'
 
   ######################################################################
   # Shelly: Reboot
@@ -44,7 +51,14 @@ automation:
   # Shelly: Update Notification
   ######################################################################
   - alias: "Shelly: Update Notification"
-
+    variables:
+      pending_update_list: >
+        {{ states.update
+          | selectattr('state','eq','on')
+          | selectattr('entity_id', 'in', states.group.shelly.attributes.entity_id)
+          | map(attribute='entity_id')
+          | list
+        }}
     trigger:
       - platform: state
         entity_id: group.shelly
@@ -63,11 +77,9 @@ automation:
         data_template:
           title: "Shelly - Aggiornamento"
           message: >
-            Sono disponibili aggiornamenti per i dispositivi Shelly:
-            {%- for entity_id in states.group.shelly.attributes.entity_id -%}
-              {% if is_state(entity_id, 'on') %}
+            Sono disponibili {{pending_update_list | count }} aggiornamenti per i dispositivi Shelly:
+            {% for entity_id in pending_update_list %}
                 -> {{ state_attr(entity_id, 'friendly_name')|replace(" - Aggiornamento Firmware", "") }}: {{ state_attr(entity_id, 'latest_version') }}
-              {%- endif -%}
             {%- endfor -%}
           notification_id: "update"
           enable_persistent: true