แนวคิด Home Resilience Index
บ้านอัจฉริยะสมัยใหม่เก็บข้อมูลมหาศาล แต่ข้อมูลกระจัดกระจายใน entity หลายร้อยตัว Home Resilience Index (HRI) รวมมิติสำคัญ 4 ด้านเป็นคะแนนเดียว 0–100 ให้เจ้าของบ้านประเมินสถานการณ์โดยรวมได้ทันที
4 มิติของ HRI
| มิติ | น้ำหนัก | ตัวชี้วัด | |---|---|---| | ความปลอดภัย (S) | 30% | Frigate event count (24h), ล็อคประตู, กล้อง online | | คุณภาพอากาศ (A) | 25% | PM2.5, CO2 ppm, TVOC | | พลังงาน (E) | 25% | Solar self-consumption %, แบตเตอรี่ SOC, grid dependency | | สุขภาพ (W) | 20% | อุณหภูมิ/ความชื้น, เสียงรบกวน dB, presence hours |
สูตร HRI และ Sub-score
HRI = (S_score × 0.30) + (A_score × 0.25) + (E_score × 0.25) + (W_score × 0.20)
แต่ละ sub-score คำนวณจาก raw sensor เป็น 0–100 ด้วย linear interpolation:
python # ตัวอย่าง AQI score: PM2.5 0→100 คะแนน (PM2.5 0=100pts, PM2.5 75+=0pts) aqi_score = max(0, 100 - (pm25 / 75) * 100) # Energy score: solar self-consumption % + battery SOC energy_score = (solar_self_pct * 0.6) + (battery_soc * 0.4) # Security score: inverse of threats, lock + camera online bonus threat_penalty = min(100, frigate_events_24h * 15) security_score = 100 - threat_penalty + (10 if all_locks_locked else 0) + (5 if cameras_online else 0) security_score = max(0, min(100, security_score))
Home Assistant Template Sensor
yaml template: - sensor: - name: HRI Security Score unit_of_measurement: pts state: > {% set events = states('sensor.frigate_events_24h') | int(0) %} {% set locks = states('lock.front_door') == 'locked' and states('lock.back_door') == 'locked' %} {% set cams = states('binary_sensor.frigate_cameras_online') == 'on' %} {% set base = [0, 100 - (events * 15)] | max %} {{ [100, base + (10 if locks else 0) + (5 if cams else 0)] | min }} - name: HRI AQI Score unit_of_measurement: pts state: > {% set pm25 = states('sensor.pm25_indoor') | float(0) %} {% set co2 = states('sensor.co2_living_room') | float(400) %} {% set pm_score = [0, 100 - (pm25 / 75 * 100)] | max %} {% set co2_score = [0, 100 - ((co2 - 400) / 1200 * 100)] | max %} {{ ((pm_score * 0.6) + (co2_score * 0.4)) | round(1) }} - name: HRI Energy Score unit_of_measurement: pts state: > {% set solar_pct = states('sensor.solar_self_consumption_pct') | float(0) %} {% set soc = states('sensor.battery_soc') | float(0) %} {{ ((solar_pct * 0.6) + (soc * 0.4)) | round(1) }} - name: HRI Wellness Score unit_of_measurement: pts state: > {% set temp = states('sensor.living_room_temperature') | float(25) %} {% set rh = states('sensor.living_room_humidity') | float(60) %} {% set temp_score = [0, 100 - ([0, temp - 28] | max * 10) - ([0, 18 - temp] | max * 10)] | max %} {% set rh_score = [0, 100 - ([0, rh - 65] | max * 3) - ([0, 40 - rh] | max * 3)] | max %} {{ ((temp_score * 0.5) + (rh_score * 0.5)) | round(1) }} - name: Home Resilience Index unit_of_measurement: pts icon: mdi:shield-home state: > {% set s = states('sensor.hri_security_score') | float(0) %} {% set a = states('sensor.hri_aqi_score') | float(0) %} {% set e = states('sensor.hri_energy_score') | float(0) %} {% set w = states('sensor.hri_wellness_score') | float(0) %} {{ (s * 0.30 + a * 0.25 + e * 0.25 + w * 0.20) | round(1) }}
Lovelace Gauge Card
yaml type: gauge entity: sensor.home_resilience_index name: Home Resilience Index min: 0 max: 100 severity: green: 70 yellow: 40 red: 0 needle: true
Composite Dashboard ทั้งหมด
yaml type: vertical-stack cards: - type: gauge entity: sensor.home_resilience_index name: 🏠 HRI min: 0 max: 100 severity: green: 70 yellow: 40 red: 0 - type: horizontal-stack cards: - type: gauge entity: sensor.hri_security_score name: 🔒 Security min: 0 max: 100 - type: gauge entity: sensor.hri_aqi_score name: 🌿 Air min: 0 max: 100 - type: gauge entity: sensor.hri_energy_score name: ⚡ Energy min: 0 max: 100 - type: gauge entity: sensor.hri_wellness_score name: 💚 Wellness min: 0 max: 100
LINE Alert เมื่อ HRI ต่ำกว่า Threshold
yaml alias: HRI Alert — Below 50 trigger: - platform: numeric_state entity_id: sensor.home_resilience_index below: 50 for: "00:10:00" action: - service: notify.line_notify data: message: >- ⚠️ Home Resilience Index: {{ states('sensor.home_resilience_index') }}/100 Security: {{ states('sensor.hri_security_score') }} Air: {{ states('sensor.hri_aqi_score') }} Energy: {{ states('sensor.hri_energy_score') }} Wellness: {{ states('sensor.hri_wellness_score') }}
สรุป
HRI เปลี่ยนข้อมูลเซ็นเซอร์หลายร้อยตัวให้เป็นตัวเลขเดียวที่เข้าใจง่าย — เหมาะสำหรับรายงานสรุปประจำวัน แดชบอร์ดผู้บริหาร หรือแจ้งเตือนเมื่อสถานการณ์บ้านเสื่อมถอย