熱帯夜に加山雄三の「海その愛」が流れるようにした

**寝れない夜のお供が欲しい**
----------
みなさんは**暑がり**ですか？それとも**寒がり**ですか？
私は**極度の暑がり**です。
夏は冷房がないと寝付くとこすら困難だ。

そんな暑くて寝れない夜に暑い歌を流して眠りの手助けをしてもらおう。

そこで選んだ曲が加山雄三さんの「**海その愛**」だ。


**完成品**
-----------------------
1分おきに気温を確認して音楽を流してくれる。

https://twitter.com/Chanmina_IT/status/1587246429449252865?s=20&t=tt6Am0pu_hrUu2p_h3FJbQ

LINEの画面では
![thumbnail_IMG_3064.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2885188/cc01dced-58fe-cb8d-ffef-0102f4827f46.png)



Node-REDのフローで書き出したものが
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2885188/355f8db7-ccb7-1c4d-f573-1d2d08c21909.png)


初期設定
```json
obniz.display.clear(); // 画面を消去
obnizParts.LM60 = obniz.wired("LM60",{ gnd: 0, output: 1, vcc: 2 }); // 温度センサー
obnizParts.Speaker = obniz.wired("Speaker",{ signal:10, gnd:11 });
```


JSONで書き出したものが
```json
[{"id":"eb0090ab04ec1ed6","type":"obniz-function","z":"5d75aef43dac31d1","obniz":"015034b08e6aa6aa","name":"海その愛","code":"const sleep = (msec) => new Promise(res => setTimeout(res, msec));\n\nobniz.display.clear(); // 画面を消去\nobnizParts.Speaker.play(987); await sleep(600); obnizParts.Speaker.stop(); await sleep(300); \n\"う\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"み\"\nobnizParts.Speaker.play(659); await sleep(400); obnizParts.Speaker.stop(); await sleep(1000); \n\"よ\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"お\"\nobnizParts.Speaker.play(880); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"れ\"\nobnizParts.Speaker.play(987); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"の\"\nobnizParts.Speaker.play(1174); await sleep(600); obnizParts.Speaker.stop(); await sleep(200); \n\"う\"\nobnizParts.Speaker.play(1108); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"み\"\nobnizParts.Speaker.play(1108); await sleep(800); obnizParts.Speaker.stop();await sleep(1000);\n\"よ\"\nobnizParts.Speaker.play(987); await sleep(600); obnizParts.Speaker.stop(); await sleep(300); \n\"う\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"み\"\nobnizParts.Speaker.play(659); await sleep(500); obnizParts.Speaker.stop(); await sleep(1000); \n\"よ\"\nobnizParts.Speaker.play(880); await sleep(300); obnizParts.Speaker.stop(); await sleep(200); \n\"れ\"\nobnizParts.Speaker.play(987); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"の\"\nobnizParts.Speaker.play(1174); await sleep(400); obnizParts.Speaker.stop(); await sleep(200); \n\"う\"\nobnizParts.Speaker.play(1108); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"み\"\nobnizParts.Speaker.play(1108); await sleep(800); obnizParts.Speaker.stop();\n\"よ\"\n","x":560,"y":440,"wires":[["2033b7f633d9ca11"]]},{"id":"15a7c55c6dbf66fe","type":"obniz-repeat","z":"5d75aef43dac31d1","obniz":"","name":"1分おきにチェック","interval":"60000","code":"msg.payload = await obnizParts.LM60.getWait();\n\nreturn msg;","x":110,"y":320,"wires":[["27d1b6d28e674dd6","a927e6867924581c"]]},{"id":"e1fca52b2439e768","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":300,"wires":[]},{"id":"27d1b6d28e674dd6","type":"switch","z":"5d75aef43dac31d1","name":"気温別加山雄三","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"25","vt":"num","v2":"30","v2t":"num"},{"t":"btwn","v":"30","vt":"num","v2":"35","v2t":"num"},{"t":"gt","v":"35","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":320,"y":320,"wires":[["3c13c84537f2ec39"],["55c3ed6b48ad6c2b"],["73f1639a7f82433b"]]},{"id":"3c13c84537f2ec39","type":"function","z":"5d75aef43dac31d1","name":"人間、好きなことをやってる時って光るんだよね。","func":"msg.payload = msg.payload + '度超えてるな。人間、好きなことをやってる時って光るんだよね。'\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":300,"wires":[["e1fca52b2439e768"]]},{"id":"55c3ed6b48ad6c2b","type":"function","z":"5d75aef43dac31d1","name":"自分の性格が、自分の運命を決めるんだ。","func":"msg.payload = msg.payload + \"度です。自分の性格が、自分の運命を決めるんだ。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":340,"wires":[["5110f06dd1a66882"]]},{"id":"73f1639a7f82433b","type":"function","z":"5d75aef43dac31d1","name":"人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。","func":"msg.payload = msg.payload + \"度です。人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":380,"wires":[["fc8af4b6faee882e"]]},{"id":"5110f06dd1a66882","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":340,"wires":[]},{"id":"fc8af4b6faee882e","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":380,"wires":[]},{"id":"a927e6867924581c","type":"switch","z":"5d75aef43dac31d1","name":"25度以上強制「海その愛」","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"25","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":440,"wires":[["eb0090ab04ec1ed6"]]},{"id":"2033b7f633d9ca11","type":"debug","z":"5d75aef43dac31d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":440,"wires":[]},{"id":"015034b08e6aa6aa","type":"obniz","obnizId":"","deviceType":"obnizboard","name":"","accessToken":"","code":"obniz.display.clear(); // 画面を消去\nobnizParts.LM60 = obniz.wired(\"LM60\",{ gnd: 0, output: 1, vcc: 2 }); // 温度センサー\nobnizParts.Speaker = obniz.wired(\"Speaker\",{ signal:10, gnd:11 });"}]
```
**ユーザー環境・言語等**
--------------
Node-RED v2.2.3
LINEBot
JavaScript

電子パーツ
-------------
Obniz Board 1Y
高精度IC温度センサ LM60BIZ
スピーカー


**まずObnizに「海その愛」を流させる**
-----------------------
Obnizから音楽を流すためには一音一音入力しないといけないという**非常に地味な作業**に入る。

まず**楽譜の確保**からだが、すべて有料であった。金は払いたくない。
そこで[楽譜@ELISE](https://www.at-elise.com/elise/JPDPHA00682/)のサンプルの合間を見ながら楽譜を完成させた。

しかし、楽譜が読めない。

そこで[【楽譜が読めない人必見】楽譜の読み方をお教えします！](https://komiura.com/score/#:~:text=%E6%A5%BD%E8%AD%9C%E3%81%AE%E8%AA%AD%E3%81%BF%E6%96%B9%EF%BC%81%20%E3%80%9C%E3%83%88%E9%9F%B3%E8%A8%98%E5%8F%B7%E3%81%A8%E3%83%98%E9%9F%B3%E8%A8%98%E5%8F%B7%E3%80%9C%20%E6%A5%BD%E8%AD%9C%E3%81%AB%E3%81%AF%E4%B8%BB%E3%81%AB%20%E3%83%88%E9%9F%B3%E8%A8%98%E5%8F%B7%20%E3%81%A8%20%E3%83%98%E9%9F%B3%E8%A8%98%E5%8F%B7%20%E3%81%A8%E3%81%84%E3%81%86%E8%A8%98%E5%8F%B7%E3%81%8C%E4%BD%BF%E3%82%8F%E3%82%8C%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%20%E3%81%A8%E3%80%81%E6%A5%BD%E5%99%A8%E3%81%AB%E3%82%88%E3%81%A3%E3%81%A6%E5%BE%97%E6%84%8F%E3%81%AA%E9%9F%B3%E3%81%AE%E9%AB%98%E3%81%95%E3%81%8C%E7%95%B0%E3%81%AA%E3%82%8B%E3%81%AE%E3%81%A7%E3%80%81%E3%81%9D%E3%82%8C%E3%81%AB%E3%82%88%E3%81%A3%E3%81%A6,%E3%81%B8%E9%9F%B3%E8%A8%98%E5%8F%B7%20%E3%82%92%E4%BD%BF%E3%81%84%E5%88%86%E3%81%91%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%20%E3%83%94%E3%82%A2%E3%83%8E%E3%81%AF%E4%B8%A1%E6%89%8B%E3%81%A7%E4%BD%8E%E3%81%84%E9%9F%B3%E3%81%8B%E3%82%89%E9%AB%98%E3%81%84%E9%9F%B3%E3%81%BE%E3%81%A7%E5%BC%BE%E3%81%8F%E3%81%9F%E3%82%81%E3%80%81%E3%81%AA%E3%82%93%E3%81%A8%E3%81%A9%E3%81%A1%E3%82%89%E3%81%AE%E8%A8%98%E5%8F%B7%E3%82%82%E5%87%BA%E3%81%A6%E3%81%8D%E3%81%BE%E3%81%99%E3%80%82%20%E3%81%97%E3%81%8B%E3%82%82%E5%90%8C%E6%99%82%E3%81%AB%E8%AA%AD%E3%82%93%E3%81%A7%E3%81%84%E3%81%8B%E3%81%AA%E3%81%8F%E3%81%A6%E3%81%AF%E3%81%AA%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%20%E6%A5%BD%E5%99%A8%E3%81%AE%E7%8E%8B%E6%A7%98%E3%81%A8%E8%A8%80%E3%82%8F%E3%82%8C%E3%82%8B%E3%81%A0%E3%81%91%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%81%AD%E2%80%A6%E2%80%A6%20%E4%B8%8B%E3%81%8C%20%E3%81%B8%E9%9F%B3%E8%A8%98%E5%8F%B7%20%E3%81%A7%E3%81%99%E3%80%82)と[音階と周波数の関係（平均律一覧表）](https://composer-instruments.com/scale-and-frequency/)の二つのサイトを駆使して、Obniz 1Y用の**ヘルツ楽譜**を作り上げた。

この１フレーズを完成させるのだけでも一苦労。大変だから今回は「海よ俺の海よ～ 大きなその愛よ～」だけ流れることにする。

こんないい歌を1フレーズだけ流すのは逆に冒涜だった。


**熱帯夜だけ流させる**
-----------------------
安眠しているときには流れないようにしたいので、暑くて寝れない**熱帯夜**にだけ流れるように設定する。

そのためには**高精度IC温度センサ LM60BIZ**を使って25度以上の時にだけ音楽が流れるようにNode-Redで設定する。

**加山雄三風のlineからメッセージが来る**
-----------------------
今回は気温別に合わせて加山雄三の格言３つが送られてくるようにする。

フローがこちら
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2885188/6c3b3a1a-b849-b6a1-d6f9-5777fc637aad.png)

JSONはこちら
```json
[{"id":"e3dc16adc145302b","type":"PushMessage","z":"c82121acc2e0e415","name":"","x":1000,"y":400,"wires":[]},{"id":"dd7e2b4de0965d56","type":"switch","z":"c82121acc2e0e415","name":"気温別加山雄三","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"25","vt":"num","v2":"30","v2t":"num"},{"t":"btwn","v":"30","vt":"num","v2":"35","v2t":"num"},{"t":"gt","v":"35","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":180,"y":420,"wires":[["1af9dc9425e6e90f"],["a2f5013013e78156"],["9a21d0b5bbe8723d"]]},{"id":"1af9dc9425e6e90f","type":"function","z":"c82121acc2e0e415","name":"人間、好きなことをやってる時って光るんだよね。","func":"msg.payload = msg.payload + '度超えてるな。人間、好きなことをやってる時って光るんだよね。'\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":400,"wires":[["e3dc16adc145302b"]]},{"id":"a2f5013013e78156","type":"function","z":"c82121acc2e0e415","name":"自分の性格が、自分の運命を決めるんだ。","func":"msg.payload = msg.payload + \"度です。自分の性格が、自分の運命を決めるんだ。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":440,"wires":[["40eb03b09258db8c"]]},{"id":"9a21d0b5bbe8723d","type":"function","z":"c82121acc2e0e415","name":"人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。","func":"msg.payload = msg.payload + \"度です。人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":480,"wires":[["afe0a3b8d5392ce4"]]},{"id":"40eb03b09258db8c","type":"PushMessage","z":"c82121acc2e0e415","name":"","x":1000,"y":440,"wires":[]},{"id":"afe0a3b8d5392ce4","type":"PushMessage","z":"c82121acc2e0e415","name":"","x":1000,"y":480,"wires":[]}]
```
最後にこれをObnizの処理と組み合わせる。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2885188/2f87a37b-ddc9-6a5a-f603-53c63ca17887.png)

```json
[{"id":"eb0090ab04ec1ed6","type":"obniz-function","z":"5d75aef43dac31d1","obniz":"015034b08e6aa6aa","name":"海その愛","code":"const sleep = (msec) => new Promise(res => setTimeout(res, msec));\n\nobniz.display.clear(); // 画面を消去\nobnizParts.Speaker.play(987); await sleep(600); obnizParts.Speaker.stop(); await sleep(300); \n\"う\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"み\"\nobnizParts.Speaker.play(659); await sleep(400); obnizParts.Speaker.stop(); await sleep(1000); \n\"よ\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"お\"\nobnizParts.Speaker.play(880); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"れ\"\nobnizParts.Speaker.play(987); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"の\"\nobnizParts.Speaker.play(1174); await sleep(600); obnizParts.Speaker.stop(); await sleep(200); \n\"う\"\nobnizParts.Speaker.play(1108); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"み\"\nobnizParts.Speaker.play(1108); await sleep(800); obnizParts.Speaker.stop();await sleep(1000);\n\"よ\"\nobnizParts.Speaker.play(987); await sleep(600); obnizParts.Speaker.stop(); await sleep(300); \n\"う\"\nobnizParts.Speaker.play(659); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"み\"\nobnizParts.Speaker.play(659); await sleep(500); obnizParts.Speaker.stop(); await sleep(1000); \n\"よ\"\nobnizParts.Speaker.play(880); await sleep(300); obnizParts.Speaker.stop(); await sleep(200); \n\"れ\"\nobnizParts.Speaker.play(987); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"の\"\nobnizParts.Speaker.play(1174); await sleep(400); obnizParts.Speaker.stop(); await sleep(200); \n\"う\"\nobnizParts.Speaker.play(1108); await sleep(200); obnizParts.Speaker.stop(); await sleep(200); \n\"み\"\nobnizParts.Speaker.play(1108); await sleep(800); obnizParts.Speaker.stop();\n\"よ\"\n","x":560,"y":440,"wires":[["2033b7f633d9ca11"]]},{"id":"804ddd3a5970cc82","type":"debug","z":"5d75aef43dac31d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":240,"wires":[]},{"id":"17756f343dd5498a","type":"obniz-function","z":"5d75aef43dac31d1","obniz":"","name":"","code":"msg.payload = \"finish\";\nawait obniz.wait(1000); \nobniz.close();\n\nreturn msg;","x":520,"y":240,"wires":[["804ddd3a5970cc82"]]},{"id":"9f841fb91e320531","type":"inject","z":"5d75aef43dac31d1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":340,"y":240,"wires":[["17756f343dd5498a"]]},{"id":"15a7c55c6dbf66fe","type":"obniz-repeat","z":"5d75aef43dac31d1","obniz":"","name":"1分おきにチェック","interval":"60000","code":"msg.payload = await obnizParts.LM60.getWait();\n\nreturn msg;","x":110,"y":320,"wires":[["27d1b6d28e674dd6","a927e6867924581c"]]},{"id":"e1fca52b2439e768","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":300,"wires":[]},{"id":"27d1b6d28e674dd6","type":"switch","z":"5d75aef43dac31d1","name":"気温別加山雄三","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"25","vt":"num","v2":"30","v2t":"num"},{"t":"btwn","v":"30","vt":"num","v2":"35","v2t":"num"},{"t":"gt","v":"35","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":320,"y":320,"wires":[["3c13c84537f2ec39"],["55c3ed6b48ad6c2b"],["73f1639a7f82433b"]]},{"id":"3c13c84537f2ec39","type":"function","z":"5d75aef43dac31d1","name":"人間、好きなことをやってる時って光るんだよね。","func":"msg.payload = msg.payload + '度超えてるな。人間、好きなことをやってる時って光るんだよね。'\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":300,"wires":[["e1fca52b2439e768"]]},{"id":"55c3ed6b48ad6c2b","type":"function","z":"5d75aef43dac31d1","name":"自分の性格が、自分の運命を決めるんだ。","func":"msg.payload = msg.payload + \"度です。自分の性格が、自分の運命を決めるんだ。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":340,"wires":[["5110f06dd1a66882"]]},{"id":"73f1639a7f82433b","type":"function","z":"5d75aef43dac31d1","name":"人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。","func":"msg.payload = msg.payload + \"度です。人が喜ぶことを、本気になってやろう。それが自分自身の幸せでもある。。\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":380,"wires":[["fc8af4b6faee882e"]]},{"id":"5110f06dd1a66882","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":340,"wires":[]},{"id":"fc8af4b6faee882e","type":"PushMessage","z":"5d75aef43dac31d1","name":"","x":1140,"y":380,"wires":[]},{"id":"a927e6867924581c","type":"switch","z":"5d75aef43dac31d1","name":"25度以上強制「海その愛」","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"25","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":440,"wires":[["eb0090ab04ec1ed6"]]},{"id":"2033b7f633d9ca11","type":"debug","z":"5d75aef43dac31d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":440,"wires":[]},{"id":"015034b08e6aa6aa","type":"obniz","obnizId":"","deviceType":"obnizboard","name":"","accessToken":"","code":"obniz.display.clear(); // 画面を消去\nobnizParts.LM60 = obniz.wired(\"LM60\",{ gnd: 0, output: 1, vcc: 2 }); // 温度センサー\nobnizParts.Speaker = obniz.wired(\"Speaker\",{ signal:10, gnd:11 });"}]
```

**結論**
-----------------------
余計寝れなくなった。1分おきに流れる音楽に気が狂いそうになる最悪の結果に。

当初の予定とは逆の結論に至ってしまった。出来たら意外と何とか実用できると思っていたが、その予想が外れることになるとは思わなかった。