-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node-Red.txt
1 lines (1 loc) · 16.6 KB
/
Node-Red.txt
1
[{"id":"8880deba.f3f43","type":"tab","label":"Tesla Collector","disabled":false,"info":""},{"id":"d0bf48b7.1b7f58","type":"login","z":"8880deba.f3f43","name":"Brian Woods","x":135.5,"y":103.0000228881836,"wires":[["8b241b33.8b2d18"]]},{"id":"c11a0e26.18adb","type":"command","z":"8880deba.f3f43","name":"","command":"get_charge_state","x":316.50018310546875,"y":217.0001678466797,"wires":[["3b559a12.d1c576","8423e4a3.7d4958"]]},{"id":"abd82f75.4ee9d","type":"inject","z":"8880deba.f3f43","name":"","topic":"","payload":"","payloadType":"date","repeat":"900","crontab":"","once":false,"onceDelay":0.1,"x":225.5001220703125,"y":1099,"wires":[["d0bf48b7.1b7f58"]]},{"id":"8b241b33.8b2d18","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"","pretty":false,"x":120.5001220703125,"y":154.0000457763672,"wires":[["c11a0e26.18adb","c5c1c39f.9f872","633f8411.81bd7c","ab7c873d.311c38"]]},{"id":"3b559a12.d1c576","type":"change","z":"8880deba.f3f43","name":"","rules":[{"t":"delete","p":"payload.conn_charge_cable","pt":"msg"},{"t":"delete","p":"payload.fast_charger_type","pt":"msg"},{"t":"delete","p":"payload.fast_charger_brand","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":549.000114440918,"y":219.00018882751465,"wires":[["87e3fb21.e8e7d8"]]},{"id":"87e3fb21.e8e7d8","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"str","pretty":false,"x":729.5000991821289,"y":218.0001096725464,"wires":[["5acbf60c.6f6d08"]]},{"id":"5acbf60c.6f6d08","type":"change","z":"8880deba.f3f43","name":"DeNull","rules":[{"t":"change","p":"payload","pt":"msg","from":"null","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860.5001220703125,"y":217.66672325134277,"wires":[["471541fa.7a796"]]},{"id":"471541fa.7a796","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"obj","pretty":false,"x":1010.5002059936523,"y":216.00012016296387,"wires":[["3409680b.d2fe98"]]},{"id":"c5c1c39f.9f872","type":"command","z":"8880deba.f3f43","name":"","command":"get_drive_state","x":322.5000915527344,"y":531.0000915527344,"wires":[["81e96c45.e5"]]},{"id":"81e96c45.e5","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"str","pretty":false,"x":568.0002059936523,"y":531.1667308807373,"wires":[["8ddfa9bd.91ae48"]]},{"id":"d2b92a99.845548","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"obj","pretty":false,"x":981.5001220703125,"y":533.1666870117188,"wires":[["4a1ef42.9c16a0c"]]},{"id":"8ddfa9bd.91ae48","type":"change","z":"8880deba.f3f43","name":"DeNull","rules":[{"t":"change","p":"payload","pt":"msg","from":"null","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":776.0002174377441,"y":532.166690826416,"wires":[["d2b92a99.845548"]]},{"id":"7ded67e8.51b1b8","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"obj","pretty":true,"x":748.5000610351562,"y":700.0000610351562,"wires":[["f468d060.0c1d"]]},{"id":"f468d060.0c1d","type":"change","z":"8880deba.f3f43","name":"Cleanup","rules":[{"t":"move","p":"payload.odometer","pt":"msg","to":"payload2.odometer","tot":"msg"},{"t":"move","p":"payload.homelink_nearby","pt":"msg","to":"payload2.homelink_nearby","tot":"msg"},{"t":"move","p":"payload.is_user_present","pt":"msg","to":"payload2.is_user_present","tot":"msg"},{"t":"move","p":"payload.locked","pt":"msg","to":"payload2.locked","tot":"msg"},{"t":"move","p":"payload.remote_start","pt":"msg","to":"payload2.remote_start","tot":"msg"},{"t":"move","p":"payload.valet_mode","pt":"msg","to":"payload2.valet_mode","tot":"msg"},{"t":"move","p":"payload.sun_roof_percent_open","pt":"msg","to":"payload2.sun_roof_percent_open","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload2","tot":"msg"},{"t":"delete","p":"payload.timestamp","pt":"msg"},{"t":"delete","p":"payload2","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1147.5001220703125,"y":658.5001831054688,"wires":[["ecc7f767.46fdd8","c193e62e.98b3d8","b80313dc.80f3"]]},{"id":"633f8411.81bd7c","type":"command","z":"8880deba.f3f43","name":"","command":"get_vehicle_state","x":327.50006103515625,"y":702.3333740234375,"wires":[["7ded67e8.51b1b8"]]},{"id":"ecc7f767.46fdd8","type":"join","z":"8880deba.f3f43","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"10","count":"100","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1355.8333740234375,"y":878.0004272460938,"wires":[["24fd3020.df141","633fc559.aba2cc"]]},{"id":"4a1ef42.9c16a0c","type":"change","z":"8880deba.f3f43","name":"No Time","rules":[{"t":"delete","p":"payload.timestamp","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150.5,"y":534.0000610351562,"wires":[["ecc7f767.46fdd8","c193e62e.98b3d8","354efb1e.c453a4"]]},{"id":"3409680b.d2fe98","type":"change","z":"8880deba.f3f43","name":"No Time","rules":[{"t":"delete","p":"payload.timestamp","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1152.5,"y":216.00006103515625,"wires":[["ecc7f767.46fdd8","c193e62e.98b3d8","65d03aa4.6e3ec4"]]},{"id":"560abbd0.15f804","type":"influxdb out","z":"8880deba.f3f43","influxdb":"a54d22b4.08283","name":"","measurement":"AllData","precision":"m","retentionPolicy":"","x":865,"y":973,"wires":[]},{"id":"8423e4a3.7d4958","type":"switch","z":"8880deba.f3f43","name":"GetLastChargeIfNeeded","property":"payload.charging_state","propertyType":"msg","rules":[{"t":"eq","v":"Disconnected","vt":"str"},{"t":"eq","v":"Complete","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":377.9000244140625,"y":276.60003662109375,"wires":[["7641801.64e298","93d6708e.cb879","dfc505b5.36a7f8"],["93d6708e.cb879","dfc505b5.36a7f8"]]},{"id":"24fd3020.df141","type":"function","z":"8880deba.f3f43","name":"Add Tags","func":"//270 Max range I could ever see, anything higher means we lost a charge window.\n//If you have something other than a P85, this number might be higher, or lower.\nvar Max_Possible_Rage = 270;\n\n//To calculate this, I used some data from the web that suggested a P85 only\n// uses 77 kWh of the 85 kWh. This is a base to find the ideal kWh Per mile.\n//Then I used my ideal range to calculate it:\n// 77 kWh (Usable) * 0.76 (Charge State) * 10 / 223.6 (Ideal Range) = 0.2617kWh\n// I rounded this to 260 Wh per mile as I assume my base numbers are slightly\n// off and that this is the value that Tesla uses for their calculation.\n//You may also be able to get this from the following:\n// charge_energy_added / charge_miles_added_ideal\nvar Ideal_kWh_PerMile = .260;\nvar LD = 0;\n\n//This area deals with odd \"glitches\" that change data types around.\n//I don't know if this is Node-RED or Tesla...\nif (msg.payload.charge_port_door_open === 0) {\n msg.payload.charge_port_door_open = false;\n} else if (msg.payload.charge_port_door_open == 1) {\n msg.payload.charge_port_door_open = true;\n}\n\nif (msg.payload.fast_charger_present === 0) {\n msg.payload.fast_charger_present = false;\n} else if (msg.payload.fast_charger_present == 1) {\n msg.payload.fast_charger_present = true;\n}\n\nif (msg.payload.not_enough_power_to_heat === 0) {\n msg.payload.not_enough_power_to_heat = false;\n} else if (msg.payload.not_enough_power_to_heat == 1) {\n msg.payload.not_enough_power_to_heat = true;\n}\n\nif (msg.payload.trip_charging === 0) {\n msg.payload.trip_charging = false;\n} else if (msg.payload.trip_charging == 1) {\n msg.payload.trip_charging = true;\n}\n\n\nif (msg.payload.battery_heater_no_power === 0) {\n msg.payload.battery_heater_no_power = false;\n} else if (msg.payload.battery_heater_no_power == 1) {\n msg.payload.battery_heater_no_power = true;\n}\n\n\n//Energy effeciency:\nif (msg.payload.charging_state == \"Disconnected\") {\n connected = false;\n \n //We put this all in here incase there is a math error of some sort...\n //This can happen if this is the first record, so something just gets stuck.\n try {\n var traveled = msg.payload.odometer - msg.payload.LastConnectedOdometer;\n \n if (traveled <= Max_Possible_Rage) {\n msg.payload.traveled = traveled;\n msg.payload.energy_used = (msg.payload.LastIdealRange - msg.payload.ideal_battery_range) * Ideal_kWh_PerMile;\n //We add this \"extra\" veriable because InfluxDB kills the time field when doing back in queries.\n msg.payload.kwh_per_mile = msg.payload.energy_used / traveled \n \n }\n }\n catch(error) {\n console.error(error);\n }\n LD = msg.payload.LastConnectedOdometer;\n} else { \n connected = true;\n LD = msg.payload.odometer;\n}\n\n//Range lost to vampire load & pre-heat:\nif (msg.payload.charging_state == \"Disconnected\" || msg.payload.charging_state == \"Complete\") {\n if (msg.payload.LastOdometer == msg.payload.odometer) {\n if (msg.payload.LastRange > msg.payload.ideal_battery_range) {\n if (msg.payload.is_climate_on) {\n msg.payload.lostrange_climate = msg.payload.ideal_battery_range - msg.payload.LastRange;\n msg.payload.lostenergy_climate = (msg.payload.ideal_battery_range - msg.payload.LastRange) * Ideal_kWh_PerMile;\n } else {\n msg.payload.lostrange_vampire = msg.payload.ideal_battery_range - msg.payload.LastRange;\n msg.payload.lostenergy_vampire = (msg.payload.ideal_battery_range - msg.payload.LastRange) * Ideal_kWh_PerMile;\n }\n }\n }\n}\n\n\nvar tags = {Connected:connected, ConnectedOdometer:LD, Odometer:msg.payload.odometer, HomelinkNearby:msg.payload.homelink_nearby, IsUserPresent:msg.payload.is_user_present, Locked:msg.payload.locked, RemoteStart:msg.payload.remote_start, ValetMode:msg.payload.valet_mode};\n\n\nmsg.payload=[msg.payload, tags];\n\nreturn msg;","outputs":1,"noerr":0,"x":318.9000244140625,"y":973.4000244140625,"wires":[["3712c200.bb091e"]]},{"id":"7641801.64e298","type":"influxdb in","z":"8880deba.f3f43","influxdb":"a54d22b4.08283","name":"LastConnectedOdometer","query":"SELECT last(\"odometer\") AS LastConnectedOdometer FROM \"AllData\" WHERE (\"Connected\" = 'true') ","rawOutput":false,"precision":"","retentionPolicy":"","x":670,"y":270,"wires":[["dcd1ca56.3ff3e8","8dd3e31c.aa644"]]},{"id":"e30b6834.fb05f8","type":"debug","z":"8880deba.f3f43","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":795,"y":1056,"wires":[]},{"id":"dcd1ca56.3ff3e8","type":"function","z":"8880deba.f3f43","name":"De-Array","func":"msg.payload = msg.payload[0]\nreturn msg;","outputs":1,"noerr":0,"x":984.5,"y":270,"wires":[["73080861.71fa08"]]},{"id":"3712c200.bb091e","type":"change","z":"8880deba.f3f43","name":"Cleanup","rules":[{"t":"delete","p":"payload[0].LastConnectedOdometer","pt":"msg"},{"t":"delete","p":"payload[0].LastIdealRange","pt":"msg"},{"t":"delete","p":"payload2","pt":"msg"},{"t":"set","p":"payload[0].timestamp","pt":"msg","to":"","tot":"date"},{"t":"delete","p":"payload[0].time","pt":"msg"},{"t":"delete","p":"payload[0].LastRange","pt":"msg"},{"t":"delete","p":"payload[0].LastOdometer","pt":"msg"},{"t":"delete","p":"payload[0].shift_state","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":567,"y":973,"wires":[["560abbd0.15f804","e30b6834.fb05f8"]]},{"id":"8dd3e31c.aa644","type":"influxdb in","z":"8880deba.f3f43","influxdb":"a54d22b4.08283","name":"LastIdealRange","query":"SELECT last(LastIdealRange) AS LastIdealRange FROM (SELECT max(\"ideal_battery_range\") AS LastIdealRange FROM \"AllData\" WHERE (\"Connected\" = 'true') GROUP BY \"ConnectedOdometer\")","rawOutput":false,"precision":"","retentionPolicy":"","x":739.5,"y":328,"wires":[["e20f5509.0c3bc8"]]},{"id":"e20f5509.0c3bc8","type":"function","z":"8880deba.f3f43","name":"De-Array","func":"msg.payload = msg.payload[0]\nreturn msg;","outputs":1,"noerr":0,"x":982,"y":328,"wires":[["94cb1e1b.5dbf8"]]},{"id":"c193e62e.98b3d8","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1355,"y":823,"wires":[]},{"id":"73080861.71fa08","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"obj","pretty":false,"x":1144.5,"y":271,"wires":[["c193e62e.98b3d8","ecc7f767.46fdd8","ec0de8e6.37cb18"]]},{"id":"94cb1e1b.5dbf8","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"obj","pretty":false,"x":1142.5,"y":328,"wires":[["c193e62e.98b3d8","ecc7f767.46fdd8","d837cfe3.27058"]]},{"id":"93d6708e.cb879","type":"influxdb in","z":"8880deba.f3f43","influxdb":"a54d22b4.08283","name":"LastRange","query":"SELECT last(ideal_battery_range) AS LastRange FROM \"AllData\"","rawOutput":false,"precision":"","retentionPolicy":"","x":730,"y":381,"wires":[["40f07a7a.bf23d4"]],"inputLabels":["LastIdeal"]},{"id":"dfc505b5.36a7f8","type":"influxdb in","z":"8880deba.f3f43","influxdb":"a54d22b4.08283","name":"LastOdometer","query":"SELECT last(odometer) AS LastOdometer FROM \"AllData\"","rawOutput":false,"precision":"","retentionPolicy":"","x":738,"y":433,"wires":[["5ae63fc3.91ddd"]]},{"id":"40f07a7a.bf23d4","type":"function","z":"8880deba.f3f43","name":"De-Array","func":"msg.payload = msg.payload[0]\nreturn msg;","outputs":1,"noerr":0,"x":978,"y":380,"wires":[["fb607a47.b3caf8"]]},{"id":"fb607a47.b3caf8","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"obj","pretty":false,"x":1145.5,"y":380,"wires":[["c193e62e.98b3d8","ecc7f767.46fdd8","472b8438.c5fb4c"]]},{"id":"5ae63fc3.91ddd","type":"function","z":"8880deba.f3f43","name":"De-Array","func":"msg.payload = msg.payload[0]\nreturn msg;","outputs":1,"noerr":0,"x":974,"y":432,"wires":[["311df122.06aaee"]]},{"id":"311df122.06aaee","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"obj","pretty":false,"x":1141.5,"y":432,"wires":[["ecc7f767.46fdd8","c193e62e.98b3d8","6e63c1c6.ee7b9"]]},{"id":"633fc559.aba2cc","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1412,"y":953,"wires":[]},{"id":"ab7c873d.311c38","type":"command","z":"8880deba.f3f43","name":"","command":"get_climate_state","x":339,"y":765,"wires":[["f64041fa.cba05"]]},{"id":"8c520e3d.cd35a","type":"change","z":"8880deba.f3f43","name":"No Time","rules":[{"t":"delete","p":"payload.timestamp","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1135,"y":754,"wires":[["c193e62e.98b3d8","ecc7f767.46fdd8","55ae27bc.104298"]]},{"id":"55ae27bc.104298","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1367,"y":753,"wires":[]},{"id":"b80313dc.80f3","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1368,"y":659,"wires":[]},{"id":"354efb1e.c453a4","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1359,"y":534,"wires":[]},{"id":"6e63c1c6.ee7b9","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1354,"y":432,"wires":[]},{"id":"472b8438.c5fb4c","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1351,"y":380,"wires":[]},{"id":"d837cfe3.27058","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1351,"y":328,"wires":[]},{"id":"ec0de8e6.37cb18","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1344,"y":270,"wires":[]},{"id":"65d03aa4.6e3ec4","type":"debug","z":"8880deba.f3f43","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1344,"y":216,"wires":[]},{"id":"f64041fa.cba05","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"str","pretty":false,"x":641,"y":764,"wires":[["2dd6dc.187bc924"]]},{"id":"2dd6dc.187bc924","type":"change","z":"8880deba.f3f43","name":"DeNull","rules":[{"t":"change","p":"payload","pt":"msg","from":"null","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":772.0000228881836,"y":763.6666135787964,"wires":[["3ba8779c.4f8e98"]]},{"id":"3ba8779c.4f8e98","type":"json","z":"8880deba.f3f43","name":"","property":"payload","action":"obj","pretty":false,"x":922.0001068115234,"y":762.0000104904175,"wires":[["8c520e3d.cd35a"]]},{"id":"a54d22b4.08283","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"Tesla","name":"","usetls":false,"tls":""}]