mcpField
H
homeassistant-config

homeassistant-config

github.com/esjavadex開発2755 回インストール48 週間前に更新
リポジトリ

homeassistant-config について

homeassistant-configは、Home Assistantの自動化、スクリプト、テンプレート、ブループリント、ダッシュボードなどのYAML設定を作成・管理するスキルです。設定の検証や重複分析、スマートホームの改善提案も行います。

主な機能

  1. 01自動化、スクリプト、テンプレートの作成・管理
  2. 02YAMLとLovelace設定の検証
  3. 03重複、類似項目、トリガー競合の検出
  4. 04設定構造、エンティティ、インクルード、シークレットの分析
  5. 05実用的なYAMLを含む改善提案

活用シーン

  1. 01Home Assistantの自動化やスクリプトを作成・整理
  2. 02保存前にYAML構文や一般的な設定問題を確認
  3. 03重複する自動化や競合するトリガーを発見
  4. 04シーンやデバイス構成の改善案を検討

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/esjavadex/claude-homeassistant-plugins --skill homeassistant-config

インストール後、Claude Code で/homeassistant-configを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

examples/
automations.yaml
configuration.yaml
lovelace-custom-cards.yaml
lovelace-dashboard.yaml
scripts.yaml
secrets.yaml
templates.yaml
references/
best-practices.md
blueprints.md
lovelace.md
patterns.md
templates.md
troubleshooting.md
scripts/
check_config.py
find_duplicates.py
lovelace_validator.py
validate_yaml.py

詳細

Home Assistant 設定スキル

自動化、スクリプト、テンプレート、ブループリント、ファイル構成など、Home Assistant の YAML 設定ファイルを作成および管理します。

スラッシュコマンド

コマンド説明
/ha-find-duplicates [path]設定内の重複した自動化とスクリプトを検索します
/ha-find-duplicates

Home Assistant の設定ファイルをスキャンして、以下を検索します:

  • 完全な重複: トリガーとアクションが同一の自動化/スクリプト
  • 類似項目: 類似度 80% 以上の項目(名前、エンティティ、構造)
  • トリガーの競合: 同じトリガーに応答する複数の自動化

使用方法: /ha-find-duplicates /path/to/config、またはカレントディレクトリの場合は /ha-find-duplicates。

サブエージェント

エージェント説明
ha-suggestions自動化、シーン、デバイスの推奨を行うスマートホーム改善アドバイザー
ha-suggestions

Home Assistant の設定を分析し、以下についてパーソナライズされた提案を行う、能動的なスマートホームコンサルタントです:

  • 新しい自動化: モーション照明、在宅検知、時間ベースのルーティン、省エネ
  • 新しいシーン: 映画鑑賞ナイト、朝のエネルギー、ディナータイム、在宅勤務、パーティーモード
  • スクリプトの改善: 再利用可能なシーケンスとパラメーター化されたルーティン
  • デバイスの推奨: セットアップを強化するセンサー、スイッチ、連携
  • 最適化: 統合、トリガーの効率化、モードの使用、ブループリントへの変換

このエージェントは設定ファイルを自動的に検出し、ドメイン別(ライト、センサー、気候など)にエンティティを棚卸しし、完全でそのまま使える YAML コードを備えた優先度付きの提案を生成します。

検証スクリプト

このスキルには、Home Assistant の設定を検証および分析するスクリプトが含まれています。

YAML バリデーター

YAML の構文を検証し、HA でよくある問題(タブ、クォートされていない真偽値、非推奨の構文)をチェックします:

python3 {baseDir}/scripts/validate_yaml.py /path/to/config.yaml
python3 {baseDir}/scripts/validate_yaml.py /path/to/config.yaml --strict
設定チェッカー

HA 設定の構造を分析し、エンティティを検出し、インクルードとシークレットを追跡します:

python3 {baseDir}/scripts/check_config.py /path/to/config/directory
python3 {baseDir}/scripts/check_config.py /path/to/config.yaml --verbose
Lovelace バリデーター

Lovelace ダッシュボードの設定(YAML および JSON の .storage 形式)を検証します:

python3 {baseDir}/scripts/lovelace_validator.py /path/to/ui-lovelace.yaml
python3 {baseDir}/scripts/lovelace_validator.py /path/to/.storage/lovelace --strict

機能:

  • カードタイプ(組み込みおよびカスタム)を検証します
  • エンティティ ID の形式をチェックします
  • アクション(tap_action、hold_action)を検証します
  • カスタムカード(HACS)を検出します
  • YAML と JSON の両方のストレージ形式をサポートします
重複検出ツール

設定ファイル全体から重複および類似した自動化/スクリプトを検出します:

python3 {baseDir}/scripts/find_duplicates.py /path/to/config/directory
python3 {baseDir}/scripts/find_duplicates.py /path/to/automations.yaml --verbose

機能:

  • 完全な重複の検出(トリガー + アクションが同一)
  • 類似項目の検出(名前、エンティティ、構造の 80% しきい値)
  • トリガー競合の検出(同じトリガーに対する複数の自動化)
  • 自動化間のエンティティ重複の分析
  • 詳細な検出結果を含む JSON 出力

保存前検証フック

このプラグインには、保存前に YAML ファイルを自動的に検証する保存前フックが含まれています。以下をチェックします:

  • タブ文字(HA ではスペースが必要)
  • 基本的な YAML 構文エラー

このフックは、.yaml および .yml ファイルに対する Write/Edit 操作で自動的に実行されます。

YAML の要件

  • インデント: 1 レベルにつき 2 スペース(タブは決して使用しない)
  • 文字列: 真偽値のような値("on"、"off"、"yes"、"no")はクォートする
  • リスト: 適切なインデントで - プレフィックスを使用する
  • コメント: インラインドキュメントには # を使用する
  • 主要な用語: action:(service: ではない)、triggers:(trigger: ではない)、actions:(シーケンスには action: ではない)を使用する

ファイル構成

基本的なインクルード
# configuration.yaml
automation: !include automations.yaml
script: !include scripts.yaml
sensor: !include sensors.yaml
ディレクトリのインクルード
# Merge all files in directory
automation: !include_dir_merge_list automations/
sensor: !include_dir_merge_list sensors/
シークレット管理
# secrets.yaml
mqtt_password: "super_secret_password"
api_key: "your-api-key-here"

# configuration.yaml
mqtt:
  password: !secret mqtt_password

自動化(2024 以降の構文)

基本構造
automation:
  - alias: "Descriptive Name"
    id: unique_automation_id
    description: "What this automation does"
    mode: single  # single, restart, queued, parallel
    triggers:
      - trigger: state
        entity_id: binary_sensor.motion
        to: "on"
    conditions:
      - condition: time
        after: "sunset"
    actions:
      - action: light.turn_on
        target:
          entity_id: light.living_room
一般的なトリガー

状態トリガー

triggers:
  - trigger: state
    entity_id: sensor.temperature
    from: "off"
    to: "on"
    for:
      minutes: 5

時間トリガー

triggers:
  - trigger: time
    at: "07:00:00"

数値状態トリガー

triggers:
  - trigger: numeric_state
    entity_id: sensor.temperature
    above: 25
    below: 30

太陽トリガー

triggers:
  - trigger: sun
    event: sunset
    offset: "-00:30:00"

テンプレートトリガー

triggers:
  - trigger: template
    value_template: "{{ states('sensor.power') | float > 1000 }}"

カレンダートリガー

triggers:
  - trigger: calendar
    entity_id: calendar.work
    event: start
    offset: "-00:15:00"  # 15 min before event

デバイストリガー

triggers:
  - trigger: device
    device_id: abc123
    domain: zwave_js
    type: event.value_notification.entry_control

イベントトリガー

triggers:
  - trigger: event
    event_type: mobile_app_notification_action
    event_data:
      action: "CONFIRM_ACTION"
トリガー ID(複数トリガーの自動化向け)
triggers:
  - trigger: state
    id: "motion_detected"
    entity_id: binary_sensor.motion
    to: "on"
  - trigger: state
    id: "door_opened"
    entity_id: binary_sensor.door
    to: "on"
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: "motion_detected"
        sequence:
          - action: light.turn_on
            target:
              entity_id: light.hallway
一般的なアクション

サービス呼び出し

actions:
  - action: light.turn_on
    target:
      entity_id: light.bedroom
    data:
      brightness_pct: 50
      color_temp: 350

遅延

actions:
  - delay:
      seconds: 30

条件分岐(選択)

actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: sun.sun
            state: "below_horizon"
        sequence:
          - action: light.turn_on
            target:
              entity_id: light.porch
    default:
      - action: light.turn_off
        target:
          entity_id: light.porch

繰り返し

actions:
  - repeat:
      count: 3
      sequence:
        - action: notify.mobile_app
          data:
            message: "Alert!"
        - delay:
            minutes: 1

If-Then-Else

actions:
  - if:
      - condition: state
        entity_id: sun.sun
        state: "below_horizon"
    then:
      - action: light.turn_on
        target:
          entity_id: light.porch
    else:
      - action: light.turn_off
        target:
          entity_id: light.porch

並列アクション

actions:
  - parallel:
      - action: notify.person1
        data:
          message: "Alert sent simultaneously!"
      - action: notify.person2
        data:
          message: "Alert sent simultaneously!"
      - sequence:
          - action: light.turn_on
            target:
              entity_id: light.alarm
          - delay:
              seconds: 5
          - action: light.turn_off
            target:
              entity_id: light.alarm

トリガーの待機

actions:
  - action: light.turn_on
    target:
      entity_id: light.porch
  - wait_for_trigger:
      - trigger: state
        entity_id: binary_sensor.motion
        to: "off"
    timeout:
      minutes: 10
    continue_on_timeout: true
  - action: light.turn_off
    target:
      entity_id: light.porch

応答変数(アクションからデータを取得)

actions:
  - action: calendar.get_events
    target:
      entity_id: calendar.work
    data:
      duration:
        hours: 24
    response_variable: agenda
  - action: notify.mobile_app
    data:
      message: "You have {{ agenda['calendar.work'].events | count }} events today"

エラー時の続行

actions:
  - action: notify.unreliable_service
    data:
      message: "This might fail"
    continue_on_error: true
  - action: light.turn_on
    target:
      entity_id: light.bedroom

応答を返して停止

actions:
  - if:
      - condition: state
        entity_id: input_boolean.enabled
        state: "off"
    then:
      - stop: "Feature is disabled"
        error: true
  - action: script.do_something

スクリプト

script:
  morning_routine:
    alias: "Morning Routine"
    description: "Start the day"
    fields:
      brightness:
        description: "Light brightness"
        example: 80
        default: 100
        selector:
          number:
            min: 0
            max: 100
    sequence:
      - action: light.turn_on
        target:
          area_id: bedroom
        data:
          brightness_pct: "{{ brightness }}"
      - action: media_player.play_media
        target:
          entity_id: media_player.speaker
        data:
          media_content_id: "morning_news"
          media_content_type: "music"

Jinja2 テンプレート

状態関数
# Get state
{{ states('sensor.temperature') }}

# Get attribute
{{ state_attr('climate.thermostat', 'current_temperature') }}

# Check if entity exists
{{ states.sensor.temperature is defined }}
フィルターとテスト
# Convert types
{{ states('sensor.temp') | float(0) }}
{{ states('sensor.count') | int(0) }}

# Math operations
{{ states('sensor.power') | float * 0.15 | round(2) }}

# Date/time
{{ now().strftime('%H:%M') }}
{{ as_timestamp(now()) }}
テンプレートセンサー
template:
  - sensor:
      - name: "Total Power Usage"
        unit_of_measurement: "W"
        state: >
          {{ states('sensor.plug_1_power') | float(0) +
             states('sensor.plug_2_power') | float(0) }}
        availability: >
          {{ states('sensor.plug_1_power') not in ['unknown', 'unavailable'] }}

Lovelace ダッシュボード

YAML モードを有効にする
# configuration.yaml
lovelace:
  mode: yaml
基本的なダッシュボード構造
# ui-lovelace.yaml
title: My Home
views:
  - title: Home
    path: home
    icon: mdi:home
    cards:
      - type: entities
        title: Living Room
        entities:
          - light.living_room
          - switch.fan
一般的なカードの種類

エンティティカード

type: entities
title: Room Controls
state_color: true
entities:
  - entity: light.ceiling
    name: Ceiling Light
  - type: divider
  - entity: climate.thermostat

ボタンカード

type: button
entity: light.bedroom
name: Bedroom
icon: mdi:lightbulb
tap_action:
  action: toggle
hold_action:
  action: more-info

グリッドレイアウト

type: grid
columns: 3
square: true
cards:
  - type: button
    entity: light.1
  - type: button
    entity: light.2
  - type: button
    entity: light.3

エリアカード

type: area
area: living_room
display_type: compact
navigation_path: /lovelace/living-room
sensor_classes:
  - temperature
  - humidity

条件付きカード

type: conditional
conditions:
  - condition: state
    entity: person.john
    state: home
card:
  type: entities
  entities:
    - light.johns_room
カードアクション
tap_action:
  action: toggle           # Toggle entity
  # action: more-info      # Show details
  # action: navigate       # Go to view
  #   navigation_path: /lovelace/lights
  # action: call-service   # Call action
  #   service: light.turn_on
  #   target:
  #     entity_id: light.all
人気のカスタムカード(HACS 経由)

Mushroom カード

type: custom:mushroom-light-card
entity: light.bedroom
show_brightness_control: true
use_light_color: true

ボタンカード(カスタム)

type: custom:button-card
entity: light.bedroom
name: Bedroom
styles:
  card:
    - border-radius: 12px
state:
  - value: "on"
    styles:
      icon:
        - color: amber

検証ツール

  1. 開発者ツール > YAML: 設定の構文を確認します
  2. 開発者ツール > テンプレート: Jinja2 テンプレートをテストします
  3. 開発者ツール > 状態: エンティティの状態を検証します
  4. ログ: トラブルシューティングのためにデバッグログを有効にします
logger:
  default: info
  logs:
    homeassistant.components.automation: debug

よくある問題

問題解決策
タブ文字2 つのスペースに置き換えます
引用符なしのブール値"on"、"off"、"yes"、"no" を引用符で囲みます
テンプレートエラーまず開発者ツールでテストします
エンティティが見つからないentity_id の綴りを確認します
オートメーションが実行されないトレースでトリガー条件を確認します

ブループリント

設定可能な入力を持つ再利用可能なオートメーションテンプレート:

blueprint:
  name: Motion-activated Light
  description: Turn on a light when motion is detected
  domain: automation
  input:
    motion_sensor:
      name: Motion Sensor
      selector:
        entity:
          filter:
            - domain: binary_sensor
              device_class: motion
    target_light:
      name: Light
      selector:
        target:
          entity:
            - domain: light
    delay_time:
      name: Delay
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

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

actions:
  - action: light.turn_on
    target: !input target_light
  - wait_for_trigger:
      - trigger: state
        entity_id: !input motion_sensor
        to: "off"
        for:
          seconds: !input delay_time
  - action: light.turn_off
    target: !input target_light

参照ファイル

詳細なパターンと例については、以下を参照してください:

  • references/patterns.md - 一般的なオートメーションパターン
  • references/templates.md - テンプレートセンサーの例
  • references/lovelace.md - ダッシュボードのカードとレイアウト
  • references/troubleshooting.md - エラーの解決策
  • references/best-practices.md - 最適化のヒント
  • references/blueprints.md - ブループリント作成ガイド
  • examples/ - 完全な動作する設定

コメント