-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow.json
1 lines (1 loc) · 7.93 KB
/
flow.json
1
[{"id":"c61c4d4d.4e57f","type":"function","z":"7d3776b649989fee","name":"Calculate Amps","func":"//State\n//1 - Not plugged into car\n//4 - Plugged in but not charging\n//9 - Plugged in but not charging\n//11 - Plugged in and charging\n\nconst exportWatts = parseFloat(msg.exportpower);\nconst importWatts = parseFloat(msg.importpower);\nconst evWatts = parseFloat(msg.evpower);\n\nconst totalWatts = exportWatts + evWatts - importWatts;\n\n\n\nif (!isNaN(totalWatts)) {\n // Convert negative watts to positive\n const watts = Math.abs(totalWatts);\n // Convert watts to amps at 240V\n let amps = Math.round((watts / 240) * Math.pow(10, 0)) / Math.pow(10, 0);\n\n\n if (amps > 32) {\n amps = 32;\n }\n\n //Start Check if active charging\n //If charging is active and have negative grid \n //we will set amps to 5 amps for 5 minutes before stop\n if (totalWatts < 0 && msg.current_state == 11) {\n amps = 1;\n // If totalWatts is negative, set it to zero\n // Check if this is the first time encountering a negative totalWatts value\n let count = context.get('negativeTotalWattsCount') || 0;\n count++;\n context.set('negativeTotalWattsCount', count);\n // If we have seen a negative totalWatts value 5 times in a row, set the amps to 0 and reset the count\n if (count >= 5) {\n amps = 0;\n context.set('negativeTotalWattsCount', 0);\n node.warn(\"teller ned\");\n }\n node.warn(\"skal egentlig slutte\" + count + \" \" + msg.current_state);\n }else if (totalWatts <0 && msg.current_sate !== 11){\n amps = 0;\n context.set('negativeTotalWattsCount', 0);\n }else{\n context.set('negativeTotalWattsCount', 0);\n }\n\n \n msg.amps = amps;\n msg.totalPower = totalWatts;\n\n\n if(amps == 0 && msg.current_state != 11){\n return null\n }else if (msg.current_state != 11 && amps > 10) {\n node.warn(\"Start Charging with amps:\" +amps+\" Current state: \"+msg.current_state);\n return[msg, null, null];\n }else if (amps == 0) {\n msg.amps = 0;\n node.warn(\"Stop Charging!\");\n return [null, msg, null];\n // Check if amps have changed\n } else if (context.get('amps') != amps) {\n node.warn(\"Change to amps:\"+amps);\n context.set('amps', msg.amps)\n return [msg, null, null];\n } else {\n return [null, null, null];\n \n }\n}","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":300,"wires":[["caf37618d6d43509"],["19ed8543f91fbc31"],[]]},{"id":"e1c158186cf24b50","type":"api-current-state","z":"7d3776b649989fee","name":"export power","server":"a7c55e81aa13f774","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.kamstrup_active_power_export","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"exportpower","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":750,"y":120,"wires":[["5de368b2e2a1dcdf"]]},{"id":"ee54b4d82e162014","type":"poll-state","z":"7d3776b649989fee","name":"Is Tesla connected to Wall Connector?","server":"a7c55e81aa13f774","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":true,"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":230,"y":240,"wires":[["337c86a40e8d28c8"],[]]},{"id":"caf37618d6d43509","type":"api-current-state","z":"7d3776b649989fee","name":"Is tesla charging activated?","server":"a7c55e81aa13f774","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.charger","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":1060,"y":220,"wires":[["78d4808a694b49e2"],["6cfc713846931c52"]]},{"id":"6cfc713846931c52","type":"api-call-service","z":"7d3776b649989fee","name":"Activate Charging","server":"a7c55e81aa13f774","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.charger"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1090,"y":280,"wires":[["78d4808a694b49e2"]]},{"id":"78d4808a694b49e2","type":"api-call-service","z":"7d3776b649989fee","name":"Set amps to tesla","server":"a7c55e81aa13f774","version":5,"debugenabled":false,"domain":"number","service":"set_value","areaId":[],"deviceId":[],"entityId":["number.charging_amps"],"data":"{\"value\":{{amps}}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1370,"y":240,"wires":[[]]},{"id":"19ed8543f91fbc31","type":"api-call-service","z":"7d3776b649989fee","name":"Turn Off Charging","server":"a7c55e81aa13f774","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.charger"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1090,"y":400,"wires":[["78d4808a694b49e2"]]},{"id":"5b36a9472974208e","type":"api-current-state","z":"7d3776b649989fee","name":"import power","server":"a7c55e81aa13f774","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.kamstrup_active_power_import","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"importpower","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":750,"y":60,"wires":[["e1c158186cf24b50"]]},{"id":"5de368b2e2a1dcdf","type":"api-current-state","z":"7d3776b649989fee","name":"ev power","server":"a7c55e81aa13f774","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.powercalc_all_ev","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"evpower","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":740,"y":180,"wires":[["c61c4d4d.4e57f"]]},{"id":"337c86a40e8d28c8","type":"api-current-state","z":"7d3776b649989fee","name":"Wall Connector State","server":"a7c55e81aa13f774","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tesla_wall_connector_state","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"current_state","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":460,"y":120,"wires":[["5b36a9472974208e"]]},{"id":"a7c55e81aa13f774","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]