Custom Update Entities for Home Assistant 2022.4+

I run Home Assistant via a Container installation in Docker, and update this using the shell_command integration from a script.
With the introduction of update entities in Home Assistant 2022.4, I wanted to see if I could integrate this and so I have created Custom Update Entities

You can use this to create as many update entities as you want, based on two sensors (for the latest and installed version) and an action in script syntax.

Here is the configration I am actually using on my system for Home Assistant updates:

custom_update_entities:
  updaters:
    - name: Home Assistant Core
      latest_version_entity: sensor.latest_beta_version
      installed_version_entity: sensor.current_version
      logo_url: https://brands.home-assistant.io/_/homeassistant/icon.png
      update_action:
        - service: shell_command.update_hass
          data:
            version: '{{ version }}'
        - delay: '00:00:10'
        - service: homeassistant.update_entity
          target:
            entity_id: binary_sensor.hass_update_completed
        - wait_for_trigger:
            - platform: state
              entity_id: binary_sensor.hass_update_completed
              to: 'on'

(The wait_for_trigger is used there because the update command runs in the background, so the script relies on a sensor to check if the update has completed and it’s about to restart.)

You can install this manually or by addit it to HACS as a custom repository (although I may see if I can get it in the official repositories).

2 Likes

Does this still work? I tried it, but my update entity only registered as unknown. And I see a couple of deprecation warnings in my logs.

If not, are there any alternatives? I’m currently running an automation to push a persistent notification when there are updates, but it would be so much better to have it within the Update mechanisms, and be able to add other updates as well.

I found an alternative that seems to work from simple testing: MQTT Update

Replacing the persistent notification in my automation with this:

action: mqtt.publish
data:
  retain: true
  topic: custom/updates/home_assistant
  payload: >-
    {
      "installed_version": "{{ states('sensor.version_current') }}",
      "latest_version": "{{ states('sensor.version_available') }}",
      "title": "Home Assistant Core",
      "release_url": "https://www.home-assistant.io/latest-release-notes/",
      "entity_picture": "https://brands.home-assistant.io/_/homeassistant/icon.png"
    }

Then adding the update sensor:

mqtt:
  update:
    - state_topic: "custom/updates/home_assistant" 
      name: "Home Assistant Core"
      command_topic: "custom/updates/home_assistant"
      payload_install: "install"