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')orstate_attr('entity','attribute')β avoid direct dot access likestates.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/orlogic 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 π‘ 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 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.logand enable debug logging selectively:
logger:
default: warning
logs:
homeassistant.components.automation: debug
homeassistant.components.template: info πΎ Version Control Reminder
- Store your
configuration.yamlin 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 %} 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 %} 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
| floatand| 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 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
descriptionand sensible defaults. - Use
!inputvariables 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.