Get an alert when ESPHome flash has finished! (Working)

Get an alert when ESPHome flash has finished!

  • My ESPHome flashes take a while and so I get distracted and side-tracked while waiting, then forget to go back to testing/working on them. It would be nice to get an alert of sorts.

  • The folk over on the ESPHome Discord (well user @antonio-fiol ) suggested including a timestamped ESPHome version sensor in all my ESPHome configs, then watching for any changes.

  • And I adapted an automation / trigger from over here.

In your all of your ESPHome configs:

# I use substitutions but you don't have to. 
substitutions:
  friendly_name: This is my device friendly name I like

text_sensor:
# Reports the ESPHome Version with compile date
  - platform: version
    name: ${friendly_name} ESPHome Version

As a HA automation:

############################
#ESPHome Flash has finished
############################
#Based on this:  https://community.home-assistant.io/t/template-to-add-values-of-all-sensors-with-certain-name-ending/64488/21?u=mahko_mahko
#And thanks to Antonio-Fiol on the ESPHome Discord for the suggestion to use the ESPHome version sensor.
- id: '5656254'
  alias: An ESPHome Flash has Finished
  trigger:
    platform: event
    event_type: state_changed
  condition:
  #Check for substring "_esphome_version" in entity_id
    condition: template
    value_template: "{{ '_esphome_version' in trigger.event.data.entity_id }}"    
  action:
  #Do something useful.
  - service: rest_command.assistant_broadcast
    data:
    #Include the Friendly name of the ESPHOme device in message. Remove " ESPHome Version" from message.
      command: Finished Flashing {{ state_attr(trigger.event.data.entity_id, 'friendly_name') |replace(" ESPHome Version","")}}

It works, but interested to hear if there are more elegant solutions.

Would be cool to know how long the flash took.

1 Like

You can probably streamline this a bit:

command: Finished Flashing {{ trigger.event.data.new_state.name.removesuffix(' ESPHome Version') }}
1 Like