MQTT Automation to update all Shelly/Shellies to the latest firmware

Tags: #<Tag:0x00007f3266d2d800> #<Tag:0x00007f3266d2d6e8> #<Tag:0x00007f3266d2d5d0> #<Tag:0x00007f3266d2d490> #<Tag:0x00007f3266d2d3a0>

GitHub Gist: https://gist.github.com/CyanAutomation/909c44e133d3b50193d59004049f8e84

If you have connected your Shelly devices to HA through MQTT, then this is a great automation to update all your connected Shellies to the latest firmware with one automation and command, simultaneously. It makes use of the update_fw command, as defined in the Shelly MQTT API. The automation allows you to select which day of the week is most convenient, as well as the time. Please note that during a firmware update, lights connected to Shellies may flash, and devices may lose power - this is due to how Shelly devices update themselves.

Day

This section allows you to select one or more days for the automation to run. For most people, checking for updates weekly (selecting a single day), is sufficient. The structure of this section was inspired by a blueprint created by delphiki.

Scheduled Update Time

Here allows the user to select the time of day for the automation to trigger. Please note than this is in 12-hour format, and you will need to select AM or PM.

Prerequisites

Devices need to be defined in Home Assistant via MQTT; this will not work if defined using the standard Shelly integration, or CoAP.

Blueprint

blueprint:
  # Please note that during a firmware update, lights connected to Shellies may flash, and devices may lose power
  name: Update Shelly Device Firmware via MQTT for all connected devices
  description: Use MQTT to update all connected Shellies to the latest firmware. Please select the day you want the automation to check for new firmware updates.
  domain: automation
  input:
    # Create a variable to capture the intended day for the automation to run, inspired by delphiki (https://community.home-assistant.io/u/delphiki)
    monday_enabled:
      name: Monday
      default: false
      selector:
        boolean:
    tuesday_enabled:
      name: Tuesday
      default: false
      selector:
        boolean:
    wednesday_enabled:
      name: Wednesday
      default: false
      selector:
        boolean:
    thursday_enabled:
      name: Thursday
      default: false
      selector:
        boolean:
    friday_enabled:
      name: Friday
      default: false
      selector:
        boolean:
    saturday_enabled:
      name: Saturday
      default: false
      selector:
        boolean:
    sunday_enabled:
      name: Sunday
      default: false
      selector:
        boolean:
    # Create a variable to capture the desired time for the automation to run
    scheduled_time:
      name: Scheduled Update Time
      description: Choose the time of the day to run the firmware update. Note than this is in 12-hour format, and you will need to select AM or PM.
      default: "11:00"
      # Use a selector, to pick the desired time
      selector:
        time: {}

# Prevent the automation from running concurrently
mode: single

# Define the variables used in the Action section
variables:
  current_day: "{{ now().weekday() | int }}"
  monday_enabled: !input monday_enabled
  tuesday_enabled: !input tuesday_enabled
  wednesday_enabled: !input wednesday_enabled
  thursday_enabled: !input thursday_enabled
  friday_enabled: !input friday_enabled
  saturday_enabled: !input saturday_enabled
  sunday_enabled: !input sunday_enabled

# Define the trigger for the automation
trigger:
  # Using time as the condition here, checking that the current time matches the capture desired/scheduled time for the update
  platform: time
  at: !input scheduled_time

# Use an OR condition table to check against the selected day; this was inspired by a blueprint created by delphiki (https://community.home-assistant.io/u/delphiki)
condition:
 # Use on OR structure to check if current day matches any of the selected days
 condition: or
 conditions: 
 - condition: template
   value_template: "{{ (current_day == 0 and monday_enabled) }}"
 - condition: template
   value_template: "{{ (current_day == 1 and tuesday_enabled) }}" 
 - condition: template
   value_template: "{{ (current_day == 2 and wednesday_enabled) }}" 
 - condition: template
   value_template: "{{ (current_day == 3 and thursday_enabled) }}" 
 - condition: template
   value_template: "{{ (current_day == 4 and friday_enabled) }}" 
 - condition: template
   value_template: "{{ (current_day == 5 and saturday_enabled) }}" 
 - condition: template
   value_template: "{{ (current_day == 6 and sunday_enabled) }}" 

# This section will simply call the MQTT Publish service to run the update command, as define in the Shelly MQTT API
action:
  # A very simple MQTT statement (topic and payload), which it will check if there's a more recent firmware, then if true - apply it
  - service: mqtt.publish
    data:
      # Please note that during a firmware update, lights connected to Shellies may flash, and devices may lose power
      topic: shellies/command
      payload: update_fw
      # Use QoS2 for confident messaging
      qos: 2
      # No need to retain
      retain: false

Changelog

  • 2021-02-25: Initial version

First Time Working With Blueprints?

How To Import Blueprints

1 Like

Please note than this is in 12-hour format, and you will need to select AM or PM.

Personally, I think the time picker is mostly self-explanatory, and doesn’t need to be clarified.