How do i set temperature by using plain REST not firebase api

有些话、适合烂在心里 提交于 2019-12-10 19:46:34

问题


I could not find any information on how to set the target temperature or set Away mode. Has anyone successfully gotten it to work?

https://developer-api.nest.com/devices.json?auth=asdasdasd

^ Provides the information but how do we modify the temperature or away mode??


回答1:


Keep the auth in the querystring, and PUT the JSON-formatted change to the appropriate endpoint. eg (PHP):

To set target temperature:

$ch = curl_init("https://developer-api.nest.com/devices/thermostats/$THERMOSTAT_ID?auth=$AUTH");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"target_temperature_c": 21.5}');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);

To set Away mode:

$ch = curl_init("https://developer-api.nest.com/structures/$STRUCTURE_ID?auth=$AUTH");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"away":"away"}');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);


来源:https://stackoverflow.com/questions/24457353/how-do-i-set-temperature-by-using-plain-rest-not-firebase-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!