# Preheat or precool car

**URL:** <https://discourse.nodered.org/t/preheat-or-precool-car/63879>\
**Category:** Share Your Projects\
**Created:** [13 June 2022 21:40 UTC](https://discourse.nodered.org/t/preheat-or-precool-car/63879 "2022-06-13T21:40:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hitnrun30](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hitnrun30/32/63191_2.png) [@hitnrun30](https://discourse.nodered.org/u/hitnrun30)\
**Post date:** [13 June 2022 21:40 UTC](https://discourse.nodered.org/t/preheat-or-precool-car/63879/1 "2022-06-13T21:40:58Z")

</div>

Ok, i need a little help, so far I have been able to use the http request to get half of what I need. I get the hourly forecast and then using a function loop through the values to get the next days forecast for the hour I leave in the morning. I have a Tesla so I can set the temperature I want based on that, but I have no idea what I should set the ranges to be, I figure if it is below 50F set it to High and if it is above 70 set it to low, but I was wondering if anyone actually knows what optimal values would be?

I am happy to share what I have so far, below is my test, just go to [NWS API](https://www.weather.gov/documentation/services-web-api) and find out your location.

```auto
[{"id":"c1fc09c193206e62","type":"inject","z":"b7e849477e35b95d","name":"test","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":380,"wires":[["af1358208666a1fd"]]},{"id":"af1358208666a1fd","type":"http request","z":"b7e849477e35b95d","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.weather.gov/gridpoints/XXX/##,###/forecast/hourly","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":290,"y":440,"wires":[["c1a65130f1882701","0ac57048d0a2145d"]]},{"id":"c1a65130f1882701","type":"function","z":"b7e849477e35b95d","name":"","func":"const tomorrow = new Date();\ntomorrow.setDate(tomorrow.getDate() + 1);\nvar tommstr = tomorrow.getFullYear() + \"-\" + String(tomorrow.getMonth()+1).padStart(2,\"0\") + \"-\" + String(tomorrow.getDate()).padStart(2,\"0\") + \"T07:00:00\";\n\nvar dataset = msg.payload.properties.periods\nvar fahrenheit = 0;\nvar celcius = 0;\n\nfor(var i = 0; i < dataset.length; i++) {\n var obj = dataset[i];\n if (obj.startTime.includes(tommstr)) { \n fahrenheit = obj.temperature;\n celcius = +((fahrenheit - 32) * 5 / 9).toFixed(2);\n break; \n }\n}\nmsg = {};\nmsg.payload = {};\nmsg.payload.fahrenheit = fahrenheit;\nmsg.payload.celcius = celcius;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":440,"wires":[["c670848a93bc1823"]]},{"id":"c670848a93bc1823","type":"debug","z":"b7e849477e35b95d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":380,"wires":[]}]

```
