Skip to content

Instantly share code, notes, and snippets.

@MrBearPresident
Created September 18, 2025 07:05
Show Gist options
  • Select an option

  • Save MrBearPresident/a9a103dff9c7dd24293992e113bc3e62 to your computer and use it in GitHub Desktop.

Select an option

Save MrBearPresident/a9a103dff9c7dd24293992e113bc3e62 to your computer and use it in GitHub Desktop.
Home Assistant Routines with buttons

Home Assistant Routines with buttons

This document explains how I use a todo-list system to present simple tasks that help my children with their morning and evening routines.

image

Prerequisites

Before starting, make sure you have:

  • Auto-entities integration installed.
  • Bubble-Cards: I use bubble-cards on my dashboards, but you can use another card type if preferred.

How to Populate the Todo List

I use a script that populates a todo entity named todo.task_house_kid_tasks based on the current day of the week and time of day. This allows different tasks to appear in the morning, afternoon, or evening.

For example: For example: On Tuesdays, my child needs to pack swimming gear for swimming lessons. So, the script adds Swimming_gear as a morning task for Tuesday (day 2).

View the Script
sequence:
  - alias: Depending on day or time add tasks to todo-list
    repeat:
      sequence:
        - if:
            - condition: template
              value_template: "{{now().strftime('%w') == repeat.item.day|string }}"
          then:
            - choose:
                - conditions:
                    - condition: time
                      before: "17:00:00"
                      after: "10:00:00"
                  sequence:
                    - variables:
                        task: "{{ repeat.item.afternoon_task }}"
                - conditions:
                    - condition: time
                      after: "17:00:01"
                  sequence:
                    - variables:
                        task: "{{ repeat.item.evening_task }}"
              default:
                - variables:
                    task: "{{ repeat.item.morning_task }}"
            - repeat:
                sequence:
                  - action: todo.add_item
                    data:
                      item: "{{repeat.item}}"
                    target:
                      entity_id: todo.task_house_kid_tasks
                for_each: "{{task}}"
      for_each:
        - day: 1
          morning_task:
            - Brush_teeth
            - Make_Bag
          afternoon_task:
            - Cookie
          evening_task:
            - Brush_teeth
        - day: 2
          morning_task:
            - Brush_teeth
            - Make_Bag
            - Swimming_gear
          afternoon_task:
            - Cookie
          evening_task:
            - Brush_teeth
        - day: 3
          morning_task:
            - Brush_teeth
            - Make_Bag
          afternoon_task:
            - Cookie
          evening_task:
            - Brush_teeth
        - day: 4
          morning_task:
            - Brush_teeth
            - Make_Bag
          afternoon_task:
            - Cookie
          evening_task:
            - Brush_teeth
        - day: 5
          morning_task:
            - Brush_teeth
            - Make_Bag
          afternoon_task:
            - Cookie
          evening_task:
            - Brush_teeth
        - day: 6
          morning_task:
            - Brush_teeth
          afternoon_task:
            - Cookie
          evening_task:
            - Brush_teeth
        - day: 0
          morning_task:
            - Brush_teeth
          afternoon_task:
            - Cookie
          evening_task:
            - Brush_teeth
alias: SCRIPT-House-PlanningKid
description: ""

Creating a Helper Sensor Using a Template

Since actions are needed to retrieve all items from a todo entity, we use a helper sensor to represent the todo list state.

Note: You need to add this template manually to your config.yaml file as it's not possible to create this helper via the Home Assistant GUI.

View Template Configuration
template:
  - trigger:
      - platform: state
        entity_id: todo.task_house_kid_tasks
      - platform: event
        event_type: event_template_reloaded
      - platform: homeassistant
        event: start
    action:
      - service: todo.get_items
        data:
          status: needs_action
        target:
          entity_id: todo.task_house_kid_tasks
        response_variable: items
    sensor:
      - name: HELP-House-Kid-Tasks
        unique_id: help_house_kid_tasks
        state: "{{ (items.values() | list)[0]['items'] | length }}"
        attributes:
          items: "{{ (items.values() | list)[0]['items'] | map(attribute='summary') | list }}"

Display Todo Items with Bubble-Cards and Auto-entities

To display all todo items from the helper sensor sensor.help_house_kid_tasks, I use the auto-entities card. Each task is represented as a bubble-card button. Pressing, double-pressing, or holding a button marks the corresponding todo item as completed in todo.task_house_kid_tasks.

Icon files for the tasks are stored in the /www/Icons folder inside your Home Assistant config directory. Each icon file name matches the task name in lowercase, for example:

  • brush_teeth.png
  • make_bag.png
  • swimming_gear.png
View Auto-entities Card Configuration
type: custom:auto-entities
card:
  square: false
  type: grid
  columns: 2
card_param: cards
filter:
  template: |-
    {% for st in state_attr("sensor.help_house_kid_tasks", "items") -%}
      {{
        {
          "type": "custom:bubble-card",
          "card_type": "button",
          "button_type": "name",
          "rows": "3",
          "button_action": {

            "tap_action": {
              "action": "perform-action",
              "perform_action": "todo.update_item",
              "target": {
                "entity_id": "todo.task_house_kid_tasks"
              },
              "data": {
                "status": "completed",
                "item": st
              }
            },
            "double_tap_action": {
              "action": "perform-action",
              "perform_action": "todo.update_item",
              "target": {
                "entity_id": "todo.task_house_kid_tasks"
              },
              "data": {
                "status": "completed",
                "item": st
              }
            },
            "hold_action": {
              "action": "perform-action",
              "perform_action": "todo.update_item",
              "target": {
                "entity_id": "todo.task_house_kid_tasks"
              },
              "data": {
                "status": "completed",
                "item": st
              }
            },
        },
        "name": st,
        "icon": "mdi:checkbox-blank-circle-outline",
        "styles": ".bubble-background{ \n background-image: url('/local/Icons/"+st.lower()+".png');  \n  \n    background-size: calc(60%) ;background-position-x: right; background-position-y: bottom; \n    background-repeat: no-repeat;} .bubble-main-icon-container, .bubble-name-container{ align-self: start;} .bubble-name-container{
        min-height: 42px; padding-top: 6px} .bubble-button-card{background-color: #4422ff77}"
        }
      }},
    {%- endfor %}
sort:
  method: state
  numeric: true
  reverse: false
show_empty: true
grid_options:
  columns: full
  rows: auto

Additional Useful Scripts, Automations, Cards

'Empty a todolist'-script

Sometimes it's convenient to clear all tasks in a todo list with a single tap. The built-in todo.clear_completed_items action only removes completed tasks, but I use this script to mark all tasks as completed and then clear them.

View Clear List Script
alias: SCRIPT-House-complete-list
description: Complete all items in a specified todo list
fields:
  entity:
    selector:
      entity:
        domain: todo
    required: true
    name: Entity
    description: Todo list entity to complete all items for
sequence:
  - action: todo.get_items
    target:
      entity_id: "{{ entity }}"
    data:
      status: needs_action
    response_variable: todo_items
  - repeat:
      for_each: "{{ todo_items[entity]['items'] }}"
      sequence:
        - action: todo.update_item
          target:
            entity_id: "{{ entity }}"
          data:
            item: "{{ repeat.item.uid }}"
            status: completed
  - action: todo.remove_completed_items
    target:
      entity_id: "{{ entity }}"
    data: {}

Top Control Card for Quick Actions

I have a bubble-card above the todo list that triggers useful actions:

  • sub-button-1: Run the repopulation script.
  • sub-button-2: Clear all todo list items (even unfinished ones).
  • Main-button Tap: Reloads templates.
  • Main-button Dubble-Tap: Opens the script editor.
  • Main-button Hold: Opens the todo list view.
View Top Control Card Configuration
type: custom:bubble-card
card_type: button
button_type: state
entity: sensor.help_house_kid_tasks
name: Kid Tasks
show_icon: false
scrolling_effect: true
grid_options:
  columns: full
button_action:
  tap_action:
    action: perform-action
    perform_action: template.reload
  hold_action:
    action: navigate
    navigation_path: /todo?entity_id=todo.task_house_kid_tasks
  double_tap_action:
    action: url
    url_path: /config/script/edit/script_house_planningkid
sub_button:
  - entity: script.script_house_planningkid
    icon: mdi:reload
    tap_action:
      action: toggle
    hold_action:
      action: more-info
  - entity: sensor.help_house_kid_tasks
    icon: mdi:trash-can
    tap_action:
      action: perform-action
      perform_action: script.script_house_complete_list
      target: {}
      data:
        entity: todo.task_house_kid_tasks

Auto clear done tasks when all is done - Automation

This automation waits until a todo list has fewer than 1 active task for 5 minutes. Once that condition is met, it clears all completed tasks from the list, effectively resetting it for future use.

View the Automation
alias: AUT-HOUSE-RemoveItemsFromToDoList
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - todo.task_house_kid_tasks
      - todo.task_house_kid2_tasks
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: 1
conditions: []
actions:
  - action: todo.remove_completed_items
    metadata: {}
    data: {}
    target:
      entity_id: "{{trigger.entity_id}}"
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment