Shelly firmware updates

Just noticed by chance Shelly have new firmware available. Has the super cool feature of backup WiFi! Love it! It is fantastic for my situation for reasons too complicated to list here.

However, got me thinking, does anyone have an automation to alert them to new firmware for their Shellys? I never look at the Shelly web GUI unless there’s a problem

You’re using MQTT with your shellies?

- alias: "Shelly Update available"
  id: 'pnsua'
  trigger:
    platform: mqtt
    topic: shellies/announce
  condition:
    condition: template
    value_template: "{{ trigger.payload_json['new_fw'] == true }}"
  action:
    service: persistent_notification.create
    data:
      title: "Update available!"
      message: "New version of Shelly released"
      notification_id: shellyUpdateAvailable
5 Likes

Is there a way to report which device/s require an update? I have 20+ Shellies and most have been updated but trying to find a way to easily report the one or two that still require updating.

This produces one notificiation per device that reports a firmware update and creates a clickable link to trigger the update procedure:

  - alias: "Shelly New Firmware Notification"
    id: 'snfn'
    trigger:
      platform: mqtt
      topic: shellies/announce
    condition:
      condition: template
      value_template: "{{ trigger.payload_json['new_fw'] == true }}"
    action:
      service: persistent_notification.create
      data_template:
        title: "New Shelly Firmware Update Released"
        message: "<a target='_blank' href='http://{{ trigger.payload_json['ip'] }}/ota?update=true'>Trigger update</a> for <a target='_blank' href='http://{{ trigger.payload_json['ip'] }}/'>{{ trigger.payload_json['id'] }}</a>."
        notification_id: "{{ trigger.payload_json['id'] }}"

This one removes the notification again once updated:

  - alias: "Shelly New Firmware Notification Removal"
    id: 'snfnr'
    trigger:
      platform: mqtt
      topic: shellies/announce
    condition:
      condition: template
      value_template: "{{ trigger.payload_json['new_fw'] == false }}"
    action:
      service: persistent_notification.dismiss
      data_template:
        notification_id: "{{ trigger.payload_json['id'] }}"
6 Likes

Thank you so much! Trying now.

My Shellies are on v1.7.0 and they don’t seem to be periodically posting to shellies/announce.
It seem we need to publish a announce message to the topic shellies/command to trigger this announcement.

I’ve adapted @Florian snippet and added a periodic trigger to receive the announcements as well as adding the shelly ip to the notifications message for easy access to the GUI where one can update it.

- alias: "Periodic Shelly FW check"
  trigger:
    platform: time
    at: "21:30:00"
  action:
    service: mqtt.publish
    data:
      topic: shellies/command
      payload: announce 

- alias: "Shelly new firmware notification"
  trigger:
    platform: mqtt
    topic: shellies/announce
  condition:
    condition: template
    value_template: "{{ trigger.payload_json['new_fw'] == true }}"
  action:
    service: persistent_notification.create
    data_template:
      title: "New Shelly firmware update released"
      message: "Update shelly at <a target='_blank' href='http://{{ trigger.payload_json['ip'] }}'>{{ trigger.payload_json['ip'] }}</a>."
      notification_id: "shellies/{{ trigger.payload_json['id'] }}"
4 Likes

To be honest now the latest release seems to have resolved the connectivity woes that have plagued my shellies for the last few months, I don’t think I’ll ever update again. Updating from when I bought them actually made them less reliable.

Does the code need to be entered in configuration.yaml or do I need to create an automation? Sorry but I’m still a bit immature at the Home Assistant level.

Thanks bye

Yes to both, depending on whether you’ve split your automations into a separate yaml file. Basically the above are both automations.

I entered in automation.yaml (for a little more order …)
works excellently !!
Thanks a lot and hello everyone!

1 Like

Very nice. Is there any way to automatically run the update, and maybe give a notification on success? Rather than manually having to click the link.
I am supporting quite a few Home Assistant installs all with shelly devices, and it would be great to be able to keep them up to date.

Edit, yes there is:
in configuration.yaml, add the rest integration and configure like so:

 	rest_command:
	  update_shelly:
	    url: 'http://{{ shelly_ip }}/ota?update=true'

create a new automation, eg. shellyupdate.yaml that looks like this:

 	  - alias: "Shelly New Firmware Notification"
	    id: 'snfn'
	    trigger:
	      platform: mqtt
	      topic: shellies/announce
	    condition:
	      condition: template
	      value_template: "{{ trigger.payload_json['new_fw'] == true }}"
	    action:
	      - service: persistent_notification.create
	        data_template:
	          title: "New Shelly Firmware Update Released. Update will be attempted."
	          message:  Update will be attempted"
	          notification_id: "{{ trigger.payload_json['id'] }}"
	      - service: rest_command.update_shelly
	        data:
	          shelly_ip: "{{ trigger.payload_json['ip'] }}"
	
	  - alias: "Shelly New Firmware Notification Removal"
	    id: 'snfnr'
	    trigger:
	      platform: mqtt
	      topic: shellies/announce
	    condition:
	      condition: template
	      value_template: "{{ trigger.payload_json['new_fw'] == false }}"
	    action:
	      service: persistent_notification.dismiss
	      data_template:
	        notification_id: "{{ trigger.payload_json['id'] }}"
1 Like

Just wondering, how would that look like in case Shelly is not utilized over MQTT Service? Rather for instance default Protocol, CoAP? Possible? Advantage or Disadvantage not to use MQTT?

Hello Peter,

Great automation you posted!
Quite new to yaml/HASS and not great at programming so I have a question:
It triggers the update by shelly url. I have a username/password on the shelly devices, does it login via the username/pass provided within hass and perform the update?

So far it didn’t trigger yet, even though an update was avail.

Edit: figured some stuff out with the help of shelly api docs. Think I figured it out.
The automation above does not check if there’s a firmware version difference (shelly device vs latest release), but rather checks the releasedate.
Means: I just have to wait for a new release to see if it triggers.

@spol when you’ll have it confirmed can you please share your code? I also have all my Shellies configured using Shelly integration (CoAP) with username and password and I was also wondering if the update is possible. Thanks!

Before I tackle this myself I thought I would check if anyone had set up automated updating with notification using CoAP (since I now have 8 or 10 shelly’s that need updates).

While new to HA I have been an engineer for MANY many years. Seems straight forward if I understand how things SHOULD work. At a high-level it seems like one could use

  • Trigger: binary_sensor.<< entity name >>_lts_firmware_update = True
  • Service: would be Notification Service described, and of course the REST command to update.
service: rest_command.update_shelly
	        data:
	          shelly_ip: "{{ trigger.payload_json['ip'] }}"

Of course I would need to understand how to do this “generically” rather then having to specify each Shelly (something like) binary_sensor.*_lts_firmware_update = True)? If there is some sort of wildcard support in HA. And of course have to understand if the rest of the scripts above that were contributed would still work for passing IPs to updater as written if NOT triggered by MQTT.

In summary seems like the is a better solution then just simply choosing to ditch the built in Shelly integration for the HACS integration they seems to provide UI support for updating Firmware (both of which are preferable to the web bookmark I made that I currently use to update all Shellys via URL or the terminal command I have that does the same) as those options still require my intervention.

Thanks for any guidance. When/if I finally get around to doing this myself I will post code here as seems at least 2 others here were looking for the same solution. Perhaps some FUTURE version of HA might make automation and other code snippet sharing easier… But that’s clearly a bigger topic for another day and I need too learn a lot more before I make THOSE kind of suggestions as something tells me Script Kiddies on steroids is not a great idea for stability/predictability/or MORE importantly Security!.. lol

1 Like

Hello, very good, have you made any progress here?

Thank you

Not yet as I haven’t had time to devote to it given other pressing HA issues (adding new Shelly’s and other issues around adding HAS type add-ons via docker since I don’t use Supervisor. However I am coincidentally looking at picking the issue back up soon after get around to implementing circadian lighting for my house full of Lifx bulbs (many controlled by Shelly connected physical light switches.

Will update here when have something to share.

–T

FWIW, I have a version of the MQTT “approach” that includes requesting the Shellies to update the firmware. I recently moved over from OpenHAB, where I’ve used this (MQTT) approach for a couple of years.

alias: Shelly new firmware notification and update
description: Shelly new firmware notification and update
trigger:
  - platform: mqtt
    topic: shellies/announce
condition:
  - condition: template
    value_template: '{{ trigger.payload_json[''new_fw''] == true }}'
action:
  - service: persistent_notification.create
    data:
      title: Ny Shelly firmware tilgængelig
      message: >-
        Update shelly at <a target='_blank' href='http://{{
        trigger.payload_json['ip'] }}'>{{ trigger.payload_json['id'] }}</a>.
      notification_id: shellies/{{ trigger.payload_json['id'] }}
  - service: logbook.log
    data:
      name: New Shelly firmware
      entity_id: automation.shelly_new_firmware_notification
      message: '"shellies/{{ trigger.payload_json[''id''] }}"'
  - service: mqtt.publish
    data:
      payload: update_fw
      topic: shellies/{{ trigger.payload_json['id'] }}/command
  - service: logbook.log
    data:
      name: Updated Shelly firmware
      entity_id: automation.shelly_new_firmware_notification
      message: '"shellies/{{ trigger.payload_json[''id''] }}"'
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: persistent_notification.dismiss
    data:
      notification_id: shellies/{{ trigger.payload_json['id'] }}
mode: single
1 Like

Thank you for the code. It used to work, but now I get error:

Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘payload_json’

I don’t see announce under shellys in MQTT Explorer

Strange, I have similar errors in my logs. I can actually see the shellies/announce topic and I can see the JSON payload. Try sending the shellies/command message with announce a payload and see what comes back…