Skip to content

Instantly share code, notes, and snippets.

@Ceralor
Last active April 12, 2024 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ceralor/6887fc790c86cdef537a8410ed9dd23d to your computer and use it in GitHub Desktop.
Save Ceralor/6887fc790c86cdef537a8410ed9dd23d to your computer and use it in GitHub Desktop.
Actionable Telegram Notifications for Home Assistant Updates

Telegram Notifications for Home Assistant Updates

Simple blueprint. You must create an input_text helper entity for this blueprint -- it will ask for the entity ID when you create an automation using the blueprint. The value of this will store the entity ID of the updater being used, the chat ID, and message ID for replying to notify once the update is complete if a restart is required.

You also must have the telegram_bot integration set up, specifically the bot part. The notifier is not needed but may as well configure it.

Once that's created, use the import button below, and then define the entities you want to update and select the helper you created, and you're good to go!

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Alternatively, you can paste the URL of this gist in when you go to Settings->Automations->Blueprints and click Import.

blueprint:
name: Telegram Home Assistant Update Notifications
description: Sends a message via a Telegram bot to allow updating specified components.
domain: automation
author: Kay Ohtie
input:
updates:
name: Updates
description: These update entities will trigger the prompt
selector:
entity:
multiple: true
filter:
- domain: update
helper_id:
name: State Helper
description: Input Text helper entity used to store state between restarts
selector:
entity:
filter:
- domain: input_text
variables:
helper_id: !input helper_id
trigger:
- alias: When update available for any selected
platform: state
entity_id: !input updates
to: "on"
from: "off"
id: update
- platform: event
event_type: telegram_callback
id: command_do_update
event_data:
command: /update
- platform: event
event_type: telegram_callback
id: command_cancel
event_data:
command: /cancel
- platform: homeassistant
event: start
id: start
- platform: template
value_template: "{{ states(states(helper_id).split('|')[0]) == 'off' }} "
id: start
condition:
- condition: or
conditions:
- condition: and
conditions:
- condition: trigger
id:
- start
- condition: not
conditions:
- condition: state
entity_id: !input helper_id
state: ""
alias: Test if triggered by startup and updating entities not empty
- condition: not
conditions:
- condition: trigger
id:
- start
alias: test if triggered by not start
action:
- choose:
- conditions:
- condition: trigger
id: command_cancel
sequence:
- service: telegram_bot.edit_message
data:
message: Update cancelled.
inline_keyboard: []
chat_id: "{{ trigger.event.data.chat_id }}"
message_id: "{{ trigger.event.data.message.message_id }}"
- conditions:
- condition: trigger
id: command_do_update
sequence:
- service: telegram_bot.edit_replymarkup
metadata: {}
data:
inline_keyboard: []
chat_id: "{{ trigger.event.data.chat_id }}"
message_id: "{{ trigger.event.data.message.message_id }}"
- service: telegram_bot.send_message
metadata: {}
data:
reply_to_message_id: "{{ trigger.event.data.message.message_id|int }}"
target:
- "{{ trigger.event.data.chat_id|int }}"
message: >-
Sending update request for updating {{
state_attr(trigger.event.data.args[0],"title") }}...
- service: input_text.set_value
metadata: {}
data:
value: >-
{{ trigger.event.data.args[0] }}|{{ trigger.event.data.chat_id
}}|{{ trigger.event.data.message.message_id }}
target:
entity_id: !input helper_id
- service: update.install
data:
backup: >-
{{ true if trigger.event.data.args[0] ==
"update.home_assistant_core_update" else false }}
target:
entity_id: "{{ trigger.event.data.args[0] }}"
- conditions:
- condition: trigger
id:
- start
sequence:
- service: telegram_bot.send_message
metadata: {}
data:
reply_to_message_id: "{{ states(helper_id).split('|')[2] | int }}"
target: "{{ states(helper_id).split('|')[1] | int }}"
message: >-
Updated {{
state_attr(states(helper_id).split("|")[0],"friendly_name")
}} to {{
state_attr(states(helper_id).split("|")[0],"installed_version")
}}
- service: input_text.set_value
metadata: {}
data:
value: ""
target:
entity_id: !input helper_id
default:
- service: telegram_bot.send_message
data:
parse_mode: markdown
inline_keyboard:
- - - Update
- /update {{ trigger.entity_id }}
- - Dismiss
- /cancel
message: >-
*Current Version:* {{ trigger.to_state.attributes.installed_version
}}
*New Version:* {{ trigger.to_state.attributes.latest_version }}
{% if trigger.to_state.attributes.release_summary != None -%}
{{- trigger.to_state.attributes.release_summary -}}
{%- endif -%}
{{ trigger.to_state.attributes.release_url }}
Would you like to install it?
title: "*Update: {{ trigger.to_state.attributes.friendly_name }}*"
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment