高木のブログ

Nature RemoのローカルAPIを叩いて家電を操作する

2021/01/15

Nature Remoはアプリなどから操作した際、たとえ家に居たとしてもクラウドAPIを経由して実行される仕様になっている
この仕様のせいで、Nature Remoのクラウドで障害が起きたときに電気が消すことができなくて不便な思いをしたので、次に障害が起きても問題ないようにローカルAPI経由でも家電を操作できるようにしておく

手順

公式ドキュメント: https://local-swagger.nature.global/

Nature RemoのIPアドレスを確認

Instance Nameを特定する

$ dns-sd -B _remo._tcp
Browsing for _remo._tcp
DATE: ---Thu 14 Jan 2021---
21:00:16.807  ...STARTING...
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name
21:00:21.766  Add        2   6 local.               _remo._tcp.          Remo-XXXXXX

IPアドレスを確認

Instance Nameに.localを追加

$ dns-sd -G v4 Remo-XXXXXX.local
DATE: ---Thu 14 Jan 2021---
21:00:47.557  ...STARTING...
Timestamp     A/R    Flags if Hostname                               Address                                      TTL
21:00:47.557  Add 40000002  6 Remo-XXXXXX.local.                     192.168.10.3                                 120

赤外線信号の受信

Nature Remo本体にリモコンで信号を送ったあとに以下を実行する

$ curl -X GET http://192.168.10.3/messages -H "X-Requested-With: curl" -H "Expect:"
{"format":"us","freq":36,"data":[3401,1821,353,516,358,1387,356,506,361,509,360,509,360,510,383,482,353,516,353,516,358,508,358,510,360,509,358,511,350,1391,358,513,363,517,347,524,359,515,358,516,358,516,357,517,361,511,354,519,361,1386,355,517,360,510,348,514,353,516,363,507,358,507,386,483,360,509,359,1384,352,516,380,1361,350,1391,360,1387,361,1384,448,419,358,510,357,1383,360,509,442,1302,394,1354,356,1380,354,1392,358,509,353,1390,392,65535,0,8885,3403,1821,360,506,354,1390,359,509,359,511,358,506,363,507,353,516,360,82,65535,427,356,508,361,510,357,511,454,410,365,504,363,1382,348,524,352,521,352,525,357,520,355,518,356,517,356,515,359,514,361,513,362,1385,351,518,359,512,349,514,360,510,359,510,357,511,454,414,360,507,358,1384,352,517,359,1379,361,1382,360,1387,361,1383,354,515,350,518,360,1383,351,513,353,1392,358,1386,361,1384,358,1385,356,510,382,1360,357,65535,0,8923,3403,1825,349,523,359,1391,356,506,361,511,413,456,358,509,357,510,359,508,352,517,358,507,351,518,360,510,383,486,357,1381,362,508,350,518,358,511,355,511,359,509,353,518,356,511,358,507,361,510,358,1384,359,510,357,509,358,87,65535,422,362,506,361,508,359,507,359,512,358,508,352,1393,356,515,405,1343,358,1385,358,1382,354,1388,360,515,358,516,359,1390,355,511,358,1384,351,1392,358,1385,350,1394,360,509,362,1380,351]}

赤外線信号の送信

受信時に受け取ったものをそのままPOSTで送ってあげればよい

$ curl -X POST http://192.168.10.3/messages -H "X-Requested-With: curl" -H "Expect:" -d '{"format":"us","freq":36,"data":[3401,1821,353,516,358,1387,356,506,361,509,360,509,360,510,383,482,353,516,353,516,358,508,358,510,360,509,358,511,350,1391,358,513,363,517,347,524,359,515,358,516,358,516,357,517,361,511,354,519,361,1386,355,517,360,510,348,514,353,516,363,507,358,507,386,483,360,509,359,1384,352,516,380,1361,350,1391,360,1387,361,1384,448,419,358,510,357,1383,360,509,442,1302,394,1354,356,1380,354,1392,358,509,353,1390,392,65535,0,8885,3403,1821,360,506,354,1390,359,509,359,511,358,506,363,507,353,516,360,82,65535,427,356,508,361,510,357,511,454,410,365,504,363,1382,348,524,352,521,352,525,357,520,355,518,356,517,356,515,359,514,361,513,362,1385,351,518,359,512,349,514,360,510,359,510,357,511,454,414,360,507,358,1384,352,517,359,1379,361,1382,360,1387,361,1383,354,515,350,518,360,1383,351,513,353,1392,358,1386,361,1384,358,1385,356,510,382,1360,357,65535,0,8923,3403,1825,349,523,359,1391,356,506,361,511,413,456,358,509,357,510,359,508,352,517,358,507,351,518,360,510,383,486,357,1381,362,508,350,518,358,511,355,511,359,509,353,518,356,511,358,507,361,510,358,1384,359,510,357,509,358,87,65535,422,362,506,361,508,359,507,359,512,358,508,352,1393,356,515,405,1343,358,1385,358,1382,354,1388,360,515,358,516,359,1390,355,511,358,1384,351,1392,358,1385,350,1394,360,509,362,1380,351]}'
{}

参考


ytkg

Written by ytkg, Twitter, GitHub