### perform-action with confirmation Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md Example of a tap_action using perform-action to call light.turn_on with a target and data, including a confirmation prompt. Templates are not allowed inside actions; call a script instead. ```json { "tap_action": { "action": "perform-action", "perform_action": "light.turn_on", "target": {"entity_id": "light.kitchen"}, "data": {"brightness_pct": 40}, "confirmation": {"text": "Turn on the kitchen?"} } } ``` -------------------------------- ### Set up and run HA examples checker Source: https://github.com/homeassistant-ai/skills/blob/main/CLAUDE.md Clone a sparse home-assistant/core checkout and run check_ha_examples.py against it. The checkout is a few MB and requires a tag. The script validates example actions, triggers, and conditions against HA's YAML schemas. ```bash git clone -q --depth 1 --filter=blob:none --sparse --branch https://github.com/home-assistant/core git -C sparse-checkout set --no-cone '/homeassistant/components/*/services.yaml' \ '/homeassistant/components/*/triggers.yaml' '/homeassistant/components/*/conditions.yaml' \ /homeassistant/helpers/selector.py /homeassistant/const.py uv run --no-project --with pyyaml python scripts/check_ha_examples.py --ha-core ``` -------------------------------- ### initialize() Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Called once when AppDaemon starts or the app is reloaded. Register all callbacks here, not in __init__(). ```APIDOC ## initialize() ### Description Called once when AppDaemon starts or the app is reloaded. Register all callbacks here, not in __init__(). ### Method initialize() ### Parameters None ### Request Example ```python def initialize(self): # Register callbacks here self.listen_state(self.on_motion, "binary_sensor.hallway_motion", new="on") ``` ### Response No return value. ``` -------------------------------- ### Install with npx skills add Source: https://github.com/homeassistant-ai/skills/blob/main/README.md Installs the skills into the current project using the Agent Skills installer. Requires Node.js 22.20+. ```bash npx skills add homeassistant-ai/skills ``` -------------------------------- ### Custom Card Usage Example Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md Shows how to use the custom card in a dashboard configuration. The type must be prefixed with 'custom:' and the entity is required. ```json {"type": "custom:my-card", "entity": "sensor.temperature"} ``` -------------------------------- ### Install as Claude Code plugin - install plugin Source: https://github.com/homeassistant-ai/skills/blob/main/README.md Run inside Claude Code to install the plugin after adding the marketplace. ```claude-code /plugin install home-assistant-skills@home-assistant-skills ``` -------------------------------- ### Sun Condition Examples Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Sunrise/sunset-based logic with optional offsets. ```yaml # After sunset condition: sun after: sunset # Before sunrise with offset condition: sun before: sunrise before_offset: "01:00:00" # After sunset by 30 minutes condition: sun after: sunset after_offset: "00:30:00" ``` -------------------------------- ### Hysteresis explained Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Example illustrating how hysteresis works with upper and lower thresholds. ```text With upper: 25 and hysteresis: 1: - Turns ON when value rises ABOVE 26 (25 + 1) - Turns OFF when value falls BELOW 24 (25 - 1) ``` -------------------------------- ### Home Assistant Trigger Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Fires when HA finishes starting or begins shutting down. Use start for boot-time setup; shutdown handlers get only ~20 seconds before HA stops. ```yaml triggers: - trigger: homeassistant event: start # "start" or "shutdown" ``` -------------------------------- ### Custom Card Configuration Example Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md Example dashboard configuration for a custom card with type, entity, and name fields. The type uses the 'custom:' prefix. ```json { "type": "custom:quick-status-card", "entity": "sensor.temperature", "name": "Living Room" } ``` -------------------------------- ### run_every Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Schedules a callback to run every N seconds, starting immediately. ```APIDOC ## run_every ### Description Schedules a callback to run every N seconds, starting immediately. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **callback** (function) - Required - The function to call on each interval. - **start** (datetime) - Required - The start time (e.g., `self.datetime()`). - **interval** (number) - Required - Interval in seconds. ### Request Example ```python self.run_every(self.poll_api, self.datetime(), 60) ``` ### Response No return value documented. ``` -------------------------------- ### Date/Time Calculations with Template Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Use templates for time differences, formatting, and calculations. The example shows a sensor that calculates days until an event from an input_datetime. ```yaml template: - sensor: - name: "Days Until Event" state: > {% set event_date = as_datetime(states('input_datetime.event')) %} {% set today = now().replace(hour=0, minute=0, second=0, microsecond=0) %} {{ ((event_date - today).days) }} unit_of_measurement: "days" ``` -------------------------------- ### YAML example with description and note fields Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/automation-actions.md Shows how to document an automation's intent using the top-level `description:` field and per-block `note:` annotations. The `note:` key is singular and available from Home Assistant 2026.6; it is stored in config but stripped at runtime. ```yaml description: "Turn on the porch light at dusk; skip if already on." triggers: - trigger: sun event: sunset note: "Dusk, not full dark — sunset event is ~civil twilight." actions: - action: light.turn_on target: entity_id: light.porch note: "Brightness intentionally left at last value." ``` -------------------------------- ### Dynamic Action Data with Template Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Use templates to pass dynamic values to actions based on entity states or trigger context. The example shows a light.turn_on action with brightness and color temperature derived from sensors. ```yaml actions: - action: light.turn_on target: entity_id: light.bedroom data: brightness_pct: "{{ states('input_number.default_brightness') | int }}" color_temp_kelvin: "{{ 6500 if is_state('binary_sensor.daytime', 'on') else 2700 }}" ``` -------------------------------- ### Dashboard Structure YAML/JSON Example Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md Shows the config shape for a Lovelace dashboard with a title, icon, background, and views containing sections with heading cards. This is not a file to hand-edit; storage-mode dashboards are managed via the Lovelace WebSocket API. ```json { "title": "My Home", "icon": "mdi:home", "config": { "background": {"image": "/local/background.jpg", "opacity": 30, "size": "cover"}, "views": [ { "title": "Overview", "path": "home", "type": "sections", "max_columns": 4, "sections": [ {"type": "grid", "cards": [ {"type": "heading", "heading": "Climate", "icon": "mdi:thermometer"}, ... ]}, {"type": "grid", "cards": [ {"type": "heading", "heading": "Lights", "icon": "mdi:lightbulb"}, ... ]} ] } ] } } ``` -------------------------------- ### Initiate Options Flow to Inspect Group Members (POST /api/config/config_entries/options/flow) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/safe-refactoring.md Starts an Options Flow for a specific group to read current members from suggested_value in data_schema.entities. Only one active flow per Config Entry is allowed; abandon or complete it before starting a fix flow. ```http POST /api/config/config_entries/options/flow {"handler": ""} ``` -------------------------------- ### Zone Condition Examples Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Presence detection based on zones, including negation with 'not'. ```yaml condition: zone entity_id: person.john zone: zone.home # Or check if NOT in zone condition: not conditions: - condition: zone entity_id: person.john zone: zone.home ``` -------------------------------- ### And/Or/Not Conditions Examples Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Combine conditions with logical operators. AND is default when multiple conditions are listed. ```yaml # AND (default when multiple conditions listed) condition: and conditions: - condition: state entity_id: light.kitchen state: "on" - condition: numeric_state entity_id: sensor.brightness below: 100 # OR condition: or conditions: - condition: state entity_id: person.john state: "home" - condition: state entity_id: person.jane state: "home" # NOT condition: not conditions: - condition: state entity_id: alarm_control_panel.home state: "armed_away" # Shorthand syntax conditions: - and: - condition: state entity_id: input_boolean.guest_mode state: "on" - condition: time after: "08:00:00" ``` -------------------------------- ### Blueprint metadata YAML example Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/blueprint-guide.md Defines the required blueprint metadata mapping, including name, description, domain, author, source_url, homeassistant.min_version, and input. The domain must match the blueprint body: automation uses triggers/actions, script uses sequence, template defines template entities. Set source_url to enable re-import and sharing; set min_version when using features from specific releases. ```yaml blueprint: name: Motion-Activated Light # required; short and descriptive description: Turn a light on when motion is detected, off after a delay. domain: automation # required: automation | script | template author: Your Name # optional source_url: https://github.com/you/ha-blueprints/blob/main/motion_light.yaml homeassistant: min_version: "2024.10.0" # optional; gate version-specific features (see note below) input: # ... see below ``` -------------------------------- ### Device Trigger vs State Trigger (YAML) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/device-control.md Shows the wrong and right way to trigger automations. The wrong example uses device_id which changes on device re-add; the right example uses a stable entity_id. ```yaml # WRONG — device_id changes if device is re-added triggers: - trigger: device device_id: abc123def456 domain: binary_sensor type: motion # RIGHT — entity_id is stable and renameable # (generic fallback — check motion.detected with an area target first) triggers: - trigger: state entity_id: binary_sensor.hallway_motion to: "on" ``` -------------------------------- ### Presence and Person Triggers and Conditions (Removed in 2026.5) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Shows the removed device trigger types and the correct state-based replacements. The wrong example uses device trigger types removed in 2026.5; the right examples use state triggers and conditions. ```yaml # WRONG — device trigger types removed in 2026.5 triggers: - trigger: device domain: person type: entered_home entity_id: person.john ``` ```yaml # RIGHT — state trigger triggers: - trigger: state entity_id: person.john to: "home" ``` ```yaml # RIGHT — state condition condition: state entity_id: person.john state: "home" ``` -------------------------------- ### Card-mod per-card styling example Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md Requires the `card-mod` card from HACS or the Marketplace. Use sparingly: it patches frontend internals via shadow-DOM selectors, which makes it a frequent source of breakage after HA upgrades — prefer native options and theme variables where they exist, and re-test card-mod styling after every HA update. ```yaml type: entities card_mod: style: | ha-card { --ha-card-background: teal; color: var(--primary-color); } entities: - light.bed_light ``` -------------------------------- ### Install as Claude Code plugin - add marketplace Source: https://github.com/homeassistant-ai/skills/blob/main/README.md Run inside Claude Code to add the marketplace for the plugin. ```claude-code /plugin marketplace add homeassistant-ai/skills ``` -------------------------------- ### Template Condition Shorthand Examples Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Shorthand syntax preferred when a template is necessary; long form is equivalent. ```yaml # Shorthand (preferred when template is necessary) conditions: - "{{ trigger.to_state.attributes.brightness > 100 }}" # Long form (equivalent) conditions: - condition: template value_template: "{{ trigger.to_state.attributes.brightness > 100 }}" ``` -------------------------------- ### Get fork repository for a community PR Source: https://github.com/homeassistant-ai/skills/blob/main/CLAUDE.md Use this command to get the head repository (fork) for a pull request. This is needed because community PRs come from forks and the base-repo `?ref=` will 404. ```bash gh pr view --json headRepository ``` -------------------------------- ### Entity Iteration with selectattr Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Process multiple entities dynamically using templates. The example shows a sensor that counts open windows by filtering binary sensors. ```yaml template: - sensor: - name: "Open Windows Count" state: > {{ states.binary_sensor | selectattr('attributes.device_class', 'eq', 'window') | selectattr('state', 'eq', 'on') | list | count }} ``` -------------------------------- ### Fetch latest Home Assistant core release tag Source: https://github.com/homeassistant-ai/skills/blob/main/CLAUDE.md Use this command to get the latest release tag name from the Home Assistant core repository. The plain list includes betas, so use this to get the current stable tag for verifying version-pinned claims. ```bash gh api repos/home-assistant/core/releases/latest --jq .tag_name ``` -------------------------------- ### Time trigger examples: fixed time, input_datetime, and time_pattern Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Four separate time trigger configurations: a fixed time, an input_datetime helper, a time_pattern every 5 minutes, and a time_pattern every hour at :30. Each is a distinct trigger type or configuration. ```yaml # Fixed time triggers: - trigger: time at: "07:00:00" ``` ```yaml # Input datetime helper triggers: - trigger: time at: input_datetime.morning_alarm ``` ```yaml # Time pattern (every 5 minutes) triggers: - trigger: time_pattern minutes: "/5" ``` ```yaml # Every hour at :30 triggers: - trigger: time_pattern minutes: 30 ``` -------------------------------- ### Template sensor with device_class Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Use appropriate device_class for unit conversion and graph display. Example shows temperature sensor. ```yaml template: - sensor: - name: "Calculated Temperature" device_class: temperature unit_of_measurement: "°C" state_class: measurement state: "{{ states('sensor.raw_temp') | float / 10 }}" ``` -------------------------------- ### 2-space indentation for template blocks (standard vs non-standard) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Compares the HA Style Guide's 2-space indentation for list items under sensor:/binary_sensor: with a compact notation that is valid YAML but not used in official docs. Follow the standard style for consistency. ```yaml # Standard — 2-space indent per level (HA Style Guide, matches official docs): - binary_sensor: - name: "My Sensor" state: "{{ ... }}" # Non-standard — compact notation (valid YAML, but absent from official HA docs): - binary_sensor: - name: "My Sensor" ``` -------------------------------- ### call_service for climate, notify, and cover services Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Use call_service for any domain/service not covered by convenience methods. Format is 'domain/service_name' with a slash, not a dot. Examples show climate, notify, and cover services. ```python # Climate self.call_service( "climate/set_temperature", entity_id="climate.living_room", temperature=22, hvac_mode="heat" ) # Notify self.call_service( "notify/mobile_app_phone", title="Motion Detected", message=f"Motion in hallway" ) # Cover self.call_service( "cover/set_cover_position", entity_id="cover.living_room_blinds", position=50 ) ``` -------------------------------- ### Persisting State via HA Helpers Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Persist state across restarts using Home Assistant input helpers. The example reads an input_number, increments it, and sets an input_boolean flag. ```python # Read raw_count = self.get_state("input_number.motion_counter") count = int(float(raw_count)) if raw_count not in (None, "unavailable", "unknown") else 0 # Write self.call_service( "input_number/set_value", entity_id="input_number.motion_counter", value=count + 1 ) # Boolean flag self.call_service( "input_boolean/turn_on", entity_id="input_boolean.presence_confirmed" ) ``` -------------------------------- ### Numeric State Condition Examples Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Numeric comparisons for sensors and attributes. Prefer over template conditions with | float. ```yaml # Above threshold condition: numeric_state entity_id: sensor.temperature above: 25 # Below threshold condition: numeric_state entity_id: sensor.humidity below: 30 # Range condition: numeric_state entity_id: sensor.battery above: 20 below: 80 # Attribute numeric check condition: numeric_state entity_id: sun.sun attribute: elevation below: -6 ``` -------------------------------- ### Time Condition Examples Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Time-based restrictions with automatic midnight crossing handling. One-sided windows anchor at midnight, so provide both bounds for daytime restrictions. ```yaml # Time range (handles midnight crossing!) condition: time after: "22:00:00" before: "06:00:00" # Weekday filter condition: time weekday: - mon - tue - wed - thu - fri # Combined condition: time after: "09:00:00" before: "17:00:00" weekday: - mon - tue - wed - thu - fri ``` -------------------------------- ### Complex String Formatting with Template Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Use templates for formatted output that can't be achieved with native constructs. The example shows a sensor that formats uptime into days, hours, and minutes. ```yaml template: - sensor: - name: "Friendly Uptime" state: > {% set uptime = states('sensor.system_uptime') | float(0) %} {% set days = (uptime // 86400) | int %} {% set hours = ((uptime % 86400) // 3600) | int %} {% set minutes = ((uptime % 3600) // 60) | int %} {{ days }}d {{ hours }}h {{ minutes }}m ``` -------------------------------- ### Attribute Extraction with state_attr Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Create sensors from entity attributes using templates. The example shows a sensor that extracts the media_artist attribute from a media player. ```yaml template: - sensor: - name: "Current Song Artist" state: "{{ state_attr('media_player.spotify', 'media_artist') }}" ``` -------------------------------- ### Dynamic Notification Message with Template Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Use templates to include runtime information in notification messages. The example shows a notify action with a message that includes trigger state and duration. ```yaml actions: - action: notify.mobile_app_phone data: message: > {{ trigger.to_state.name }} has been {{ trigger.to_state.state }} for {{ trigger.for.total_seconds() | int // 60 }} minutes. ``` -------------------------------- ### Complex Conditional State with Template Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Use templates for states that depend on multiple factors. The example shows a sensor that determines comfort level based on temperature and humidity. ```yaml template: - sensor: - name: "Comfort Level" state: > {% set temp = states('sensor.temperature') | float(20) %} {% set humidity = states('sensor.humidity') | float(50) %} {% if temp >= 20 and temp <= 24 and humidity >= 40 and humidity <= 60 %} Comfortable {% elif temp < 18 or humidity < 30 %} Too Cold/Dry {% elif temp > 26 or humidity > 70 %} Too Hot/Humid {% else %} Acceptable {% endif %} ``` -------------------------------- ### Media Player Trigger: media_player.started_playing Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Fires when a media player starts playing. Requires Home Assistant 2026.5+. The target entity_id is required; the optional 'for' option specifies how long playback must continue before the trigger fires. ```yaml triggers: - trigger: media_player.started_playing target: entity_id: media_player.living_room options: for: "00:00:30" # optional: playback must continue this long ``` -------------------------------- ### Trigger Condition Example Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/triggers-and-conditions.md Matches which trigger started the run by trigger id. Only true when run was started by a trigger; false in scripts and manual runs. ```yaml condition: trigger id: motion_on # a single id, or a list (OR semantics): # id: # - motion_on # - motion_off ``` -------------------------------- ### Accessing args Safely: initialize Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Use .get() with defaults for optional args and fail loudly for required args. Logs an error and returns if 'entity_light' is missing from apps.yaml. ```python def initialize(self): # Use .get() with a default rather than direct key access self._timeout = self.args.get("timeout", 180) self._log_level = self.args.get("log_level", "INFO") # Required args: fail loudly with a clear message if "entity_light" not in self.args: self.log("entity_light is required in apps.yaml", level="ERROR") return self._light = self.args["entity_light"] ``` -------------------------------- ### Trigger check: run claude with Skill tool Source: https://github.com/homeassistant-ai/skills/blob/main/evals/CLAUDE.md Run a single prompt in a fresh session to verify it triggers the skill without a full eval run. Use --max-turns 1 because the Skill call appears in the first response; --plugin-dir tests the working tree, not the installed plugin. --model haiku is the cheapest and stricter test. Disable other plugins via --settings with an enabledPlugins map, and prefix env -u CLAUDECODE when running from inside a Claude Code session. ```bash claude -p "" --plugin-dir --output-format stream-json --verbose --max-turns 1 --allowedTools Skill ``` -------------------------------- ### Shortcut card for Assist Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md One tap to launch Assist. The text key is label, not name. Use instead of a button card with tap_action; button is fallback only before 2026.5. ```json { "type": "shortcut", "tap_action": {"action": "assist"} } ``` -------------------------------- ### generic_thermostat helper (config-flow submission, two steps) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Turns a switch or fan into a thermostat following a temperature sensor. Step 1 requires name, heater, target_sensor, ac_mode, cold_tolerance, hot_tolerance; optional duration mappings and min/max temp. Step 2 presets are all optional. YAML-only options: initial_hvac_mode, precision, target_temp_step, target_temp. Duration fields are mappings in the flow; YAML also accepts string form. ac_mode: true inverts logic for cooling. Tolerances prevent rapid cycling. ```yaml # generic_thermostat helper (config-flow submission, TWO steps) # --- step 1 (user) --- name: "Bedroom" # required heater: switch.bedroom_heater # required — a switch or fan entity target_sensor: sensor.bedroom_temperature # required — a temperature sensor ac_mode: false # required — true inverts for cooling cold_tolerance: 0.3 # required, default 0.3 hot_tolerance: 0.3 # required, default 0.3 min_cycle_duration: # optional duration mapping minutes: 5 max_cycle_duration: null # optional duration mapping cycle_cooldown: null # optional duration mapping keep_alive: null # optional duration mapping min_temp: 15 # optional max_temp: 25 # optional # --- step 2 (presets) — all optional --- away_temp: 16 comfort_temp: 21 eco_temp: 18 home_temp: 20 sleep_temp: 17 activity_temp: 20 ``` -------------------------------- ### Instance Variables (in-memory only) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Use instance variables for transient state that resets on app reload or daemon restart. The example shows a counter incremented on each trigger, with a warning that this state is lost on hot-reload. ```python def initialize(self): self._count = 0 # Reset on every app reload / daemon restart def on_trigger(self, entity, attribute, old, new, **kwargs): self._count += 1 self.log(f"Triggered {self._count} times this session") ``` -------------------------------- ### Sections View Header and Footer JSON Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md Adds a header (markdown card with badge positioning) and a footer to a sections view. The header layout accepts 'start', 'center', or 'responsive'; badges_position accepts 'top' or 'bottom'. ```json { "header": {"layout": "responsive", "badges_position": "top", "card": {"type": "markdown", "content": "# Welcome home"}}, "footer": {"max_width": 600} } ``` -------------------------------- ### turn_on / turn_off / toggle convenience methods Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Use these convenience methods for simple on/off/toggle actions. They accept optional action data like brightness_pct and color_temp_kelvin. ```python # Simple on/off/toggle self.turn_on("light.kitchen") self.turn_off("light.kitchen") self.toggle("light.kitchen") # With action data self.turn_on("light.kitchen", brightness_pct=80, color_temp_kelvin=3000) ``` -------------------------------- ### turn_on() Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Turns on an entity, such as a light, with optional parameters. ```APIDOC ## turn_on() ### Description Turns on an entity, such as a light, with optional parameters. ### Method turn_on(entity_id, **kwargs) ### Parameters - **entity_id** (string) - Required - The entity ID to turn on. - **kwargs** - Optional - Additional parameters such as brightness_pct. ### Request Example ```python self.turn_on("light.hallway") self.turn_on(kwargs["light"], brightness_pct=kwargs["brightness_pct"]) ``` ### Response No return value. ``` -------------------------------- ### Template sensor using battery macro via {% from %} import Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md YAML configuration for a template sensor that imports and calls the `battery_state` macro from `battery.jinja`. The import must appear inside every template that uses the macro because imports are per-template, not global. This example uses a Template Helper's state template, which works the same as a `template:` YAML block. ```yaml template: - sensor: - name: "Phone Battery Status" unique_id: phone_battery_status state: > {% from 'battery.jinja' import battery_state %} {{ battery_state('sensor.phone_battery') }} ``` -------------------------------- ### WRONG — Template binary sensor for any-on logic Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Example of an incorrect approach using a template binary sensor to achieve any-on logic, which should be replaced by a binary_sensor group helper. The template checks if either front_door or back_door is on. ```yaml # WRONG — Template binary sensor for any-on logic template: - binary_sensor: - name: "Any Door Open" state: > {{ is_state('binary_sensor.front_door', 'on') or is_state('binary_sensor.back_door', 'on') }} ``` -------------------------------- ### switch_as_x helper (config-flow fields) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Configuration for the switch_as_x helper to expose a switch as a different domain. Requires entity_id (switch.*) and target_domain (cover, fan, light, lock, siren, valve). Optional invert reverses on/off semantics. UI-only, no YAML equivalent. ```yaml # switch_as_x helper (config-flow fields) entity_id: switch.lamp_plug # required — must be a switch.* entity target_domain: light # required invert: false # default false ``` -------------------------------- ### Getting current state with get_state Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Shows how to retrieve the current state value, a specific attribute, or the full state dict using `get_state()`. Includes a safe numeric conversion that guards against `None`, `"unavailable"`, and `"unknown"`. ```python # Get state value state = self.get_state("binary_sensor.door") # "on" / "off" # Get a specific attribute brightness = self.get_state("light.living_room", attribute="brightness") # Get full state dict (includes 'state', 'attributes', 'last_changed', 'last_updated') attrs = self.get_state("light.living_room", attribute="all") # Safe numeric conversion — always guard against None / "unavailable" temp = self.get_state("sensor.temperature") if temp not in (None, "unavailable", "unknown"): value = float(temp) ``` -------------------------------- ### Action types and tap_action configuration Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md Action types include toggle, perform-action, more-info, navigate, url, assist, and none. perform-action is the renamed call-service; existing call-service configs still work, but write new ones with perform-action. ```json { "tap_action": {"action": "toggle"}, "hold_action": {"action": "more-info"}, "double_tap_action": {"action": "navigate", "navigation_path": "/lovelace/lights"} } ``` -------------------------------- ### Quick Reference: Action Structure Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/device-control.md Template for Home Assistant action structure: action required, target optional but recommended, data for parameters, and response_variable to capture responses. ```yaml actions: - action: . # Required target: # Optional but recommended entity_id: entity.id # Single or list area_id: area_name # Single or list device_id: device_id # Avoid except for Z2M data: # Action-specific parameters parameter: value response_variable: result # Capture response (if needed) ``` -------------------------------- ### Capture Response Data with response_variable Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/device-control.md YAML showing how to capture action response data using response_variable, then use it in a notification message. The example fetches hourly weather forecasts and sends a message with tomorrow's high temperature. ```yaml actions: - action: weather.get_forecasts target: entity_id: weather.home data: type: hourly response_variable: forecast - action: notify.mobile_app_phone data: message: "Tomorrow's high: {{ forecast['weather.home'].forecast[0].temperature }}°C" ``` -------------------------------- ### Define HA theme with dark and light modes Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/dashboard-guide.md Global styling is done with HA themes (YAML maps of CSS variables), not raw CSS. Themes are defined under `frontend: themes:` in YAML or installed from HACS or the Marketplace, and selected per user (profile) or per view/card with the `theme` option. Define both modes so OS dark/light switching applies cleanly to both. ```yaml frontend: themes: my_theme: modes: dark: ha-card-border-radius: "16px" primary-color: "#03a9f4" light: ha-card-border-radius: "16px" primary-color: "#0288d1" ``` -------------------------------- ### Expensive value_template example (avoid) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Shows a template sensor using a value_template that iterates over all entities, which runs on every source state change and is expensive. The legacy per-domain template-sensor form was removed in HA 2026.6; use the top-level template: integration key with state: instead. ```yaml # EXPENSIVE - Runs on every source state change template: - sensor: - name: "Expensive Sensor" state: > {% for entity in states %} {# Iterates ALL entities #} ... {% endfor %} ``` -------------------------------- ### Vacuum Control Actions (start, return_to_base, clean_area) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/device-control.md YAML actions for vacuum control: start cleaning, return to dock, and clean specific areas. The clean_area action requires HA area mapping (2026.3+) and uses cleaning_area_id, not area_id, under data. ```yaml # Start cleaning actions: - action: vacuum.start target: entity_id: vacuum.roborock # Return to dock actions: - action: vacuum.return_to_base target: entity_id: vacuum.roborock # Clean specific areas (2026.3+ — uses HA areas, not vendor room IDs) # Requires mapping vacuum segments to HA areas in entity settings first # Supported integrations include Matter, Ecovacs, Roborock (list may grow) actions: - action: vacuum.clean_area target: entity_id: vacuum.roborock data: cleaning_area_id: # NOT area_id: under data: that is read as a target - kitchen - living_room ``` -------------------------------- ### Fetch release blog post from Home Assistant docs Source: https://github.com/homeassistant-ai/skills/blob/main/CLAUDE.md Use this command to fetch a release blog post from the Home Assistant documentation repository. The file is located at `source/_posts/-release-.markdown`. ```bash gh api "repos/home-assistant/home-assistant.io/contents/source/_posts/2026-08-05-release-20268.markdown?ref=current" --jq .content | base64 -d ``` -------------------------------- ### first / last Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Gets the first or last item of a list. ```APIDOC ## first / last ### Description Gets the first or last item of a list. ### Returns - **any** - The first or last item. ``` -------------------------------- ### Right: utility_meter helper YAML configuration Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Shows the correct YAML configuration for a utility_meter helper. The `cycle` key is required and accepts values like `daily`; `offset` is a number of days (0-28) in the flow, but in YAML it is a duration. `tariffs` creates a select entity and per-tariff sensors; `tariffs: []` creates no select. One meter per flow submission. ```yaml # RIGHT — utility_meter helper (config-flow fields) name: "Daily Energy" source: sensor.energy_consumption cycle: daily # required — the key is `cycle`, not `meter_type` offset: 0 # required, default 0 — NUMBER OF DAYS (0-28) in the flow tariffs: [] # required, default [] — e.g. ["peak", "offpeak"] net_consumption: false # required, default false delta_values: false # required, default false periodically_resetting: true # required, default true always_available: false # optional, default false ``` -------------------------------- ### Iterate with Index Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Iterate over entities with loop.index to get the index. ```yaml {% for light in states.light %} {{ loop.index }}: {{ light.name }} is {{ light.state }} {% endfor %} ``` -------------------------------- ### Right: counter helper configuration Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Recommended configuration for the counter helper, with fields like name, initial, step, minimum, maximum, and restore. Defaults are noted for each field. ```yaml # RIGHT — counter helper (counter/create fields) name: "Coffees Today" # required initial: 0 # default 0 step: 1 # default 1 minimum: 0 # default null (no floor) maximum: 100 # default null (no ceiling) restore: true # default true ``` -------------------------------- ### Right: timer helper configuration Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Recommended configuration for the timer helper, with fields name, duration, and restore. Defaults are noted for duration and restore. ```yaml # RIGHT — timer helper (timer/create fields) name: "Laundry Timer" # required duration: "01:00:00" # default 0 restore: true # default false ``` -------------------------------- ### App Entry Using Dotted Module Path Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Configures an AppDaemon app instance using a dotted module path (lighting.motion_light) to reference a Python file inside a package subdirectory. This requires the __init__.py file in that subdirectory. ```yaml motion_light_hallway: module: lighting.motion_light class: MotionLight entity_motion: binary_sensor.hallway_motion entity_light: light.hallway ``` -------------------------------- ### Media player: play media and set volume Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/device-control.md Play media by URL and set volume level (0.0 to 1.0). ```yaml # Play media actions: - action: media_player.play_media target: entity_id: media_player.living_room_speaker data: media_content_id: "https://example.com/audio.mp3" media_content_type: music # Set volume (0.0 to 1.0) actions: - action: media_player.volume_set target: entity_id: media_player.living_room_speaker data: volume_level: 0.5 ``` -------------------------------- ### Trend helper (config-flow submission) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Correct configuration for the trend helper, showing the two-step submission process. Use this to create a binary sensor that detects trends over time. ```yaml # RIGHT — trend helper (config-flow submission, NOT configuration.yaml) # --- step 1 (user) --- name: "Temperature Rising" entity_id: sensor.temperature # --- step 2 (settings) --- attribute: null # optional — track an attribute instead of the state invert: false # true = detect a downward trend ``` -------------------------------- ### Action with target Structure (YAML) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/device-control.md Modern Home Assistant action using the target: key to specify an entity, with brightness data. ```yaml actions: - action: light.turn_on target: entity_id: light.living_room data: brightness_pct: 100 ``` -------------------------------- ### Basic state listener with listen_state Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Shows how to listen for state changes with `listen_state()`. The first call fires when the entity changes to a specific state, the second fires on any state change, the third fires when a specific attribute changes, and the fourth fires after the entity has been in the state for a duration (seconds). ```python def initialize(self): # Fire when entity changes to a specific state self.listen_state(self.on_door_open, "binary_sensor.front_door", new="on") # Fire on any state change self.listen_state(self.on_temp_change, "sensor.living_room_temperature") # Fire when a specific attribute changes self.listen_state( self.on_brightness_change, "light.living_room", attribute="brightness" ) # Fire after entity has been in state for a duration (seconds) self.listen_state( self.on_motion_timeout, "binary_sensor.hallway_motion", new="off", duration=300 # 5 minutes ) def on_door_open(self, entity, attribute, old, new, **kwargs): self.log(f"{entity} changed from {old} to {new}") ``` -------------------------------- ### Activating a Scene (scene.turn_on) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/scenes.md Activates a scene by entity_id, optionally with a transition in seconds. The scene applies all listed entity states atomically. ```yaml actions: - action: scene.turn_on target: entity_id: scene.romantic data: transition: 2.5 # optional, seconds ``` -------------------------------- ### Packages Directory Structure for AppDaemon Apps Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/appdaemon.md Shows the required directory layout for organizing AppDaemon apps into subdirectories (packages). The __init__.py files are required when using dotted module paths, but not needed for flat module names. ```text /config/appdaemon/apps/ lighting/ __init__.py # required when using dotted module paths; not needed for flat module names motion_light.py presence/ __init__.py # required for dotted module paths tracker.py ``` -------------------------------- ### Motion-Activated Light Blueprint (YAML) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/blueprint-guide.md Complete automation blueprint showing versioning best practices: input keys as public API, defaults for new inputs, min_version bump, and stable source_url. Uses modern triggers/actions syntax (requires HA 2024.10.0; input sections alone need 2024.6.0). Device-specific values come only from !input, never hardcoded; mode: restart resets the timer on re-trigger. ```yaml blueprint: name: Motion-Activated Light description: Turn a light (or area) on when motion is detected, off after a delay. domain: automation author: Your Name source_url: https://github.com/you/ha-blueprints/blob/main/motion_light.yaml homeassistant: min_version: "2024.10.0" # modern triggers/actions syntax (input sections alone need only 2024.6.0) input: devices: name: Devices icon: mdi:motion-sensor input: motion_sensor: name: Motion sensor selector: entity: domain: binary_sensor device_class: motion # constrained picker — no free text target_light: name: Light(s) to control selector: target: # target → user may pick lights OR an area entity: domain: light settings: name: Settings icon: mdi:cog collapsed: true input: no_motion_wait: name: Wait time description: Seconds to keep the light on after the last motion. default: 120 # sensible default → optional input selector: number: { min: 0, max: 3600, unit_of_measurement: seconds, mode: slider } brightness: name: Brightness default: 100 selector: number: { min: 1, max: 100, unit_of_measurement: "%" } # Body — device-specific values come only from !input, never hardcoded: mode: restart # re-trigger resets the timer max_exceeded: silent variables: brightness_pct: !input brightness # expose input for use in a template triggers: - trigger: state entity_id: !input motion_sensor # entity selector → concrete entity_id to: "on" actions: - action: light.turn_on target: !input target_light # target selector → passed straight to target: data: brightness_pct: "{{ brightness_pct }}" # variable, not !input, inside the template - wait_for_trigger: - trigger: state entity_id: !input motion_sensor to: "off" - delay: seconds: !input no_motion_wait - action: light.turn_off target: !input target_light ``` -------------------------------- ### input_select helper configuration Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Creates a dropdown selection of predefined options. The `options` list is required and must be non-empty and unique. ```yaml # input_select — input_select/create fields name: "HVAC Mode" # required options: # required, must be non-empty and unique - "auto" - "cool" - "heat" - "off" icon: mdi:thermostat ``` -------------------------------- ### Accessing Trigger Context in Automation Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Use trigger variables in automations to access context. The example shows a notify action with a message using trigger.to_state and trigger.from_state. ```yaml actions: - action: notify.mobile_app_phone data: message: > {{ trigger.to_state.name }} changed from {{ trigger.from_state.state }} to {{ trigger.to_state.state }} ``` -------------------------------- ### statistics helper configuration (three-step config-flow submission) Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/helper-selection.md Correct configuration for the statistics helper. Submitted in three steps: user, state_characteristic, and options. The 'state_characteristic' options depend on whether the source is a sensor or binary_sensor. 'max_age' uses a duration mapping; 'percentile' is only used by the percentile characteristic. ```yaml # RIGHT — statistics helper (config-flow submission, THREE steps — not one payload) # --- step 1 (user) --- name: "Temperature Change (5 min)" entity_id: sensor.temperature # --- step 2 (state_characteristic) --- state_characteristic: change # options depend on sensor vs binary_sensor source # --- step 3 (options) --- sampling_size: 50 max_age: # duration mapping minutes: 5 keep_last_sample: false percentile: 50 # only used by the percentile characteristic precision: 2 ``` -------------------------------- ### REST Sensor with value_template Source: https://github.com/homeassistant-ai/skills/blob/main/skills/home-assistant-best-practices/references/template-guidelines.md Use templates to process raw data from REST sensors. The example shows a REST sensor with a value_template extracting temperature from JSON response. ```yaml # REST sensor with JSON response rest: - resource: "http://api.example.com/data" sensor: - name: "Temperature" value_template: "{{ value_json.current.temperature }}" unit_of_measurement: "°C" ```