homeassistant-config-example/scripts.yaml

183 lines
5.9 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 这里是脚本,可以理解为一些组合命令。
# 不同于automation不会自动触发。
# 虽然script也完全可以写到switch里但有时候为了保持switch简单易读就分离出来。
# https://www.home-assistant.io/integrations/script/
# amplifier ==============================
amplifier_volume_up_10_times:
alias: Amplifier Vol Up
sequence:
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- service: switch.turn_on
entity_id: switch.amplifier_volume_up
- delay: 00:00:00
amplifier_volume_down_10_times:
alias: Amplifier Vol Down
sequence:
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- service: switch.turn_on
entity_id: switch.amplifier_volume_down
- delay: 00:00:00
# 发送媒体键 shell command 无法被前端直接调用 套个壳
media_play_pause:
alias: Play Pause
sequence:
- service: shell_command.send_play_pause
media_previous:
alias: Previous
sequence:
- service: shell_command.send_previous_track
media_next:
alias: Next
sequence:
- service: shell_command.send_next_track
# theater mode ==============================
theater_mode_on:
alias: 'Theater Mode ON'
sequence:
# 状态记录器
- service: input_boolean.turn_on
entity_id: input_boolean.theater_mode
# 放下幕布 不灵敏多按几次
- service: switch.turn_on
entity_id: switch.screen
- service: switch.turn_on
entity_id: switch.screen
- service: switch.turn_on
entity_id: switch.screen
- service: switch.turn_on
entity_id: switch.screen
- service: switch.turn_on
entity_id: switch.screen
- delay: 00:00:10
# turn on amplifier
- service: switch.turn_on
entity_id: switch.amplifier_smart
# 打开投影仪 为了保险多按几次
- service: switch.turn_on
entity_id: switch.projector_power
- service: switch.turn_on
entity_id: switch.projector_power
- service: switch.turn_on
entity_id: switch.projector_power
- delay: 00:00:20
# 关灯
- service: switch.turn_off
entity_id: group.light
- delay: 00:00:10
# 关电脑屏幕
- service: switch.turn_off
entity_id: switch.monitor
theater_mode_off:
alias: 'Theater Mode OFF'
sequence:
# 状态记录器
- service: input_boolean.turn_off
entity_id: input_boolean.theater_mode
# 关闭投影仪 为了保险多按几次
- service: switch.turn_off
entity_id: switch.projector_power
- delay: 00:00:01
- service: switch.turn_off
entity_id: switch.projector_power
- delay: 00:00:01
- service: switch.turn_off
entity_id: switch.projector_power
# 开灯 天亮的话就不开
- service_template: > # 太阳落山的话开灯
switch.turn_{% if is_state('sun.sun','below_horizon') %}on{% else %}off{% endif %}
entity_id:
- switch.light_3_smart
# 开电脑屏幕
- service: switch.turn_on
entity_id: switch.monitor
# 收起幕布 不灵敏多按几次
- service: switch.turn_off
entity_id: switch.screen
- service: switch.turn_off
entity_id: switch.screen
- service: switch.turn_off
entity_id: switch.screen
- service: switch.turn_off
entity_id: switch.screen
- service: switch.turn_off
entity_id: switch.screen
# return & leave home actions ==============================
home_return:
alias: 'Return Home'
sequence:
- service: input_boolean.turn_on # 状态记录器
entity_id: input_boolean.at_home
# template 如果没有else会导致异常并中断就要放在最后。
- service_template: > # 太阳落山的话开灯
switch.turn_{% if is_state('sun.sun','below_horizon') %}on{% else %}off{% endif %}
entity_id:
- switch.light_2_smart
- switch.light_3_smart
- service: switch.turn_on
entity_id:
- switch.amplifier_smart # 开功放
- switch.monitor # 开显示器
- switch.aircon_smart
- switch.purifier
- service: shell_command.say_welcome_back # 欢迎问候
- service: shell_command.send_volume_up # wakeup screen
- service: shell_command.open_music_player # 打开播放器
- delay: 00:00:05
- service: shell_command.send_space # 播放(远程电脑上已开启的播放器)
home_leave:
alias: 'Leave Home'
sequence:
- service: input_boolean.turn_off # 状态记录器
entity_id: input_boolean.at_home
- service: shell_command.say_welcome_leave # 欢迎问候
- service: switch.turn_off
entity_id:
- switch.monitor
- switch.amplifier_smart
- switch.water_pump
- switch.aircon_smart
- switch.purifier
- group.light
- service: shell_command.screen_off # 息屏