ã¹ãã¼ããªã¢ã³ã³ããã¤ã¹ã¨ãã¦æå㪠IRKit ã®å¾ç¶ã¨ãã¦å»å¹´çºå£²ããã NatureRemo ã§ãããå æ¥ã¤ãã« NatureRemo ã® API ãå ¬éããã¾ããã
ãã¬ãã®ãã£ã³ãã«ã HDMI4 ã«ããããã«ã¯ãè¤æ°åã®ãªã¢ã³ã³æä½ãé£ç¶çã«è¡ãªãå¿ è¦ãããã IRKit ã®é 㯠API ã使ããã¨ã§å®ç¾ã§ãã¦ããã®ã§ããã NatureRemo ã¯çºå£²å½å API ãå ¬éããã¦ããªãã£ãçºåºæ¥ã¦ãã¾ããã§ããããã®ãããæã家ã®ãªãã³ã°ã«ã¯ NatureRemo ã¨ãé£ç¶æä½ç¨ã« IRKit ãè¨ç½®ããã¦ãã¾ãããã NatureRemo ã API 対å¿ããçµæ IRKit ãæ¤å»ãããã¨ãåºæ¥ã¾ãã (å®éã«ã¯å¯å®¤ã«æã£ã¦ããã¾ãã) ã
Cloud API 㨠Local API ã«ã¤ãã¦
NatureRemo ã«ã¯ Cloud API 㨠Local API ããããã¤ã³ã¿ã¼ãããè¶ãã«ãªã¯ã¨ã¹ãããå ´å㯠Cloud API ã使ãã¾ãã
Cloud API ã¨ã¯èªå® ã«ãã NatureRemo ããã¤ã¹ãã¤ã³ã¿ã¼ãããè¶ãã«æä½ãããã¨ã®åºæ¥ã API ã§ãããã®æ©è½ãæ㤠Cloud API 㯠IRKit ã®é ããããã¾ãããã NatureRemo ã§ã¯ãªã¢ã³ã³æ å ±ãè¨æ¶ãããã¨ãã§ããããã«ãªã£ã¦ããã®ã§ãä¾ãã°ç»é²ãããªã¢ã³ã³ ID ã API ã§å¼ã³åºãã ãã§ãªã¢ã³ã³æä½ãè¡ãªããããã«ãªã£ã¦ãã¾ã (IRKit ã®ããã¯èµ¤å¤ç·ãã¼ã¿ã Cloud ã«ä¿åãã¦ããªãã®ã§ API ã§èµ¤å¤ç·ãã¼ã¿ãéãå¿ è¦ããã£ã) ã
Local API ã¨ã¯ãåãã»ã°ã¡ã³ãå ããå¼ã³åºãã API ã§ãããã㯠IRKit ãæã£ã¦ãã人ã«ã¯é¦´æã¿æ·±ãã®ã§ã¯ç¡ãã§ãããããå ã»ã©è¿°ã¹ããªã¢ã³ã³æ å ±ã¯ Cloud å´ã«æã£ã¦ããã®ã§ã Local API ã§ã¯ IRKit ã¨åãããã«ã赤å¤ç·ä¿¡å·ãéä¿¡ããããç´åã«è¨å®ãã赤å¤ç·ä¿¡å·ã®æ å ±ãè¿å´ãããã® 2 ã¤ã®æ©è½ã®ã¿ã¨ãªã£ã¦ãã¾ãã
æä½ããããªã¢ã³ã³ãç»é²ãã
ã¹ããã¢ããªã§ãªã¢ã³ã³ãç»é²ãã¦ããã¾ããããã§ç»é²ãããªã¢ã³ã³æ å ±ã¯ã¢ããªãã®ãã®ã IFTTT ããå©ç¨ã§ãã¾ããã Cloud API ãããå©ç¨ãããã¨ãåºæ¥ã¾ãã
Cloud API ã® access token ãåå¾ãã
ãã® token 管çãµã¼ãã¹ã«ãã¹ããã¢ããªã§ä½æãã NatureRemo ã¢ã«ã¦ã³ããå©ç¨ãã¦ãã°ã¤ã³ãã㨠access token ãçºè¡ãããã¨ãåºæ¥ã¾ãã ãã§ã«ã IFTTT ã Google Home ãªã©ã§å©ç¨ãã¦ããå ´åã¯ç»é¢ã«è¡¨ç¤ºããã¦ããã¨æãã¾ãããééã㦠Revoke ãããªãããã«ãã¦ãã ããã
çæãã access token 㧠Cloud API ãå¼ã³åºã
æ£ãã access token ã使ããããã¾ãã¯æå
㧠curl
ã使ã£ã¦ç¢ºèªãã¦ã¿ã¾ãããã {YOUR_ACCESS_TOKEN}
ã®é¨åãå
ã»ã©åå¾ãã token ã«ç½®ãæãã¦æ¬¡ã®ã³ãã³ããå®è¡ãã¾ãã
curl -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" "https://api.nature.global/1/users/me"
{"id":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","nickname":"shunirr"}
ãã®ããã« Response ãè¿ã£ã¦ããã°æåã§ãã
ãªã¢ã³ã³æ å ±ã®ä¸è¦§ãåã
以ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
curl -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" "https://api.nature.global/1/appliances"
ç»é²ãã¦ãããªã¢ã³ã³æ°ãå¤ãã¨ã¬ã¹ãã³ã¹ã大ãããªãã¾ãããé©å® jq
ãªã©ã§è¦æããã¦ã¿ã¦ãã ããã
[ { "id": "APPLIANCE_ID", "device": { "name": "Remo", "id": "DEVICE_ID", "created_at": "2017-10-20T01:31:04Z", "updated_at": "2018-02-10T14:34:48Z", "firmware_version": "Remo/1.0.62-gabbf5bd", "temperature_offset": 0, "humidity_offset": 0 }, "model": null, "nickname": "ãã¬ã", "image": "ico_tv", "type": "IR", "settings": null, "aircon": null, "signals": [ { "id": "550e8400-e29b-41d4-a716-446655440000", "name": "é»æºãªã³ãªã", "image": "ico_io" }, { "id": "550e8400-e29b-41d4-a716-446655440001", "name": "å ¥ååæ¿", "image": "ico_display" }, { "id": "550e8400-e29b-41d4-a716-446655440002", "name": "å°ä¸æ³¢", "image": "ico_display" }, { "id": "550e8400-e29b-41d4-a716-446655440003", "name": "ãã¥ã¼ã", "image": "ico_display" }, ...
id
ã®é¨åã¯ä¼ãã¦ããã¾ãããã ããããããªæãã«ãªãã¨æãã¾ãã signals ã® item å
ã® id ãå©ç¨ãããã¨ã§ Cloud API ãããªã¢ã³ã³ãæä½ãããã¨ãåºæ¥ã¾ãã
API ãããªã¢ã³ã³èµ¤å¤ç·ãéä¿¡ãã
éä¿¡ããããªã¢ã³ã³ããã¬ãã®ãé»æºãªã³ãªããã ã£ãå ´åã«ã¯ã 550e8400-e29b-41d4-a716-446655440000
ã¨ãã ID ã¨ãããã¨ãåããã¾ãã®ã§ããããéä¿¡ãã¦ã¿ã¾ãããã
curl -X POST "https://api.nature.global/1/signals/550e8400-e29b-41d4-a716-446655440000/send" -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}"
{}
å®éã«ãã¬ãã®é»æºããªã³ãªãããããæåã§ãã
Google Apps Script ã§ãªã¢ã³ã³ãè¤æ°åæä½ãã API ãä½ã
ãã¦ãç§ãæã£ã¦ãããã¬ãã§ã¯ HDMI4 ã«ããããã«ã¯ãå°ãã¸ããå ¥ååæ¿ããå ¥ååæ¿ããå ¥ååæ¿ããå ¥ååæ¿ãã¨æ¼ãã¦ãããã¨ã§ãã©ã®ãã£ã³ãã«ã«ãã¦ã HDMI4 ã«ã§ãã¾ããã NatureRemo ã§ãããå®ç¾ããããã«ã¯ãªã¢ã³ã³æä½ãé£ç¶çã«è¡ãªãè£ ç½®ãå¿ è¦ã§ãã
ã¶ãã¨èª¿ã¹ãæãç GAS (Google Apps Script) ã§å®ç¾ãã¦ããã®ã§ãä»åç§ããã®ããã«ãã¾ããããæ£ç´ãããã©ããå¤ãã®ã§ AWS Lambda ã¨ã使ãã°ããã£ããããç¡ããã¨å¾æâ¦ãããåºæ¥ãã®ã§ãã¨ãããããã®ã¾ã¾éç¨ãã¦ãã¾ãã
GAS ã§ã¯ GET ã POST ãªã¯ã¨ã¹ããåããã¾ãå¥ã® HTTP ãªã¯ã¨ã¹ããçºè¡ãããã¨ãåºæ¥ã¾ãããããªããç§ã®ç°å¢ã§ã¯ POST ãä¸æãåããªãã£ãã®ã§ GET ãªã¯ã¨ã¹ãã§ãªã¢ã³ã³ãæä½ã§ããããã«ãã¾ããã
script å ã« token ã signal_id ãç´æ¥æ¸ãã¦ãããã¨ãåºæ¥ã¾ããã GAS ã¯æ£ç´ãããªã«æä½ããããªãã®ã§ã Query parameter ã§æå®ããããã«ãã¦ãã¾ãã
token
㧠{YOUR_ACCESS_TOKEN} ã ã£ãé¨åã signal_ids
ã§èµ¤å¤ç· ID ã ,
åºåãã§æ¸ãã¦ãããã¨ã§ 300ms ãã¨ã«èµ¤å¤ç·éä¿¡ããªã¯ã¨ã¹ããã¾ãã
curl -L "https://script.google.com/macros/s/aaaa-bbbb-cccc-dddd/exec?token={YOUR_ACCESS_TOKEN}&signal_ids=aaaa,bbbb,cccc,dddd"
ãã®ããã«ãã㨠aaaa -> 300ms -> bbbb -> 300ms -> cccc -> 300ms -> dddd ã®ããã« NatureRemo Cloud API ã«å¯¾ãã¦ãªã¯ã¨ã¹ããè¡ãªããã¾ãã
Google Home ãã使ããããã« IFTTT ã«ç»é²ãã
IFTTT ã«ã¯ WebHooks ã¨ãããã©ã°ã¤ã³ãããããããå©ç¨ãããã¨ã§ä»»æã® HTTP ãªã¯ã¨ã¹ããçºçããããã¨ãåºæ¥ã¾ããä»å GAS ã§ä½æãã API ãã Google Assistants ããå¼ã³åºããããã«ãã¾ãããã
å¿ç¨ç·¨
ãã® API ãå©ç¨ãããã¨ã§ NatureRemo ã«ç»é²ãã赤å¤ç·æä½ãé£ç¶ãã¦è¡ãªããã¨ãåºæ¥ã¾ãã
- ãå
¨é¨æ¶ãã¦ãã§ã·ã¼ãªã³ã°ã©ã¤ãããã¬ããã¨ã¢ã³ã³ãªã©ã®æä½ãä¸åº¦ã«è¡ãªã
- åãå¼ã³åºãæ¹æ³ã§è¤æ°ã®ã¬ã·ããç»é²ããã°å®ç¾å¯è½ã ãå®éé¢å
- ããããã«ã¼ãããä»ãã¦ãã§é»æºãä¸æ¦ãªãã«ãã¦ãããªã³ã«ãã
- ãã¡ã§ã¯ãããã«ã¼ãããã®é»æºããªã¢ã³ã³ã»ã³ãã§ãªã³ãªããã¦ããã®ã§ããããããã«ã¼ãããèªä½ãæ°æéã§é»æºãªãç¶æ ã«ãªãä»æ§ã«ãªã£ã¦ãã¾ã
- ãã®ç¶æ ã«ãªãã¨ãªã¢ã³ã³ã»ã³ãçã«ã¯é»æºãªã³ã¨ãã¦èªèãã¦ãã¾ãããå®éã«ã¯é»æºãåãã¦ããã®ã§ãä¸åº¦ãªãã«ãã¦ãããªã³ã«ãããã¨ã§è§£æ±ºãã¦ãã