My Home Assistant had grown the way most installations grow: one automation at a time, one helper at a time, each in whatever file the UI or a tutorial put it in. It worked, but nobody, me included, could tell where a feature started and where it ended.

Over the last weeks I rebuilt a big part of it, with one idea in mind: a home that only speaks when it matters. The dashboard and the notifications should show what needs an action, and keep everything else available but out of the way.

This series tells how I did it, one step per week. It is more about the approach than about copying YAML:

  1. Tidying up with packages (this post)
  2. An app-like dashboard
  3. Alerts worth having
  4. Weather, pollen and the health of the house
  5. One dashboard, several people
  6. Building all this with an AI assistant

Group by feature, not by file type

By default, Home Assistant splits your configuration by type: automations in automations.yaml, scripts in scripts.yaml, helpers in the UI, template sensors in configuration.yaml. A feature like "notifications" ends up spread over four places.

Packages let you do the opposite: one file per feature, containing everything that feature needs.

# configuration.yaml
homeassistant:
  packages: !include_dir_named packages
# packages/batteries.yaml
template:
  - sensor:
      - name: Low batteries
        # ...
automation:
  - id: battery_alert
    # ...

The rule I now follow:

  • A feature that is stable and reusable goes into a package, automations included. I can read it, version it, copy it or delete it as one unit.
  • Everyday automations that I tweak with the mouse stay in the UI, in automations.yaml. The UI editor can only edit that file, and it rewrites it entirely when you save (comments included), so hand-written YAML has no business there.

Note

Automations in a package show up in the UI with their traces, and you can enable or disable them, but the visual editor is read-only for them. That is the trade-off.

A few things I learned the hard way:

  • packages: must be under homeassistant:. At the root of configuration.yaml, Home Assistant looks for an integration called "packages" and complains.
  • You can declare automation: several times with a label (automation ui:, automation manual:): Home Assistant only looks at the first word. Handy to keep the UI file and a folder of hand-written automations side by side.
  • Some integrations simply do not load from a package in some setups. When a daily utility_meter refused to appear, with nothing in the logs, I created it as a helper in the UI instead. Same entity, two minutes, problem gone. Not everything has to be YAML.

One way to send a notification

Setting up Telegram

I will not repeat the Telegram setup here: the official documentation covers it well. Create a bot with BotFather following the Telegram bot tutorial, then add it to Home Assistant with the Telegram bot integration. Limit it to your own chats (allowed chat IDs). Once your bot can send a message from Developer tools → Actions, everything below works as is.

The second change was notifications. Every automation used to call its own notify service, with its own message format. I replaced that with three building blocks.

1. One notification engine

A single script, notification_engine, takes who, a title, a message and optional extras (a link, a camera snapshot, Telegram buttons). It decides how to deliver: the companion app for a phone, Telegram for the family group. Automations no longer know or care.

- action: script.notification_engine
  data:
    who: family_group
    message: It is raining and the shutters are open
    buttons: "🪟 Close:/run close_shutters, Ignore:/ignore"

The trick that makes it robust: every optional field gets a default at the top of the script, and each destination has its own branch in a choose. The mobile app and Telegram do not accept the same extra data, so sending one common payload to both was the source of half my errors.

Show the full notification engine

Replace phone_1, phone_2 and the notify.mobile_app_… actions with your own devices. family_group sends to the Telegram chat configured in the integration.

script:
  notification_engine:
    alias: Notification engine
    mode: queued
    fields:
      who:
        name: Who?
        required: true
        selector:
          select:
            options:
              - phone_1
              - phone_2
              - family_group
      title:
        name: Title
        selector:
          text:
      message:
        name: Message
        required: true
        selector:
          text:
      url:
        name: Link (opened on tap in the app, added to the text on Telegram)
        selector:
          text:
      camera_entity:
        name: Camera snapshot (mobile app)
        selector:
          entity:
            domain: camera
      buttons:
        name: Telegram buttons, e.g. "Close:/run close_shutters, Ignore:/ignore"
        selector:
          text:
    sequence:
      # Defaults: an empty field becomes an empty string
      - variables:
          title_: "{{ title | default('') }}"
          link: "{{ url | default('') }}"
          camera: "{{ camera_entity | default('') }}"
          btns: "{{ buttons | default('') }}"
          mobile_target: >
            {{ {'phone_1': 'notify.mobile_app_phone_1',
                'phone_2': 'notify.mobile_app_phone_2'}.get(who, '') }}
      - choose:
          # Telegram
          - conditions: "{{ who == 'family_group' }}"
            sequence:
              - action: telegram_bot.send_message
                data:
                  title: "{{ title_ }}"
                  message: "{{ message ~ ('\n' ~ link if link else '') }}"
                  inline_keyboard: "{{ [btns] if btns else [] }}"
          # Companion app (iOS and Android)
          - conditions: "{{ mobile_target != '' }}"
            sequence:
              - action: "{{ mobile_target }}"
                data:
                  title: "{{ title_ }}"
                  message: "{{ message }}"
                  data: >
                    {% set d = {} %}
                    {% if link %}
                      {% set d = dict(d, url=link, clickAction=link,
                           actions=[{'action': 'URI', 'title': 'Open', 'uri': link}]) %}
                    {% endif %}
                    {% if camera %}
                      {% set d = dict(d, entity_id=camera,
                           image='/api/camera_proxy/' ~ camera) %}
                    {% endif %}
                    {{ d }}
        default:
          - action: system_log.write
            data:
              level: warning
              message: "notification_engine: unknown recipient '{{ who }}'"

2. A script that asks and returns the answer

Some automations need a decision: "the garage has been open for 30 minutes, shall I close it?". For that I have a confirmation script that sends a Telegram message with Yes / No buttons, waits for the click, and returns the answer to the caller:

- action: script.telegram_confirm
  data:
    message: Close the garage?
  response_variable: r
- if: "{{ r.answer == 'yes' }}"
  then:
    - action: cover.close_cover
      target:
        entity_id: cover.garage

Two details matter. Each question carries a random tag in its button data, so an old message cannot answer a new question. And the automation must call the script directly, not through script.turn_on, or it will not wait for the answer.

Show the full confirmation script
script:
  telegram_confirm:
    alias: Telegram - ask for confirmation
    mode: parallel
    fields:
      title:
        name: Title
        selector:
          text:
      message:
        name: Message
        required: true
        selector:
          text:
      timeout:
        name: How long to wait
        default: "00:05:00"
        selector:
          text:
    sequence:
      # Unique tag: a click on an old message cannot answer this question
      - variables:
          tag: "{{ range(100000, 999999) | random }}"
      - action: telegram_bot.send_message
        data:
          title: "{{ title | default('') }}"
          message: "{{ message }}"
          inline_keyboard:
            - "✅ Yes:/yes_{{ tag }}, ❌ No:/no_{{ tag }}"
      - wait_for_trigger:
          - trigger: event
            event_type: telegram_callback
            event_data:
              data: "/yes_{{ tag }}"
            id: "yes"
          - trigger: event
            event_type: telegram_callback
            event_data:
              data: "/no_{{ tag }}"
            id: "no"
        timeout: "{{ timeout }}"
        continue_on_timeout: true
      - if: "{{ wait.trigger is not none }}"
        then:
          # Stop the spinner on the button, then remove the buttons
          - action: telegram_bot.answer_callback_query
            data:
              callback_query_id: "{{ wait.trigger.event.data.id }}"
              message: "Got it: {{ wait.trigger.id }}"
          - action: telegram_bot.edit_replymarkup
            data:
              chat_id: "{{ wait.trigger.event.data.chat_id }}"
              message_id: "{{ wait.trigger.event.data.message.message_id }}"
              inline_keyboard: []
      - variables:
          result:
            answer: "{{ wait.trigger.id if wait.trigger is not none else 'timeout' }}"
            by: "{{ wait.trigger.event.data.from_first if wait.trigger is not none else '' }}"
      - stop: Done
        response_variable: result

3. One router for all buttons

The confirmation script is for questions that need an answer now. For simple action buttons ("close the shutters", "ignore"), I did not want one automation per button. A single router automation listens to every Telegram button press, reads a command like /run close_shutters, and runs that script if it is on an allow-list.

That allow-list is not optional. Without it, anybody in the chat, or anybody able to forge a callback, could run any script in the house.

Adding a new button is now: write the script, add its name to the allow-list, use "Label:/run script_name" in a notification. No new automation.

Show the full router
automation:
  - id: telegram_button_router
    alias: Telegram - button router
    mode: queued
    triggers:
      - trigger: event
        event_type: telegram_callback
    conditions:
      # Only our commands: /yes_ and /no_ are handled by the confirmation script
      - "{{ trigger.event.data.data.startswith('/run ') or trigger.event.data.data == '/ignore' }}"
    actions:
      - variables:
          cmd: "{{ trigger.event.data.data }}"
          target: "{{ cmd.split(' ')[1] if cmd.startswith('/run ') else '' }}"
          # Allow-list: only these scripts can be started from Telegram
          allowed:
            - close_shutters
      - choose:
          - conditions: "{{ target in allowed }}"
            sequence:
              - action: "script.{{ target }}"
              - variables:
                  reply: "✅ {{ target }} started"
          - conditions: "{{ cmd == '/ignore' }}"
            sequence:
              - variables:
                  reply: "👍 Ignored"
        default:
          - variables:
              reply: "⛔ Command not allowed"
      - action: telegram_bot.answer_callback_query
        data:
          callback_query_id: "{{ trigger.event.data.id }}"
          message: "{{ reply }}"
      - action: telegram_bot.edit_replymarkup
        data:
          chat_id: "{{ trigger.event.data.chat_id }}"
          message_id: "{{ trigger.event.data.message.message_id }}"
          inline_keyboard: []

Where I am today

Being honest about the state of things: the engine, the confirmation script and the router are in place and tested. Only two alerts actually send Telegram messages today (a suspected water leak and an abnormal power draw at night); everything else shows on the dashboard. A morning summary and a "house is empty" check are designed but not switched on yet. The building blocks exist, so adding them is now a matter of writing the message, not plumbing.

Next week: turning all this into a dashboard that feels like an app on a phone.