『瀚思彼岸』» 智能家居技术论坛

标题: 用HA做闹钟 [打印本页]

作者: sephrioth    时间: 2021-3-8 16:21
标题: 用HA做闹钟
本帖最后由 sephrioth 于 2023-2-6 18:11 编辑

问: 为啥要用HA做闹钟呢?
答: 因为可以想怎么闹就怎么闹。。。

----------------

首先需要一些准备条件
1. 我们要设置的是工作日闹钟,需要能在前台设置时间, 所以这里我们先定义input_date
  1. workday_alarm: #工作日闹钟
  2.   name: Workday Alarm  
  3.   has_date: false  #不需要日期
  4.   has_time: true   #只需要时间
复制代码
2. 更新下, 这里建议使用 https://github.com/Crazysiri/chineseholiday 插件来获取工作日信息, 完美对接

复制代码
3. TTS 不是必须的。这个就是用来通报, 建议使用 百度tts, 中文支持比较好, 具体配置可以参考官方 https://www.home-assistant.io/integrations/baidu/
  1. tts:
  2. - platform: baidu
  3.   app_id: YOUR_APPID
  4.   api_key: YOUR_APIKEY
  5.   secret_key: YOUR_SECRETKEY
复制代码
-----------------

好了, 我们开始写自动化
  1. - alias: 'Workday Alarm'
  2.   trigger:
  3.   - platform: time
  4.     at: input_datetime.workday_alarm    #到具体时间触发, 具体闹钟时间在lovelace里面改
  5.   condition:
  6.   - condition: state
  7.     entity_id: sensor.holiday
  8.     state: '工作日'     #工作日为on的条件下
  9.   action:     #你想怎么闹都行了, 我这里只是用tts举例
  10.   - service: tts.baidu_say
  11.     data_template:
  12.       entity_id: media_player.sonos   #tts推送的音箱
  13.       message: xxxxx   #推送的信息, 个人建议推送你HA集成的天气信息, 比如彩云天气啥的
  14.   - delay: 00:00:05   #等推送的信息播放完成后, 你还可以干点别的
复制代码


--------------------------
最后写到 lovelace 的界面里, 可以通过 condition 的卡片, 闹钟激活了就显示时间, 不激活不显示;为了效果更好, 还可以引入 stack-in-card 卡片
  1. cards:
  2. - type: conditional
  3.   conditions:
  4.   - entity: automation.workday_alarm
  5.     state: 'on'
  6.   card:
  7.     type: entity
  8.     entity: input_datetime.workday_alarm
  9. - type: entities
  10.   entities:
  11.   - entity: automation.workday_alarm
  12.     secondary_info: last-triggered
  13.     show_name: false
  14. mode: vertical
  15. type: 'custom:stack-in-card'
复制代码


最终效果
1. 闹钟激活
[attach]28450[/attach]

2. 修改时间
[attach]28452[/attach]

3. 关闭闹钟
[attach]28451[/attach]





作者: Terrance    时间: 2021-3-9 14:01
好顶赞
我好多音响但是没有一个能用hass发声,貌似官方的dlna插件有问题,现在是每隔五分钟由远及近开灯,用灯光唤醒
作者: sephrioth    时间: 2021-3-10 09:29
Terrance 发表于 2021-3-9 14:01
好顶赞
我好多音响但是没有一个能用hass发声,貌似官方的dlna插件有问题,现在是每隔五分钟由远及近开 ...

随便搞个智能音箱就行....  个人比较推荐Sonos, tts完播放音乐一气呵成~
作者: Terrance    时间: 2021-3-10 10:39
sephrioth 发表于 2021-3-10 09:29
随便搞个智能音箱就行....  个人比较推荐Sonos, tts完播放音乐一气呵成~

有yas408 天猫精灵 homepod 和 marshall standmore,之前还有个R1,没有一个能不折腾直接在系统里识别 一直在可用和不可用之间跳
作者: sephrioth    时间: 2021-3-10 11:53
Terrance 发表于 2021-3-10 10:39
有yas408 天猫精灵 homepod 和 marshall standmore,之前还有个R1,没有一个能不折腾直接在系统里识别  ...

我是 amazon alexa echo, google home, sonos...   理论上接入应该都还好吧, 只是作为 media player 的话
作者: Terrance    时间: 2021-3-10 12:47
sephrioth 发表于 2021-3-10 11:53
我是 amazon alexa echo, google home, sonos...   理论上接入应该都还好吧, 只是作为 media player 的 ...

应该还好 就是懒
作者: lhnanyang    时间: 2021-3-12 20:18
我用的自动化创建的脚本,每天太阳升起叫我起床,播报天气,挺爽
作者: 15283928038    时间: 2021-3-14 01:20
不错不错,明天也写个自定义闹钟。
作者: qinima    时间: 2021-3-24 16:30

好顶赞
作者: qazma1452    时间: 2023-2-6 09:28
  理论上接入应该都还好吧, 只是作为 media player 的话




欢迎光临 『瀚思彼岸』» 智能家居技术论坛 (https://bbs.hassbian.com/) Powered by Discuz! X3.5