高木のブログ

Nature Remo Cloud APIを使って家電を操作する時のメモ

2019/11/19

ドキュメント

https://swagger.nature.global/

トークンの発行

https://home.nature.global/

手順

認証確認

$ curl -X GET "https://api.nature.global/1/users/me" -H "Authorization: Bearer Authorization: Bearer {取得したトークン}" | jq .
{
  "id": "{User ID}",
  "nickname": "ytkg"
}

電化製品一覧取得

$ curl -X GET "https://api.nature.global/1/appliances" -H "Authorization: Bearer {取得したトークン}" | jq .
[
  {
    "id": "{Appliance ID}",
    "device": {
      "name": "Remo",
      "id": "{Device ID}",
      "created_at": "2017-05-20T09:52:53Z",
      "updated_at": "2019-11-16T15:58:16Z",
      "mac_address": "{Mac Address}",
      "serial_number": "{Serial Number}",
      "firmware_version": "Remo/1.0.39-g41c1188",
      "temperature_offset": 0,
      "humidity_offset": 0
    },
    "model": null,
    "type": "IR",
    "nickname": "電気",
    "image": "ico_av",
    "settings": null,
    "aircon": null,
    "signals": [
      {
        "id": "{ONのSignal ID}",
        "name": "ON",
        "image": "ico_on"
      },
      {
        "id": "{OFFのSignal ID}",
        "name": "OFF",
        "image": "ico_off"
      }
    ]
  },
  {
    省略
  }
]

電化製品を操作する赤外線を送る

curl -X POST "https://api.nature.global/1/signals/{Signal ID}/send" -H "Authorization: Bearer {取得したトークン}"

Rubyで書くと

require 'faraday'

client = Faraday.new url: 'https://api.nature.global'
token = '{トークン}'
client.headers['Authorization'] = "Bearer #{token}"

response = client.get do |req|
  req.url '/1/appliances'
end

JSON.parse(response.body)

signal_id = 'Signal ID'
client.post do |req|
  req.url "/1/signals/#{signal_id}/send"
end

SNS でシェアする


ytkg

Written by ytkg, Twitter, GitHub