母亲年龄大了,去年生了一场病,需要每天早晚吃药,偶尔忘记吃药的事情时有发生,自己不在身边,能做的不多……
所以利用家中现成的 Home Assistant 做了这个私人定制的吃药提醒。
一、软硬件准备
- Home Assistant 是必须的
- 米家无线开关,有开关自然得有网关
- TTS 音箱,我用的是百度TTS
二、代码
比较简单,三个自动化。
- 8:00-9:30,18:30-21:00,每隔十分钟提醒一次
- 吃药后按下按钮“打卡”,禁用提醒
- 定时重新打开提醒
#每天提醒吃药 automation: - alias: Pills Remind trigger: - platform: time at: '8:00' - platform: time at: '18:30' - platform: time_pattern minutes: /10 condition: - condition: state entity_id: device_tracker.mama_hongmi state: 'home' - condition: or conditions: - condition: time after: '7:59' before: '9:30' - condition: time after: '18:29' before: '21:00' action: - service: script.si_tts data_template: msg: > 吃药时间到了,记得按时吃药。健康小知识:{{ states.sensor.fortune_health.state }} - delay: '3' - alias: Turn off Pills Remind on when button is pressed trigger: - platform: event event_type: xiaomi_aqara.click event_data: entity_id: binary_sensor.switch_158d000186f521 click_type: single - platform: event event_type: xiaomi_aqara.click event_data: entity_id: binary_sensor.switch_158d000186f521 click_type: double - platform: event event_type: xiaomi_aqara.click event_data: entity_id: binary_sensor.switch_158d000186f521 click_type: hold condition: - condition: state entity_id: automation.pills_remind state: 'on' action: - service: automation.turn_off data: entity_id: automation.pills_remind - service: script.si_tts data: msg: "好的,本次吃药已完成。" - alias: Turn on Pills Remind trigger: - platform: time at: '18:00:00' - platform: time at: '7:30:00' action: - service: automation.turn_on data: entity_id: automation.pills_remind
package下载:pills_remind.yaml
再啰嗦几句,关于 TTS 的配置,自己参考教程,不是本文讨论范围。
为了防止误触,我把无线开关的单击、双击、长按都加上了。
健康小知识:{{ states.sensor.fortune_health.state }},这个是用 fortune 做的健康小知识,几分钟更换一条,每次提醒吃药的同时附上不同的内容。