Last active
December 8, 2017 02:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
在hass上检测通过Google Home生成的Google Calendar Event |
利用timer组件达到TTS重复发声的目的
timer官方文档: https://home-assistant.io/components/timer/
设计思路:
- automation1: "TTS on event (speak and start timer) "
trigger: 当日历事件
action:
触发automation之后发声,
并触发一个timer: timer_for_repeat_tts_on_google_calender_event
并设定一个标记为on - automation2: "TTS on timer (speak and start timer again)"
trigger: timer_for_repeat_tts_on_google_calender_event
condition: 标记是否已经off
action:
发声
并重启timer_for_repeat_tts_on_google_calender_event
那么,如何设定一个可以on/off的标记呢?
设计思路:
在automation1中设定一个标记,比如一个智能插座(或灯)。
这个标记将成为automation2的执行条件
手动关闭这个插座或灯,就可以结束automation2导致的循环
设置timer
timer的配置文件和常见的书写方式略有不同:
设置多个timer,必须得这样:
timer_for_repeat_tts_on_google_calender_event:
duration: '00:01:00'
timer_for_repeat_tts_on_google_calender_event_2:
duration: '00:01:00'
不能用 "-"那种模式
最终完成重复TTS配置如下
timer:
timer_for_repeat_tts_take_a_walk:
duration: '00:00:10'
automation:
################################################################
# begin : automation for "stop working, take a walk"
- alias: "TTS on event (speak and start timer): stop working, take a walk"
trigger:
platform: state
entity_id: calendar.start_work
from: 'on'
to: 'off' # stop working
action:
- service: tts.google_say
entity_id: media_player.living_room_home
data:
message: "Time to take a walk, human!"
- service: switch.turn_on # set the signal on
entity_id: switch.orange_orvibo_wifi_socket
- service: timer.start # start the timer for repeat
entity_id: timer.timer_for_repeat_tts_take_a_walk
- alias: "TTS on timer (speak and start timer again): stop working, take a walk"
trigger:
platform: state
entity_id: timer.timer_for_repeat_tts_take_a_walk
to: 'idle' # time up
condition:
condition: state
entity_id: switch.orange_orvibo_wifi_socket
state: 'on' # repeat if signal is on
action:
- service: tts.google_say
entity_id: media_player.living_room_home
data:
# message: "Time to take a walk, human!"
message: "喂!够了够了,必须站起来走走了!"
language: "zh"
- service: timer.start # start this timer again
entity_id: timer.timer_for_repeat_tts_take_a_walk
# end : automation for "stop working, take a walk"
################################################################
不足的地方:
- event 下发不及时
说检查状态的间隔时间是15分钟 - event 无法在通过google home设定时间周期,总是默认1小时长度
最终发现,在这个案例中,可以通过设置开始时间为 "20 minutes ago"来控制总时长 - event 状态有时候不更新
原因未知。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
先track一个event
通过测试发现,通过google home设定的event是出现在默认的日历里面的。
设定好要监控的日历event:
设定好automation:
重启hass。
时间到了之后,什么都没发生。
哪里出了错?
但是到了预定触发时间点之后的1分钟,触发了!
尝试说出中文
google tts号称支持的语言:
https://cloud.google.com/speech/docs/languages
但里面的“cmn-Hans-CN”这样的写法并不被google支持,会报错。
上文链接中说用到了这里的规定:
https://tools.ietf.org/html/bcp47
那么language参数的正确写法,中文很可能是"language:zh"
所以可以把action的data改成这样:
结果证明是可以的。
通过google搜索还可以找到这里的使用案例:pndurette/gTTS#31