套件:
前置套件:https://github.com/adamoutler/HassOSConfigurator ※需完整重
啟二次
HA 套件連結:https://github.com/uvjim/rpi_waveshare_ups
HACS套件:Mushroom、mini-graph-card、template-entity-row
自動化
alias: "UPS 安全關機與徹底斷電"
trigger:
- platform: numeric_state
entity_id: sensor.waveshare_ups_capacity
below: 20
condition:
# 判定只要不是 "on" (充電中) 即執行,避免 unavailable 等異常干擾
- condition: not
conditions:
- condition: state
entity_id: binary_sensor.waveshare_ups_online
state: "on"
action:
- service: notify.persistent_notification
data:
title: "電力預警"
message: "電量低於 20% 且未充電,系統將於 30 秒後關閉硬體電源。"
- service: shell_command.ups_cut_off_power # 送出指令讓硬體準備斷電
- delay: "00:00:10"
- service: hassio.host_shutdown
configuration.yaml
shell_command:
ups_cut_off_power: "python3 -c 'import os, fcntl; fd=os.open(\"/dev/i2c-1\", os.O_RDWR); fcntl.ioctl(fd, 0x0703, 0x42); os.write(fd, b\"\\x01\\x55\"); os.close(fd)'"