Skip to content

Instantly share code, notes, and snippets.

@kjagiello
Last active January 10, 2026 14:18
Show Gist options
  • Select an option

  • Save kjagiello/8e7a9b2335d19e10a1f7f4ee6c9724fd to your computer and use it in GitHub Desktop.

Select an option

Save kjagiello/8e7a9b2335d19e10a1f7f4ee6c9724fd to your computer and use it in GitHub Desktop.
blueprint:
name: |
Aivi: Update activity based on timer (template: generic)
description: |
Updates activity using the generic template based on a timer.
See the [docs](https://docs.getaivi.app/templates/#generic-template) for more info about the template.
domain: automation
input:
slug:
name: Activity slug
description: The slug of the activity
timer:
name: Timer
description: The timer entity that will drive the progression of the live activity.
selector:
entity:
filter:
- domain: timer
icon:
name: Icon
description: |
An [SF Symbols](https://developer.apple.com/sf-symbols/) icon.
Example: washer.
triggers:
- trigger: state
entity_id:
- !input timer
variables:
slug: !input slug
icon: !input icon
timer_entity: !input timer
mode: restart
actions:
- repeat:
while:
- condition: template
value_template: >-
{{ state_attr(timer_entity, "remaining") is not none }}
sequence:
- variables: &time
duration: >-
{{ as_timedelta(state_attr(timer_entity, "duration")).total_seconds() }}
eta: >-
{% if state_attr(timer_entity, "finishes_at") is none %}
{% set remaining = as_timedelta(state_attr("timer.some_activity", "remaining")).total_seconds() %}
{% else %}
{% set t_now = now() %}
{% set t_eta = as_datetime(state_attr(timer_entity, "finishes_at"), t_now) %}
{% set remaining = (t_eta - t_now).total_seconds() %}
{% endif %}
{{ max(int(remaining), 0) }}
- variables:
progress: >-
{{ (duration - eta) / duration }}
human_state: >-
{% if state_attr(timer_entity, "finishes_at") is none %}
Paused
{% else %}
In progress
{% endif %}
- action: rest_command.update_live_activity
response_variable: aivi_response
data:
slug: "{{ slug }}"
payload: >-
{
"state": "ONGOING",
"content": {
"template": "generic",
"state": {{ human_state|to_json }},
"remaining_time": {{ eta|to_json }},
"progress": {{ progress|to_json }},
"icon": {{ icon|to_json }}
}
}
- variables: *time
- delay:
seconds: >-
{% if state_attr(timer_entity, "finishes_at") is none %}
{{ 3600 }}
{% else %}
{{ max(1, min(eta % 60, (duration / 100)|round(0, 'ceil'))) }}
{% endif %}
- action: rest_command.update_live_activity
response_variable: aivi_response
data:
slug: "{{ slug }}"
payload: >-
{
"state": "IDLE",
"content": {
"template": "generic",
"state": "Done",
"remaining_time": null,
"progress": 1,
"icon": {{ icon|to_json }}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment