Created
December 8, 2017 02:21
-
-
Save willwhui/b4a365416881f3dc4a26bbeeea49ec7e to your computer and use it in GitHub Desktop.
This file contains 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
利用人体感应器制作一个提醒休息的工具 |
利用input_number实现计时器
以定时30分钟为例
- 启动计时器时,将input_number设定为1
- 启动一个automation,每隔1分钟将input_number+1
- 启动一个automation,每隔1分钟检查一次,如果input_number=30,就发起TTS,并将input_number重置为0
- 每当hass启动时,如果input_number != 0,则认为timer需要继续
示例
设置一个input_number作为计数器
实际使用的时候,每分钟+1
start_work_timer:
name: 'Start work timer'
# do not set a initial value,
# because this will cause it be initialized at every restart of hass.
# without this setting, hass will reload the last value it was, or set to '0' if it is the very first time initializing for it
# initial: 0
min: 0
max: 100
step: 1
注意,initial千万不要设置,否则每次重启的时候都会被设置为这个初始值。第一次启用这个number的时候,系统会将它设置为0
设置一个input_boolean作为flag
start_work:
name: "Work"
initial: off
icon: mdi:worker
便于通过Alexa语音控制,也是一个显式的标记。
同时也是一个被automation触发器监视的状态点。
启动
- alias: "Set working timer by motion: trigger set flag up by motion"
#hide_entity: true
trigger:
- platform: event
event_type: motion
event_data:
entity_id: !secret motion_sensor_1_id
condition:
condition: and
conditions:
- condition: numeric_state
entity_id: input_number.start_work_timer
below: 1 # less than 1 means no working timer now
- condition: state
entity_id: automation.tts_for_take_a_walk_repeating
state: 'off' # only set a timer while there is not a repeating tts current
action:
- service: input_boolean.turn_on # set flag up
entity_id: input_boolean.start_work
- alias: "Set working timer by motion: trun on"
initial_state: true
#hide_entity: true
trigger:- platform: state
entity_id: input_boolean.start_work
to: 'on'
condition:
condition: and
conditions: - condition: numeric_state
entity_id: input_number.start_work_timer
below: 1 # less than 1 means no working timer now - condition: state
entity_id: automation.tts_for_take_a_walk_repeating
state: 'off' # no repeating tts means no working timer now
action: - service: input_number.set_value
data:
entity_id: input_number.start_work_timer
value: 1 # inital start value - service: automation.turn_on # start counting
entity_id: automation.set_working_timer_by_motion_counting - service: media_player.turn_on # prompt started
entity_id: !secret current_media_player_id - delay: "00:00:03" # left some time for divice response
- service: tts.google_say
entity_id: !secret current_media_player_id
data:
message: "A start work timer started!"
- platform: state
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
目标2:难点在于找一个地方存储当前状态,以便于重启后能续上时间
但实际上不可以: home-assistant/core#10994
看起来用input-number + recorder来做最靠谱
它们可以restore重启之前的数据
https://home-assistant.io/components/input_number/
https://home-assistant.io/components/recorder/
经过简单的测试,并不需要指明使用recorder,input_number就已经可以自动restore_state了