Skip to content

Instantly share code, notes, and snippets.

@nberardi
Created March 6, 2023 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nberardi/62d911e890bc60e3f7b6e7c742a27518 to your computer and use it in GitHub Desktop.
Save nberardi/62d911e890bc60e3f7b6e7c742a27518 to your computer and use it in GitHub Desktop.
Node Red - On Model 3 Charging Adjust Amperage From Car To Maximize Sun Without Grid Usage
[
{
"id": "d20b09cd596147aa",
"type": "tab",
"label": "On Model 3 charging",
"disabled": false,
"info": "",
"env": []
},
{
"id": "648c9330.06d6dc",
"type": "server",
"name": "Home Assistant",
"addon": true
},
{
"id": "fe38402395c8c90c",
"type": "tesla-config",
"email": "yourown@email.com"
},
{
"id": "b749f00bd8ec90e3",
"type": "ha-entity-config",
"server": "648c9330.06d6dc",
"deviceConfig": "",
"name": "override_tesla_app_charging",
"version": "6",
"entityType": "switch",
"haConfig": [
{
"property": "name",
"value": "Override Tesla App Charging"
},
{
"property": "icon",
"value": ""
},
{
"property": "entity_category",
"value": "config"
},
{
"property": "device_class",
"value": "switch"
}
],
"resend": false,
"debugEnabled": false
},
{
"id": "cb1dfcde.fd153",
"type": "function",
"z": "d20b09cd596147aa",
"name": "set POST payload",
"func": "var refreshToken = msg.refresh_token;\n\nmsg.payload = {\n \"grant_type\": \"refresh_token\",\n \"client_id\": \"ownerapi\",\n \"refresh_token\": refreshToken,\n \"scope\": \"openid email offline_access\"\n};\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 570,
"y": 140,
"wires": [
[
"e44209e7.752698"
]
]
},
{
"id": "dcf34aab.218928",
"type": "inject",
"z": "d20b09cd596147aa",
"name": "Tesla Auth",
"props": [],
"repeat": "7200",
"crontab": "",
"once": true,
"onceDelay": "",
"topic": "",
"x": 150,
"y": 140,
"wires": [
[
"aee69e4b74b929e1"
]
]
},
{
"id": "e44209e7.752698",
"type": "http request",
"z": "d20b09cd596147aa",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://auth.tesla.com/oauth2/v3/token",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [
{
"keyType": "other",
"keyValue": "User-Agent",
"valueType": "other",
"valueValue": "Tesla/4.17.5 (com.teslamotors.TeslaApp; build:1576; iOS 16.3.0) Alamofire/5.2.1"
},
{
"keyType": "other",
"keyValue": "X-Tesla-User-Agent",
"valueType": "other",
"valueValue": "TeslaApp/4.17.5-1576/625ddcb31f/ios/16.3"
}
],
"x": 770,
"y": 140,
"wires": [
[
"15e29e449961baf6"
]
]
},
{
"id": "ee306582.f0dde8",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1250,
"y": 140,
"wires": []
},
{
"id": "54ba6b1ebfa346f4",
"type": "comment",
"z": "d20b09cd596147aa",
"name": "Tesla Powerwall Local API Authentication",
"info": "",
"x": 200,
"y": 80,
"wires": []
},
{
"id": "15e29e449961baf6",
"type": "function",
"z": "d20b09cd596147aa",
"name": "save API token to flow-variable",
"func": "flow.set(\"tesla_auth\", msg.payload);\n\nmsg.payload = {\n \"tesla_auth\": flow.get(\"tesla_auth\"), \n \"createdAt\": new Date().toISOString()\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1010,
"y": 140,
"wires": [
[
"ee306582.f0dde8"
]
]
},
{
"id": "b6012a6351eaf9ab",
"type": "poll-state",
"z": "d20b09cd596147aa",
"name": "poll: Tesla Plugged In",
"server": "648c9330.06d6dc",
"version": 2,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"updateinterval": "15",
"updateIntervalType": "num",
"updateIntervalUnits": "minutes",
"outputinitially": false,
"outputonchanged": false,
"entity_id": "binary_sensor.tesla_wall_connector_vehicle_connected",
"state_type": "str",
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 2,
"x": 240,
"y": 320,
"wires": [
[
"ed62f43757b79fb6"
],
[]
]
},
{
"id": "ba8947c275f43fe5",
"type": "function",
"z": "d20b09cd596147aa",
"name": "set POST payload",
"func": "const { access_token } = flow.get(\"tesla_auth\");\nconst backup_reserve_percent = msg.payload.backup_reserve_percent;\n\nmsg.headers = {\n \"Authorization\": \"Bearer \" + access_token,\n \"User-Agent\": \"Tesla/4.17.5(com.teslamotors.TeslaApp; build: 1576; iOS 16.3.0) Alamofire/5.2.1\",\n \"X-Tesla-User-Agent\": \"TeslaApp/4.17.5-1576/625ddcb31f/ios/16.3\"\n};\n\nmsg.payload = {\n \"backup_reserve_percent\": backup_reserve_percent\n};\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1470,
"y": 520,
"wires": [
[
"8f98018c86fb241f",
"eb78b9d9581651dd"
]
]
},
{
"id": "8f98018c86fb241f",
"type": "http request",
"z": "d20b09cd596147aa",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://owner-api.teslamotors.com/api/1/energy_sites/2252187651136776/backup",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 1690,
"y": 520,
"wires": [
[
"4c630b381ac563a2"
]
]
},
{
"id": "4c630b381ac563a2",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1870,
"y": 520,
"wires": []
},
{
"id": "a9598bfb97cc562b",
"type": "tesla-api",
"z": "d20b09cd596147aa",
"teslaConfig": "fe38402395c8c90c",
"command": "chargeState",
"name": "chargeState",
"vehicleID": "1492931888111677",
"autoWakeUp": true,
"x": 510,
"y": 520,
"wires": [
[
"555200ee7d0d65da"
]
]
},
{
"id": "555200ee7d0d65da",
"type": "switch",
"z": "d20b09cd596147aa",
"name": "",
"property": "payload.charging_state",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "Charging",
"vt": "str"
},
{
"t": "neq",
"v": "Charging",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 690,
"y": 520,
"wires": [
[
"6afb4934ee0ca1d4",
"e8fce17b3d228614",
"a53e9d5b93ad8092"
],
[
"30c4f96bc8320120",
"16069f2a3ffa40b2"
]
]
},
{
"id": "7c1a74482394adb2",
"type": "server-state-changed",
"z": "d20b09cd596147aa",
"name": "stated_changed: Tesla Plugged In",
"server": "648c9330.06d6dc",
"version": 4,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "binary_sensor.tesla_wall_connector_vehicle_connected",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 1,
"output_only_on_state_change": true,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": true,
"ignoreCurrentStateUnavailable": true,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
}
],
"x": 200,
"y": 260,
"wires": [
[
"ed62f43757b79fb6"
]
]
},
{
"id": "a9a1556f27c813a0",
"type": "comment",
"z": "d20b09cd596147aa",
"name": "Change Powerwall Self Consumption Mode Based On Tesla Auto Charging State",
"info": "",
"x": 320,
"y": 400,
"wires": []
},
{
"id": "aee69e4b74b929e1",
"type": "credentials",
"z": "d20b09cd596147aa",
"name": "Tesla Credentials",
"props": [
{
"value": "refresh_token",
"type": "msg"
}
],
"x": 350,
"y": 140,
"wires": [
[
"cb1dfcde.fd153"
]
]
},
{
"id": "6afb4934ee0ca1d4",
"type": "change",
"z": "d20b09cd596147aa",
"name": "Set Backup Reserve to 100%",
"rules": [
{
"t": "set",
"p": "payload.backup_reserve_percent",
"pt": "msg",
"to": "100",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 950,
"y": 500,
"wires": [
[
"dd1beae135147e91"
]
]
},
{
"id": "30c4f96bc8320120",
"type": "change",
"z": "d20b09cd596147aa",
"name": "Set Backup Reserve to 20%",
"rules": [
{
"t": "set",
"p": "payload.backup_reserve_percent",
"pt": "msg",
"to": "20",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 940,
"y": 540,
"wires": [
[
"dd1beae135147e91"
]
]
},
{
"id": "eb78b9d9581651dd",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1690,
"y": 480,
"wires": []
},
{
"id": "5d6071166465e96b",
"type": "trigger-state",
"z": "d20b09cd596147aa",
"name": "Left Panel Home Load fell below 2A",
"server": "648c9330.06d6dc",
"version": 2,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityid": "sensor.left_powerwall_load_now",
"entityidfiltertype": "exact",
"debugenabled": false,
"constraints": [
{
"targetType": "this_entity",
"targetValue": "",
"propertyType": "previous_state",
"propertyValue": "old_state.state",
"comparatorType": ">",
"comparatorValueDatatype": "str",
"comparatorValue": "2.0"
},
{
"targetType": "this_entity",
"targetValue": "",
"propertyType": "current_state",
"propertyValue": "new_state.state",
"comparatorType": "<=",
"comparatorValueDatatype": "str",
"comparatorValue": "2"
}
],
"inputs": 0,
"outputs": 2,
"customoutputs": [],
"outputinitially": false,
"state_type": "num",
"enableInput": false,
"x": 200,
"y": 580,
"wires": [
[
"a9598bfb97cc562b"
],
[]
]
},
{
"id": "d9135f7bb4c6e52f",
"type": "comment",
"z": "d20b09cd596147aa",
"name": "Start Charging Tesla Auto When Battery Reaches 100% And There Is Still Available Solar",
"info": "",
"x": 350,
"y": 720,
"wires": []
},
{
"id": "4bd42c1f4458b346",
"type": "tesla-api",
"z": "d20b09cd596147aa",
"teslaConfig": "fe38402395c8c90c",
"command": "startCharge",
"name": "startCharge",
"vehicleID": "1492931888111677",
"autoWakeUp": true,
"x": 1370,
"y": 920,
"wires": [
[
"6da1d04195c1250c",
"6e8b148a14a38f23"
]
]
},
{
"id": "4e8abe23e139cd3e",
"type": "tesla-api",
"z": "d20b09cd596147aa",
"teslaConfig": "fe38402395c8c90c",
"command": "chargeStandard",
"name": "chargeStandard",
"vehicleID": "1492931888111677",
"autoWakeUp": true,
"x": 1160,
"y": 920,
"wires": [
[
"4bd42c1f4458b346"
]
]
},
{
"id": "70c61dd561823c39",
"type": "switch",
"z": "d20b09cd596147aa",
"name": "",
"property": "payload.charging_state",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "Charging",
"vt": "str"
},
{
"t": "neq",
"v": "Charging",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 810,
"y": 780,
"wires": [
[
"5165da2132feca0b",
"d455336f418f1b52"
],
[
"0300f27b9565b43a"
]
]
},
{
"id": "e80d7e93277c1b9b",
"type": "tesla-api",
"z": "d20b09cd596147aa",
"teslaConfig": "fe38402395c8c90c",
"command": "chargeState",
"name": "chargeState",
"vehicleID": "1492931888111677",
"autoWakeUp": true,
"x": 630,
"y": 780,
"wires": [
[
"70c61dd561823c39"
]
]
},
{
"id": "5165da2132feca0b",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "Already Charging",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1010,
"y": 780,
"wires": []
},
{
"id": "0300f27b9565b43a",
"type": "switch",
"z": "d20b09cd596147aa",
"name": "",
"property": "payload.battery_level",
"propertyType": "msg",
"rules": [
{
"t": "gte",
"v": "payload.charge_limit_soc_std",
"vt": "msg"
},
{
"t": "lt",
"v": "payload.charge_limit_soc_std",
"vt": "msg"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 970,
"y": 840,
"wires": [
[
"40677c00fb33cc39",
"ab69aa5d32f2fbdc"
],
[
"4e8abe23e139cd3e"
]
]
},
{
"id": "40677c00fb33cc39",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "Already Charged",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1170,
"y": 860,
"wires": []
},
{
"id": "b4f157d3b6c708e3",
"type": "delay",
"z": "d20b09cd596147aa",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "15",
"rateUnits": "minute",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 780,
"y": 960,
"wires": [
[
"e80d7e93277c1b9b"
]
]
},
{
"id": "e8fce17b3d228614",
"type": "link out",
"z": "d20b09cd596147aa",
"name": "Tesla Charging",
"mode": "link",
"links": [
"724f43b318877b8e"
],
"x": 835,
"y": 420,
"wires": []
},
{
"id": "724f43b318877b8e",
"type": "link in",
"z": "d20b09cd596147aa",
"name": "On Tesla Charging",
"links": [
"d455336f418f1b52",
"e8fce17b3d228614"
],
"x": 55,
"y": 1080,
"wires": [
[
"806e48e11708bd9e"
]
]
},
{
"id": "d455336f418f1b52",
"type": "link out",
"z": "d20b09cd596147aa",
"name": "Telsa Charging",
"mode": "link",
"links": [
"724f43b318877b8e"
],
"x": 935,
"y": 740,
"wires": []
},
{
"id": "1e90d497ed9d5b03",
"type": "comment",
"z": "d20b09cd596147aa",
"name": "Regulate Charging Amps for Tesla Auto Based On Available Solar",
"info": "",
"x": 270,
"y": 1020,
"wires": []
},
{
"id": "3499f0827ff39396",
"type": "tesla-api",
"z": "d20b09cd596147aa",
"teslaConfig": "fe38402395c8c90c",
"command": "setChargingAmps",
"name": "setChargingAmps",
"vehicleID": "1492931888111677",
"autoWakeUp": true,
"x": 1330,
"y": 1080,
"wires": [
[
"946e39bcb9b92ab4"
]
]
},
{
"id": "3e02c5fec94c89b0",
"type": "api-current-state",
"z": "d20b09cd596147aa",
"name": "state: Tesla Plugged In",
"server": "648c9330.06d6dc",
"version": 3,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "binary_sensor.tesla_wall_connector_vehicle_connected",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 380,
"y": 840,
"wires": [
[
"4c50cdac3c42cfab"
],
[]
]
},
{
"id": "bb4b1945a773e912",
"type": "poll-state",
"z": "d20b09cd596147aa",
"name": "poll: Powerwall at 100%",
"server": "648c9330.06d6dc",
"version": 2,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"updateinterval": "60",
"updateIntervalType": "num",
"updateIntervalUnits": "seconds",
"outputinitially": false,
"outputonchanged": false,
"entity_id": "sensor.left_powerwall_charge",
"state_type": "num",
"halt_if": "100",
"halt_if_type": "num",
"halt_if_compare": "is",
"outputs": 2,
"x": 230,
"y": 780,
"wires": [
[
"3e02c5fec94c89b0"
],
[]
]
},
{
"id": "6da1d04195c1250c",
"type": "link out",
"z": "d20b09cd596147aa",
"name": "Tesla Charging Started",
"mode": "link",
"links": [
"9a532accb799d754"
],
"x": 1515,
"y": 880,
"wires": []
},
{
"id": "f15d23731c68251d",
"type": "comment",
"z": "d20b09cd596147aa",
"name": "Tesla Has Been Plugged In",
"info": "",
"x": 150,
"y": 200,
"wires": []
},
{
"id": "ed62f43757b79fb6",
"type": "link out",
"z": "d20b09cd596147aa",
"name": "Telsa Plugged In",
"mode": "link",
"links": [
"9487744a80e5d159"
],
"x": 495,
"y": 260,
"wires": []
},
{
"id": "9487744a80e5d159",
"type": "link in",
"z": "d20b09cd596147aa",
"name": "On Tesla Plugged In",
"links": [
"ed62f43757b79fb6"
],
"x": 55,
"y": 460,
"wires": [
[
"a9598bfb97cc562b"
]
]
},
{
"id": "9a532accb799d754",
"type": "link in",
"z": "d20b09cd596147aa",
"name": "On Tesla Charging Started",
"links": [
"6da1d04195c1250c"
],
"x": 55,
"y": 520,
"wires": [
[
"a9598bfb97cc562b"
]
]
},
{
"id": "9461c8f8f67a5245",
"type": "inject",
"z": "d20b09cd596147aa",
"name": "",
"props": [],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 170,
"y": 840,
"wires": [
[
"3e02c5fec94c89b0"
]
]
},
{
"id": "638518c6ae199182",
"type": "inject",
"z": "d20b09cd596147aa",
"name": "",
"props": [],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 510,
"y": 1140,
"wires": [
[
"f8e788a015ed89ae",
"100b30e264602f1b"
]
]
},
{
"id": "946e39bcb9b92ab4",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1550,
"y": 1080,
"wires": []
},
{
"id": "6e8b148a14a38f23",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1570,
"y": 920,
"wires": []
},
{
"id": "de69c4f8af46cde2",
"type": "api-current-state",
"z": "d20b09cd596147aa",
"name": "state: Override Tesla App",
"server": "648c9330.06d6dc",
"version": 3,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "switch.override_tesla_app_charging",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 450,
"y": 1080,
"wires": [
[
"f8e788a015ed89ae",
"100b30e264602f1b"
],
[]
]
},
{
"id": "4c50cdac3c42cfab",
"type": "api-current-state",
"z": "d20b09cd596147aa",
"name": "state: Override Tesla App",
"server": "648c9330.06d6dc",
"version": 3,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "switch.override_tesla_app_charging",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 390,
"y": 900,
"wires": [
[
"0731d352813c7db4"
],
[]
]
},
{
"id": "9dc1a8797af269c6",
"type": "link in",
"z": "d20b09cd596147aa",
"name": "Right Solar Now",
"links": [],
"x": 55,
"y": 1260,
"wires": [
[
"b2f40c5017f1393b",
"8e23966b3bfa6679"
]
]
},
{
"id": "fe048811e7a00c6f",
"type": "function",
"z": "d20b09cd596147aa",
"name": "Calculate Solar Now",
"func": "const right_now = msg.payload.right_powerwall_solar_now;\nconst left_estimate = msg.payload.left_powerwall_solar_estimation;\n\nif (right_now === 0)\n msg.payload = left_estimate;\nelse\n msg.payload = right_now * 2.0;\n\nmsg.topic = \"solar_current\";\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 640,
"y": 1260,
"wires": [
[
"7defda98a10bbbe9",
"55925761a76a15ab"
]
]
},
{
"id": "7defda98a10bbbe9",
"type": "link out",
"z": "d20b09cd596147aa",
"name": "link out 1",
"mode": "return",
"links": [],
"x": 815,
"y": 1260,
"wires": []
},
{
"id": "b2f40c5017f1393b",
"type": "api-current-state",
"z": "d20b09cd596147aa",
"name": "state: Right Solar Now",
"server": "648c9330.06d6dc",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "num",
"halt_if_compare": "is",
"entity_id": "sensor.right_powerwall_solar_now",
"state_type": "num",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
},
{
"property": "topic",
"propertyType": "msg",
"value": "right_powerwall_solar_now",
"valueType": "str"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 220,
"y": 1260,
"wires": [
[
"f7ef5329e877dee7"
]
]
},
{
"id": "f8e788a015ed89ae",
"type": "link call",
"z": "d20b09cd596147aa",
"name": "",
"links": [
"9dc1a8797af269c6"
],
"linkType": "static",
"timeout": "30",
"x": 720,
"y": 1140,
"wires": [
[
"3054dd459aac0c97"
]
]
},
{
"id": "0731d352813c7db4",
"type": "link call",
"z": "d20b09cd596147aa",
"name": "",
"links": [
"9dc1a8797af269c6"
],
"linkType": "static",
"timeout": "30",
"x": 360,
"y": 960,
"wires": [
[
"8122528e03a22630"
]
]
},
{
"id": "55925761a76a15ab",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 870,
"y": 1220,
"wires": []
},
{
"id": "8a0a73d7ac15d727",
"type": "comment",
"z": "d20b09cd596147aa",
"name": "Calculate the potential Right Powerwall Solar Output",
"info": "",
"x": 230,
"y": 1200,
"wires": []
},
{
"id": "f7ef5329e877dee7",
"type": "join",
"z": "d20b09cd596147aa",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "num",
"reduceFixup": "",
"x": 430,
"y": 1260,
"wires": [
[
"fe048811e7a00c6f",
"13a1338670b9635c"
]
]
},
{
"id": "8e23966b3bfa6679",
"type": "api-current-state",
"z": "d20b09cd596147aa",
"name": "state: Solar Estimation",
"server": "648c9330.06d6dc",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "sensor.power_production_now",
"state_type": "num",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
},
{
"property": "topic",
"propertyType": "msg",
"value": "left_powerwall_solar_estimation",
"valueType": "str"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 220,
"y": 1320,
"wires": [
[
"f7ef5329e877dee7"
]
]
},
{
"id": "100b30e264602f1b",
"type": "api-current-state",
"z": "d20b09cd596147aa",
"name": "state: Tesla Voltage",
"server": "648c9330.06d6dc",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "sensor.tesla_wall_connector_phase_b_voltage",
"state_type": "num",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
},
{
"property": "topic",
"propertyType": "msg",
"value": "voltage",
"valueType": "str"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 710,
"y": 1080,
"wires": [
[
"3054dd459aac0c97"
]
]
},
{
"id": "3054dd459aac0c97",
"type": "join",
"z": "d20b09cd596147aa",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 910,
"y": 1080,
"wires": [
[
"7f4e9a1b441ddbea",
"4968873e18671aaf"
]
]
},
{
"id": "7f4e9a1b441ddbea",
"type": "function",
"z": "d20b09cd596147aa",
"name": "Calculate Amps",
"func": "const current = msg.payload.solar_current;\nconst voltage = msg.payload.voltage;\n\n// reserve 1 kW for the house\nlet amps = ((current - 1) * 1000) / voltage;\n\nif (current === 0)\n amps = 40;\n\namps = Math.min(40, amps); // max of 40 amps allowed\namps = Math.max(5, amps); // min of 5 amps allowed\namps = Math.floor(amps);\n\nmsg.commandArgs = { amps };\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1100,
"y": 1080,
"wires": [
[
"f90f395cd9765492",
"3499f0827ff39396"
]
]
},
{
"id": "f90f395cd9765492",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "commandArgs",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1330,
"y": 1040,
"wires": []
},
{
"id": "4968873e18671aaf",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1090,
"y": 1040,
"wires": []
},
{
"id": "13a1338670b9635c",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 610,
"y": 1220,
"wires": []
},
{
"id": "dd1beae135147e91",
"type": "delay",
"z": "d20b09cd596147aa",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "5",
"rateUnits": "minute",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 1240,
"y": 520,
"wires": [
[
"ba8947c275f43fe5"
]
]
},
{
"id": "8122528e03a22630",
"type": "switch",
"z": "d20b09cd596147aa",
"name": "Solar > 0 kW",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "gt",
"v": "0",
"vt": "num"
},
{
"t": "eq",
"v": "0",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 570,
"y": 960,
"wires": [
[
"b4f157d3b6c708e3"
],
[]
]
},
{
"id": "806e48e11708bd9e",
"type": "delay",
"z": "d20b09cd596147aa",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "5",
"rateUnits": "minute",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 1,
"x": 200,
"y": 1080,
"wires": [
[
"de69c4f8af46cde2"
]
]
},
{
"id": "dab9474fcaf0e0de",
"type": "poll-state",
"z": "d20b09cd596147aa",
"name": "poll: Left Panel Home Load > 2A",
"server": "648c9330.06d6dc",
"version": 2,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"updateinterval": "15",
"updateIntervalType": "num",
"updateIntervalUnits": "minutes",
"outputinitially": false,
"outputonchanged": false,
"entity_id": "sensor.left_powerwall_load_now",
"state_type": "num",
"halt_if": "2",
"halt_if_type": "num",
"halt_if_compare": "gt",
"outputs": 2,
"x": 210,
"y": 640,
"wires": [
[
"a9598bfb97cc562b"
],
[]
]
},
{
"id": "a53e9d5b93ad8092",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "Already Charging",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 910,
"y": 460,
"wires": []
},
{
"id": "16069f2a3ffa40b2",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "Not Charging",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 890,
"y": 580,
"wires": []
},
{
"id": "ab69aa5d32f2fbdc",
"type": "link out",
"z": "d20b09cd596147aa",
"name": "Tesla Charged",
"mode": "link",
"links": [
"917d2b7331620476"
],
"x": 1095,
"y": 820,
"wires": []
},
{
"id": "917d2b7331620476",
"type": "link in",
"z": "d20b09cd596147aa",
"name": "On Tesla Charged",
"links": [
"ab69aa5d32f2fbdc",
"b7d10f9411a710e7"
],
"x": 55,
"y": 1460,
"wires": [
[
"a4d7138a3fe90be7"
]
]
},
{
"id": "1812ac23d4bcd65e",
"type": "tesla-api",
"z": "d20b09cd596147aa",
"teslaConfig": "fe38402395c8c90c",
"command": "setChargingAmps",
"name": "setChargingAmps",
"vehicleID": "1492931888111677",
"autoWakeUp": true,
"x": 410,
"y": 1460,
"wires": [
[
"f74bc545ea5f43bd"
]
]
},
{
"id": "f74bc545ea5f43bd",
"type": "debug",
"z": "d20b09cd596147aa",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 630,
"y": 1460,
"wires": []
},
{
"id": "a4d7138a3fe90be7",
"type": "change",
"z": "d20b09cd596147aa",
"name": "Amps = 40",
"rules": [
{
"t": "set",
"p": "commandArgs.amps",
"pt": "msg",
"to": "40",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 190,
"y": 1460,
"wires": [
[
"1812ac23d4bcd65e"
]
]
},
{
"id": "ed05e56df053385f",
"type": "comment",
"z": "d20b09cd596147aa",
"name": "When Tesla Auto is Charged",
"info": "",
"x": 160,
"y": 1400,
"wires": []
},
{
"id": "2d9eed936a680725",
"type": "inject",
"z": "d20b09cd596147aa",
"name": "",
"props": [],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 290,
"y": 440,
"wires": [
[
"a9598bfb97cc562b"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment