From 7a66abc5e34cc9edb2383fad941a301c27a3239f Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Fri, 5 May 2023 21:02:54 +0200 Subject: [PATCH] Moved update notification in shelly package & created automation to force state update on startup --- .storage/lovelace.lovelace_dispositivi | 11 ++- automations/update_notifications.yaml | 37 ---------- input_boolean/update.yaml | 6 +- packages/shelly/shelly_customizations.yaml | 2 + packages/shelly/shelly_operations.yaml | 78 +++++++++++++++++++--- 5 files changed, 82 insertions(+), 52 deletions(-) diff --git a/.storage/lovelace.lovelace_dispositivi b/.storage/lovelace.lovelace_dispositivi index 7da0d274..2b80fad5 100644 --- a/.storage/lovelace.lovelace_dispositivi +++ b/.storage/lovelace.lovelace_dispositivi @@ -2219,7 +2219,6 @@ "type": "tile", "entity": "script.shelly_upgrade", "name": "Aggiorna Tutto", - "icon": "mdi:package-up", "tap_action": { "action": "call-service", "service": "script.shelly_upgrade" @@ -2229,11 +2228,19 @@ "type": "tile", "entity": "script.shelly_reboot", "name": "Riavvia tutto", - "icon": "mdi:restart", "tap_action": { "action": "call-service", "service": "script.shelly_reboot" } + }, + { + "type": "tile", + "entity": "script.shelly_force_state_update", + "name": "Aggiorna Stato Dispositivi", + "tap_action": { + "action": "call-service", + "service": "script.shelly_force_state_update" + } } ] } diff --git a/automations/update_notifications.yaml b/automations/update_notifications.yaml index 7c666687..2b7c380c 100644 --- a/automations/update_notifications.yaml +++ b/automations/update_notifications.yaml @@ -1,40 +1,3 @@ -###################################################################### -# Update Notification: Shelly -###################################################################### - -- alias: "Update Notification: Shelly" - - trigger: - - platform: state - entity_id: group.shelly - to: 'on' - - - platform: homeassistant - event: start - - condition: - condition: state - entity_id: group.shelly - state: 'on' - - action: - - delay: '00:00:10' - - service: script.notify_text - 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') %} - -> {{ state_attr(entity_id, 'friendly_name')|replace(" - Aggiornamento Firmware", "") }}: {{ state_attr(entity_id, 'latest_version') }} - {%- endif -%} - {%- endfor -%} - notification_id: "update" - enable_persistent: true - - - service: input_boolean.turn_on - entity_id: input_boolean.update_shelly - ###################################################################### # Update Notification: HACS ###################################################################### diff --git a/input_boolean/update.yaml b/input_boolean/update.yaml index 369af54e..756ae2d4 100644 --- a/input_boolean/update.yaml +++ b/input_boolean/update.yaml @@ -1,5 +1,5 @@ ###################################################################### -# Update: Home Assistant +# Update: Home Assistant ###################################################################### update_homeassistant: @@ -8,7 +8,7 @@ update_homeassistant: icon: mdi:cellphone-arrow-down ###################################################################### -# Update: Shelly +# Update: Shelly ###################################################################### update_shelly: @@ -17,7 +17,7 @@ update_shelly: icon: mdi:cellphone-arrow-down ###################################################################### -# Update: HACS +# Update: HACS ###################################################################### update_hacs: diff --git a/packages/shelly/shelly_customizations.yaml b/packages/shelly/shelly_customizations.yaml index fb467268..66e8571b 100644 --- a/packages/shelly/shelly_customizations.yaml +++ b/packages/shelly/shelly_customizations.yaml @@ -8,6 +8,8 @@ homeassistant: icon: mdi:package-up script.shelly_reboot: icon: mdi:restart + script.shelly_force_state_update: + icon: mdi:update # Shelly 1 - Tapparella Cucina (shellyswitch_55980f) sensor.tapparella_cucina_energy: diff --git a/packages/shelly/shelly_operations.yaml b/packages/shelly/shelly_operations.yaml index 0600e0cc..0d34129c 100644 --- a/packages/shelly/shelly_operations.yaml +++ b/packages/shelly/shelly_operations.yaml @@ -9,16 +9,16 @@ script: shelly_upgrade: alias: "Shelly: Aggiornamento Firmware Collettivo" 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: + # - group.shelly ###################################################################### # Shelly: Reboot @@ -28,6 +28,64 @@ script: sequence: - service: shell_command.shelly_reboot + ###################################################################### + # Shelly: Force State Update + ###################################################################### + shelly_force_state_update: + alias: "Shelly: Aggiornamento stato dispositivi" + sequence: + - service: mqtt.publish + data: + payload: update + topic: shellies/command + +automation: + ###################################################################### + # Shelly: Update Notification + ###################################################################### + - alias: "Shelly: Update Notification" + + trigger: + - platform: state + entity_id: group.shelly + to: 'on' + - platform: homeassistant + event: start + + condition: + condition: state + entity_id: group.shelly + state: 'on' + + action: + - delay: '00:00:10' + - service: script.notify_text + 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') %} + -> {{ state_attr(entity_id, 'friendly_name')|replace(" - Aggiornamento Firmware", "") }}: {{ state_attr(entity_id, 'latest_version') }} + {%- endif -%} + {%- endfor -%} + notification_id: "update" + enable_persistent: true + - service: input_boolean.turn_on + entity_id: input_boolean.update_shelly + + ###################################################################### + # Shelly: Force State Update at Startup + ###################################################################### + - alias: "Shelly - Startup: Aggiornamento stati" + + trigger: + - event: start + platform: homeassistant + + action: + service: script.shelly_force_state_update + ###################################################################### # Shelly Package - Operations Shell Command ###################################################################### -- 2.47.3