Home Assistant

Worthy of it's own heading.

Notes & Tips

A collection of useful Home Assistant tricks, YAML patterns, and advanced workflow reminders.

This page gathers general notes, best practices, and snippets that make daily Home Assistant use smoother. Think of it as your quick reference sheet for advanced users.

🏷️ Entity & State Tips

  • Always use states('sensor.name') or state_attr('entity','attribute') β€” avoid direct dot access like states.sensor.name.state (it may fail on reload).
  • Use filters such as | float(0) or | int(0) to prevent errors from unavailable entities.
  • Combine multiple conditions using and / or logic inside Jinja templates.

βš™οΈ Automation Snippets

alias: Turn off lights after no motion
trigger:
  - platform: state
    entity_id: binary_sensor.livingroom_motion
    to: "off"
    for: "00:05:00"
action:
  - service: light.turn_off
    target:
      area_id: living_room
mode: restart
[yaml]

πŸ’‘ Tip: Using for: in triggers is cleaner than adding a delay in actions.

🧠 Template Tricks

{{ now().strftime('%H:%M') }} β†’ current time
{{ states | count }} β†’ number of entities
{{ expand('group.all_lights') | selectattr('state', 'eq', 'on') | list | count }} β†’ lights on count
[yaml]

Combine filters for powerful real-time insights directly in templates.

🧰 Debugging & Maintenance

  • Use Developer Tools β†’ States to test changes instantly.
  • Reload templates, automations, and scripts individually instead of restarting the full system.
  • Check home-assistant.log and enable debug logging selectively:
logger:
  default: warning
  logs:
    homeassistant.components.automation: debug
    homeassistant.components.template: info
[yaml]

πŸ’Ύ Version Control Reminder

  • Store your configuration.yaml in Git β€” commit often.
  • Ignore secrets and sensitive files in .gitignore.
  • Tag working configurations before major updates or migrations.

Templates

Use Jinja2 templates in Home Assistant to create adaptive automations, sensors, and messages.

Templates use Jinja2 to let you build dynamic logic directly in Home Assistant. They can appear in automations, template sensors, notifications, and even UI cards.

Example: Dynamic Weather Summary

{% set temp = states('sensor.outdoor_temperature') | float %}
{% if temp < 5 %}
  It’s a chilly {{ temp | round(1) }}Β°C today β€” keep warm!
{% elif temp < 20 %}
  Mild weather at {{ temp | round(1) }}Β°C β€” maybe a light jacket.
{% else %}
  Warm and pleasant at {{ temp | round(1) }}Β°C β€” perfect for outdoors.
{% endif %}
[yaml]

This Jinja2 template generates a human-readable weather message that updates automatically based on the outdoor temperature.

Example: Template Sensor

template:
  - sensor:
      - name: "Weather Summary"
        unique_id: weather_summary
        state: >
          {% set temp = states('sensor.outdoor_temperature') | float %}
          {% if temp < 5 %}
            It’s a chilly {{ temp | round(1) }}Β°C today β€” keep warm!
          {% elif temp < 20 %}
            Mild weather at {{ temp | round(1) }}Β°C β€” maybe a light jacket.
          {% else %}
            Warm and pleasant at {{ temp | round(1) }}Β°C β€” perfect for outdoors.
          {% endif %}
[yaml]

Add this snippet to your configuration.yaml or include it via a templates.yaml file. The sensor will update automatically as temperature changes.

Pro Tips

  • Test templates first in Developer Tools β†’ Template.
  • Use filters like | float and | round(1) for stability.
  • Always provide defaults for missing data β€” e.g. states('sensor.x') | float(0).

Blueprints

Create reusable automations that can be shared, imported, and customized by anyone.

Blueprints in Home Assistant are templates for automations β€” reusable logic that can be easily shared and configured without editing YAML directly. They help simplify complex automations and standardize setups across devices or users.

Example: Motion-Activated Light

blueprint:
  name: Motion-Activated Light
  description: Turn on a light when motion is detected, then turn it off after a delay.
  domain: automation
  input:
    motion_sensor:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    target_light:
      name: Target Light
      selector:
        entity:
          domain: light
    delay:
      name: Delay (seconds)
      default: 60
      selector:
        number:
          min: 5
          max: 600
          unit_of_measurement: seconds

trigger:
  - platform: state
    entity_id: !input motion_sensor
    to: "on"

action:
  - service: light.turn_on
    target:
      entity_id: !input target_light
  - delay: "{{ !input delay }}"
  - service: light.turn_off
    target:
      entity_id: !input target_light

mode: restart
[yaml]

Save this file in your blueprints/automation/ directory and it will appear under Configuration β†’ Automations & Scenes β†’ Blueprints.

Why Use Blueprints?

  • Share automations without exposing private entity IDs or secrets.
  • Provide clean, configurable interfaces for users via selectors.
  • Reduce repetition in large or complex setups.
  • Allow non-technical users to create powerful automations visually.

Pro Tips

  • Always include a clear description and sensible defaults.
  • Use !input variables to make entities configurable.
  • Document your inputs and logic β€” treat Blueprints like open-source code.
  • Store and version them in GitHub for easy sharing and updates.
2025