[iOS][Raspberry Pi] X分後にアラーム

iOS から 25 分後に Raspberry Pi の音声ファイルを再生する方法について以前書いた。

[iOS][Raspberry Pi] 25 分後にアラーム – with a Christian Wife
https://wacw.cf/2018/12/06/alarm-in-25min-with-pi-and-ios/

さらに改良して、シェルスクリプトを使わず、さらにアラームの再生までの時間を自由に指定できるようになった。

これまで at コマンドはスクリプトの実行するしかやり方が分からなかったが(-f オプションでシェルスクリプトを指定する)、直接コマンドを指定する方法が分かった。すなわち、以下のようにする。

$ echo "[コマンド]" | at now +25minutes

これで 25 分後にコマンドを実行できる($ at now +25minutes < "[コマンド]" という書き方もあるようだが、実際は動かなかった)。

参考:
atコマンドの使い方(指定時間にコマンドを実行する)でスケジュール実行。 - それマグで!
http://takuya-1st.hatenablog.jp/entry/20120503/1336036427

iOS のショートカットで 25 分ではなく、プロンプトを毎回表示してアラームまでの時間を指定するには以下のようにする。

(1)ショートカットに Ask for Input を追加。

Question:何分後に通知?
Default Answer:25
Input Type:Number

(2)さらに Get Text from Input を追加。

(3)さらに Run Script Over SSH を追加。

Host:Raspberry Pi の IP アドレス、あるいはホスト名
Port:22
User:Raspberry Pi のユーザー名
Password:Raspberry Pi のパスワード
コマンド:echo “mpg321 documents/alarm.mp3” | at now +[Text]minutes([Text]部分は変数)

参考:
Raspberry Pi のタクトスイッチ(複数個)を押すと Slack に通知する – with a Christian Wife
https://wacw.cf/2018/02/28/tactswitdch-to-slack-with-raspberry-pi/

[Raspberry Pi] 25 分後にアラーム – with a Christian Wife
https://wacw.cf/2018/06/21/alarting-in-25min-with-pi/