Message Boards Message Boards

6
|
9480 Views
|
1 Reply
|
9 Total Likes
View groups...
Share
Share this post:

Sample connection to the NEST Thermostats

Posted 12 years ago
Here is a simple way to connect to your NEST thermostats. I got a few of those last week end.
They are quite easy to interface in Mathematica.
In a follow up post, I will try to provide a full dashboard.

Enjoy,

First, just set the value to userEmail and password that you used for the site www.nest.com
Luc
 
 
 loginData = ImportString[ URLFetch["https://home.nest.com/user/login/?username="<>userEmail<>"&password="<>password],"JSON" ];
 user= "user"/.loginData;
 userId = "userid"/.loginData;
 accessToken = ("access_token"/.loginData);
 authorization = ("Basic "<>accessToken);
 transportURL = Last[ StringSplit[("transport_url"/.("urls"/.loginData)),"//"]];
 
dataSet = ImportString[URLFetch["https://"<>transportURL<>"/v2/mobile/"<>user,"Headers"->{
"Host"->transportURL,
"User-Agent"->"Nest/1.1.0.10 CFNetwork/548.0.4",
"Authorization"->authorization,
"X-nl-protocol-version"->"1",
"X-nl-user-id"->userId,
"Accept-Language"->"en-us",
"Connection"->"keep-alive",
"Accept"->"*/*"
}],"JSON" ];

deviceIdList=First /@ ("device"/.dataSet);

DisplayNest[ID_,dataSet_]:=Module[{name,temp,humidity, targetTemp,sharedData,time,deviceData,heating},
deviceData=ID/.("device"/.dataSet);
sharedData=ID/.("shared"/.dataSet);
{name,temp, targetTemp, time,heating}={"name","current_temperature","target_temperature","$timestamp","hvac_ac_state"}/.sharedData;
Column[{AngularGauge[{temp,targetTemp},{9,32},GaugeFaceStyle->Black,GaugeFrameStyle->Black,GaugeFrameSize->.6,GaugeLabels->Placed[Style[Round[targetTemp],White,40],Center],GaugeMarkers->"Sector",GaugeStyle->White,
ScaleDivisions->None,ScaleOrigin->{\[Pi]+\[Pi]/4,-\[Pi]/4}
],Style[name,20]},Alignment->Center]
];

DisplayNest[#,dataSet]& /@ deviceIdList
POSTED BY: Luc Barthelet
Here is a Manipulate that simulates the look of the thermostat:
 DynamicModule[{innerTicRadius=.4,outerTicRadius =.57,tempAngle,targetTemp,targetTempAngle,lowTemp=9,highTemp=32},
 tempAngle[temp_]:= (Pi+Pi/4)(temp-highTemp)/(lowTemp-highTemp)+ (-Pi/4) (temp-lowTemp)/(highTemp-lowTemp);
 targetTemp=16;
 targetTempAngle = tempAngle[targetTemp];
 Manipulate[
 DynamicModule[{edgeColor,ambientTemperatureColor,activeColor,deltaTemp,drawTic,
 edgeRadius = 1, backgroundRadius = .95, activeRadius = .6 ,
 actualTemp=24,currentTempPosition,currentTempPositionAngle
 },
targetTempAngle= ArcTan[l[[1]],l[[2]]];
l= Mean[{innerTicRadius,outerTicRadius}]*{Cos[targetTempAngle],Sin[targetTempAngle]};
targetTemp=(5 highTemp \[Pi]+lowTemp \[Pi]-4 highTemp targetTempAngle+4 lowTemp targetTempAngle)/(6 \[Pi]);
deltaTemp = 5/( (highTemp-lowTemp));
edgeColor=GrayLevel[0.4];
ambientTemperatureColor= Black;
activeColor =If[ targetTemp>actualTemp, Orange,Black];
currentTempPositionAngle  = tempAngle[actualTemp]+.15*Sign[targetTemp-actualTemp];
currentTempPosition = Mean[{innerTicRadius,outerTicRadius}]*{Cos[currentTempPositionAngle],Sin[currentTempPositionAngle]};
drawTic[temp_]:=Module[{angle,p},
angle = tempAngle[temp];
p={Cos[angle],Sin[angle]};
{innerTicRadius*p,outerTicRadius*p}
];
Graphics[
{edgeColor,
Disk[{0,0},edgeRadius],
ambientTemperatureColor,
Disk[{0,0},backgroundRadius],
White,
Text[Style["nest",32,FontFamily->"Franklin Gothic Book"],{0,.77}],
activeColor,
Disk[{0,0},activeRadius],
White,Opacity[.5],
Line[Table[drawTic[n],{n,lowTemp,highTemp,deltaTemp}]],
Opacity[1],
Line[Table[drawTic[n],{n,actualTemp,targetTemp,deltaTemp*Sign[targetTemp-actualTemp]}]],
Text[Style[ToString[actualTemp],16],currentTempPosition],

Text[Style[ToString[Round[targetTemp]],60],{0,0}],

}
]
],
{{l,Mean[{innerTicRadius,outerTicRadius}]*{Cos[targetTempAngle],Sin[targetTempAngle]}},Locator,Appearance->None}
]
]
POSTED BY: Luc Barthelet
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract