美文网首页
Home Assistant 早上定时随机播放网易云音乐

Home Assistant 早上定时随机播放网易云音乐

作者: 一只特例独行de猪 | 来源:发表于2018-06-14 03:47 被阅读0次

安装个人修改版的musicbox和tmux

sudo apt-get install tmux
sudo apt-get install mpg123
git clone https://github.com/cloudswave/musicbox.git
cd musicbox 
python setup.py install

可以手动在终端测试播放器是否正常:musicbox -c "?",这个命令会随机开始播放音乐。
tmux的作用是模拟终端session在后台播放音乐。

配置shell_command 、触发器和动作

# configuration.yaml
shell_command:
    musicbox_play: su - pi -c 'tmux new-session -d -s  musicbox musicbox -c "?"' # 需要使用pi用户执行,否则播放不出声音
    musicbox_kill: su - pi -c 'tmux kill-session -t musicbox'

group     : !include groups.yaml
automation: !include automations.yaml
script    : !include scripts.yaml

logger:
  default: info
  logs:
    homeassistant.components.shell_command: info

# automations.yaml 中添加触发器和动作
# 播放        
- alias: musicbox_play
  trigger: # 每天早上8.30开始播放随机音乐
      platform: time
      hours: 8
      minutes: 30
      seconds: 0
  action:
    service: shell_command.musicbox_play
    
- alias: musicbox_stop
  trigger:
      platform: time
      hours: 10
      minutes: 30
      seconds: 0
      
  action:
    service: shell_command.musicbox_kill

重启hass服务

重启服务后可以手动触发自动化测试即可!


image.png

相关文章

网友评论

      本文标题:Home Assistant 早上定时随机播放网易云音乐

      本文链接:https://www.haomeiwen.com/subject/saheeftx.html