食洗機かけ終わったかわからなくなる問題を RaspberryPI + BlueButton + LINE Notify + Google Home で解決した話

食洗機かけ終わったかわからなくなる問題を RaspberryPI + BlueButton + LINE Notify + Google Home で解決した話

概要

食洗機かけ終わったかどうかわからなくなる問題が我が家で多発していました。

それを RaspberryPI + BluetButton + LINE Notify + Google Home で解決した話です。

何が問題?

我が家では、食洗機がある程度溜まったらかける、という風にしている為、必ずかける時間が決まっていません。

その為、時折、妻or自分が食洗機を引き出した時に、「これ洗ったやつだっけ?」と疑心暗鬼・一触即発状態となり、 駆け寄った息子にドラゴンストップしていただく事態が多発していました。

記録が取れる様な仕組み、何か見ればわかる!
という状態にさえしといてもらえたら助かる、ということでエンジニアリングで解決できないか、と考えました。

解決法

開始した時刻を LINE グループに通知して記録する様にしました。*1

その通知の仕組みをボタンを一押しで済ませられる様な、シンプルなものにできないか、と考え、
家にある Raspberry PI と組み合わせられる BlueButton で実装しようと考えました。

仕組み

  1. 食洗機を開始したら、BlueButton を押す
  2. BlueButton を押すと Bluetooth ペアリングしている Raspberry PI にボタン押したよ情報を渡す。
  3. Raspberry PI 側で起動させておいた BlueButton が押されたか判定するスクリプトが検知
  4. 3をトリガーに LINE Notify で LINE に通知。
  5. 3をトリガーに Google Home に食洗機開始したよメッセージを喋ってもらう。*2

押す長さによって処理分けしています。

  • 長押し=食洗機開始をGoogle Home, Line へ通知
  • 短押し=食洗機開始時刻読み上げ

購入したもの

Raspberry Pi 3 Model B V1.2 (日本製) 国内正規代理店品

Raspberry Pi 3 Model B V1.2 (日本製) 国内正規代理店品

Google Home

Google Home

BlueButton は Amazon で 100 円程度でした♪ お財布に優しい!

Google Home はあくまでスピーカー代わりでボタンが押された時の確認用として使ってます。
USB スピーカーを接続するでも、Lチカで反応させる、でも確認できるものがあれば、それで良いと思います。

Raspberry PI でのセットアップ

Raspberry PI 情報

$ uname -a

Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

事前準備

  • LINE Notify に Signup し token 生成します。
    LINE Notify

  • BlueButton を Bluetooth ペアリングしときます。

ペアリングは既にいくつも記事があります。以下記事参考になるかと思います。
Bluetoothシャットダウンボタンを作る #300円でIoTボタン

google-home-notifiler インストール

  • nodejs, npm インストール
pi$ sudo apt-get update
pi$ sudo apt-get install -y nodejs npm
pi$ sudo npm cache clean
pi$ sudo npm install npm n -g
pi$ sudo n stable
  • google-home-notifiler 設定
pi$ cd ~
pi$ git clone https://github.com/noelportugal/google-home-notifier
pi$ cd google-home-notifier/
pi$ npm install
  • example.js 編集
...
const serverPort = 8091; // default port

+ var deviceName = 'ファミリールーム'; // Google Home's device name
+ var ip = '<Google Home's IP>'; // ex. 192.168.11.5
...

Google Home's IP の確認はこちら

google-home-notifler サーバ起動スクリプト作成

  • /etc/systemd/system/googlehomenotifier.service
[Unit]
Description=google-home-notifier Server
After=syslog.target network-online.target

[Service]
Type=simple
User=root
ExecStart=/usr/bin/node example.js
Restart=on-failure
RestartSec=10
KillMode=process
WorkingDirectory=/home/pi/google-home-notifier

[Install]
WantedBy=multi-user.target

上記追加後、daemon-reload し、`googlehomenotifier.service` を認識させます。

pi$ sudo systemctl daemon-reload

いざ google-home-notifiler 起動

pi$ sudo systemctl start google-home-notifiler

試しに hello と言わせる ♪

pi$ curl -X POST -d "text=hello" https://127.0.0.1:8091/google-home-notifier

BlueButton セットアップ

pi$ sudo gem install bluebutton

食洗機 Notify スクリプト インストール

元々 python で書きましたが、shell の方が速度が出たので shell にしています。

pi$ cd ~
pi$ git clone https://github.com/kenzo0107/dishwasher
  • dishwasher.sh の以下箇所を先に生成したものと変更してください。
readonly LINENOTIFY_TOKEN="<please change yours>"

起動スクリプト設定 & 実行

pi$ sudo cp bluebutton.service /etc/systemd/system/
pi$ sudo systemctl daemon-reload
pi$ sudo systemctl start bluebutton.service

いざ実行

できました♪

BlueButton についてちょっとだけ注意

BlueButton のボタンのトリガーの種類は以下ですが、

  • key down ボタンを押す
  • key up 押したボタンを離す
  • long key down ボタン長押し
  • long key up 長押しボタンを離す

long key down (長押し)していると、まず最初に key down イベントが発生し、その後、 long key down のイベント発生となります。

key down イベントに渡した処理がある場合、
long key down のイベントに渡した処理のみを実行する、
というのはできないので注意が必要です。

総評

食洗機開始ボタンができたおかげで家庭から争いがなくなり
イヤイヤ期だった息子も朗らかになった様に思います。

是非イヤイヤ期の子供と食洗機問題を抱えている方のお力になれば何よりです。

以上です。

*1:curl 叩ければ、後々 Slack でも何でも、家族みんなが見る所に通知すれば良いかなと思ったので

*2:Google Home はあくまでスピーカー代りです。

食洗機かけ終わったかわからなくなる問題を RaspberryPI + BlueButton + LINE Notify + Google Home で解決した話

https://kenzo0107.github.io/2018/08/19/2018-08-20-raspberrypi-bluebutton-line-notify-google-home/

Author

Kenzo Tanaka

Posted on

2018-08-20

Licensed under

コメント