Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "id": "92c3441fccf0c72a",
- "type": "tab",
- "label": "Tesla PV DLM",
- "disabled": false,
- "info": "",
- "env": []
- },
- {
- "id": "5eae9844675693c3",
- "type": "function",
- "z": "92c3441fccf0c72a",
- "name": "Kw PV",
- "func": "// Inizio con acquisire i dati di potenza dei vari sensori di inverter wallbox prelievo da rete e invio in rete\nvar power1 = global.get('homeassistant.homeAssistant.states[\"sensor.input_power\"].state');\nvar power2 = global.get('homeassistant.homeAssistant.states[\"sensor.wallbox_em_channel_1_power\"].state');\nvar power3 = global.get('homeassistant.homeAssistant.states[\"sensor.active_power\"].state');\nvar power4 = global.get('homeassistant.homeAssistant.states[\"sensor.pv_to_grid_kwp\"].state');\n\nlet w1 = parseFloat(power1);\nlet w2 = parseFloat(power2);\nlet w3 = parseFloat(power3);\nlet w4 = parseFloat(power4);\n\n// calcolo la potenza da fotovoltaico disponibile al netto dei consumi della casa \nlet y = w1 - w3 + w4 + w2;\n\n// acquisisco il dato del voltaggio corrente che servira per il calcolo della potenza moltiplicandolo per gli ampere \nvar power5 = global.get('homeassistant.homeAssistant.states[\"sensor.grid_voltage\"].state');\nlet w5 = parseFloat(power5);\n\n\nlet x = 1; // Inizio la sequenza con x = 1 per trovare il valore da settare in ampere per la tesla\n\nwhile (x * w5 < y) {\n x++;\n}\n\nif (x * w5 > y) {\n x--; // Preseguo fino a quando supera y e quindi diminuisco x di una unità\n}\n\nif (x < 1) {\n x = 1; // Mi assicuro che il valore minimo di x sia 1\n}\n\nmsg.payload = x; // Setto il valore di x come payload del messaggio e lo passo al nodo successivo\nreturn msg;\n",
- "outputs": 1,
- "timeout": 0,
- "noerr": 0,
- "initialize": "",
- "finalize": "",
- "libs": [],
- "x": 350,
- "y": 160,
- "wires": [
- [
- "9ae92e887891e4b7"
- ]
- ]
- },
- {
- "id": "9ae92e887891e4b7",
- "type": "api-call-service",
- "z": "92c3441fccf0c72a",
- "name": "Set Amp Value",
- "server": "1c37c350.3f926d",
- "version": 5,
- "debugenabled": true,
- "domain": "number",
- "service": "set_value",
- "areaId": [],
- "deviceId": [],
- "entityId": [
- "number.charging_amps"
- ],
- "data": "{\"value\": payload}",
- "dataType": "jsonata",
- "mergeContext": "",
- "mustacheAltTags": false,
- "outputProperties": [],
- "queue": "none",
- "x": 460,
- "y": 220,
- "wires": [
- [
- "6d3e633a6d4a37e1"
- ]
- ]
- },
- {
- "id": "6d3e633a6d4a37e1",
- "type": "switch",
- "z": "92c3441fccf0c72a",
- "name": "",
- "property": "payload",
- "propertyType": "msg",
- "rules": [
- {
- "t": "eq",
- "v": "error",
- "vt": "msg"
- },
- {
- "t": "else"
- }
- ],
- "checkall": "true",
- "repair": false,
- "outputs": 2,
- "x": 650,
- "y": 220,
- "wires": [
- [
- "ba2a67a88932fc6e"
- ],
- [
- "b84537dbce56c0b4"
- ]
- ]
- },
- {
- "id": "ba2a67a88932fc6e",
- "type": "delay",
- "z": "92c3441fccf0c72a",
- "name": "Repeat on error",
- "pauseType": "delay",
- "timeout": "5",
- "timeoutUnits": "seconds",
- "rate": "1",
- "nbRateUnits": "1",
- "rateUnits": "second",
- "randomFirst": "1",
- "randomLast": "5",
- "randomUnits": "seconds",
- "drop": false,
- "allowrate": false,
- "outputs": 1,
- "x": 520,
- "y": 100,
- "wires": [
- [
- "5eae9844675693c3"
- ]
- ]
- },
- {
- "id": "023d82e4c90c607e",
- "type": "function",
- "z": "92c3441fccf0c72a",
- "name": "Check PV Kw",
- "func": "// Ottengo i valori di potenza dai sensori in Home Assistant\nvar power1 = global.get('homeassistant.homeAssistant.states[\"sensor.input_power\"].state');\nvar power2 = global.get('homeassistant.homeAssistant.states[\"sensor.wallbox_em_channel_1_power\"].state');\nvar power3 = global.get('homeassistant.homeAssistant.states[\"sensor.active_power\"].state');\nvar power4 = global.get('homeassistant.homeAssistant.states[\"sensor.pv_to_grid_kwp\"].state');\n\nlet w1 = parseFloat(power1);\nlet w2 = parseFloat(power2);\nlet w3 = parseFloat(power3);\nlet w4 = parseFloat(power4);\n\n// Calcolo la somma delle potenze per avere il netto da fotovoltiaco\nlet y = w1 - w3 + w4 + w2;\n\n// Ottengo il valore di tensione di rete\nvar power5 = global.get('homeassistant.homeAssistant.states[\"sensor.grid_voltage\"].state');\nlet w5 = parseFloat(power5);\n\n// Ottengo lo stato degli ampere settati in Tesla\nvar ampere1 = global.get('homeassistant.homeAssistant.states[\"number.charging_amps\"].state');\nlet a1 = parseFloat(ampere1);\n\n// Calcolo il valore della potenza di 1 ampere\nlet x = w5 * 1;\n\n// Calcolo la differenza tra potenza residua e 1 ampere\nlet z = y - x;\n\n// Verifico le condizioni e setto il payload\nif (z > 0 && z > x) {\n msg.payload = 1; // Se z è maggiore di zero e maggiore di x, imposto payload a 1, cioè ho potenza disponibile e devo aumentare gli ampere di Tesla\n} else if (z > 0 && z < x) {\n msg.payload = 0; // Se z è maggiore di zero e minore di x, imposto payload a 0, cioè non ho potenza sufficente per aumentare di 1 ampere la carica di Tesla\n} else if (z < 0 && a1 === 1) {\n msg.payload = 0; // Se z è minore di zero e a1 è 1, imposto payload sempre a 0, ho potenza netta da PV negativa ma ampere Tesla è già 1 e quindi non posso diminuirlo ulteriormente\n} else {\n msg.payload = 1; // ho potenza netta da pv negativa e quindi devo ridurre ampere Tesla\n}\n\nreturn msg;",
- "outputs": 1,
- "timeout": 0,
- "noerr": 0,
- "initialize": "",
- "finalize": "",
- "libs": [],
- "x": 880,
- "y": 200,
- "wires": [
- [
- "a9a0d4f71b0df33c"
- ]
- ]
- },
- {
- "id": "b84537dbce56c0b4",
- "type": "delay",
- "z": "92c3441fccf0c72a",
- "name": "Delay",
- "pauseType": "delay",
- "timeout": "5",
- "timeoutUnits": "seconds",
- "rate": "1",
- "nbRateUnits": "1",
- "rateUnits": "second",
- "randomFirst": "1",
- "randomLast": "5",
- "randomUnits": "seconds",
- "drop": false,
- "allowrate": false,
- "outputs": 1,
- "x": 670,
- "y": 280,
- "wires": [
- [
- "023d82e4c90c607e"
- ]
- ]
- },
- {
- "id": "a9a0d4f71b0df33c",
- "type": "switch",
- "z": "92c3441fccf0c72a",
- "name": "",
- "property": "payload",
- "propertyType": "msg",
- "rules": [
- {
- "t": "eq",
- "v": "0",
- "vt": "num"
- },
- {
- "t": "eq",
- "v": "1",
- "vt": "num"
- }
- ],
- "checkall": "true",
- "repair": false,
- "outputs": 2,
- "x": 910,
- "y": 360,
- "wires": [
- [
- "12231880eba72e9a"
- ],
- [
- "d85fb9a663ec890c"
- ]
- ]
- },
- {
- "id": "12231880eba72e9a",
- "type": "delay",
- "z": "92c3441fccf0c72a",
- "name": "Delay",
- "pauseType": "delay",
- "timeout": "5",
- "timeoutUnits": "seconds",
- "rate": "1",
- "nbRateUnits": "1",
- "rateUnits": "second",
- "randomFirst": "1",
- "randomLast": "5",
- "randomUnits": "seconds",
- "drop": false,
- "allowrate": false,
- "outputs": 1,
- "x": 890,
- "y": 260,
- "wires": [
- [
- "023d82e4c90c607e"
- ]
- ]
- },
- {
- "id": "c1a4eb5bcf897556",
- "type": "trigger-state",
- "z": "92c3441fccf0c72a",
- "name": "Tesla Charger ON",
- "server": "1c37c350.3f926d",
- "version": 4,
- "inputs": 0,
- "outputs": 2,
- "exposeAsEntityConfig": "",
- "entityId": "switch.charger",
- "entityIdType": "exact",
- "debugEnabled": false,
- "constraints": [
- {
- "targetType": "this_entity",
- "targetValue": "",
- "propertyType": "current_state",
- "propertyValue": "new_state.state",
- "comparatorType": "is",
- "comparatorValueDatatype": "str",
- "comparatorValue": "on"
- },
- {
- "targetType": "this_entity",
- "targetValue": "",
- "propertyType": "previous_state",
- "propertyValue": "old_state.state",
- "comparatorType": "is",
- "comparatorValueDatatype": "str",
- "comparatorValue": "off"
- }
- ],
- "customOutputs": [],
- "outputInitially": false,
- "stateType": "str",
- "enableInput": false,
- "exposeToHomeAssistant": false,
- "haConfig": [
- {
- "property": "name",
- "value": ""
- },
- {
- "property": "icon",
- "value": ""
- }
- ],
- "x": 110,
- "y": 80,
- "wires": [
- [
- "3f70a3d940f291bb"
- ],
- []
- ]
- },
- {
- "id": "3f70a3d940f291bb",
- "type": "api-current-state",
- "z": "92c3441fccf0c72a",
- "name": "Tesla is at Home",
- "server": "1c37c350.3f926d",
- "version": 3,
- "outputs": 2,
- "halt_if": "home",
- "halt_if_type": "str",
- "halt_if_compare": "is",
- "entity_id": "device_tracker.location_tracker",
- "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": 140,
- "y": 160,
- "wires": [
- [
- "5eae9844675693c3"
- ],
- []
- ]
- },
- {
- "id": "d85fb9a663ec890c",
- "type": "api-current-state",
- "z": "92c3441fccf0c72a",
- "name": "if on Charger",
- "server": "1c37c350.3f926d",
- "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": 330,
- "y": 360,
- "wires": [
- [
- "5eae9844675693c3"
- ],
- []
- ]
- },
- {
- "id": "1c37c350.3f926d",
- "type": "server",
- "name": "Home Assistant",
- "version": 5,
- "addon": true,
- "rejectUnauthorizedCerts": true,
- "ha_boolean": "y|yes|true|on|home|open",
- "connectionDelay": true,
- "cacheJson": true,
- "heartbeat": false,
- "heartbeatInterval": "30",
- "areaSelector": "id",
- "deviceSelector": "id",
- "entitySelector": "id",
- "statusSeparator": "at: ",
- "statusYear": "hidden",
- "statusMonth": "short",
- "statusDay": "numeric",
- "statusHourCycle": "h23",
- "statusTimeFormat": "h:m",
- "enableGlobalContextStore": true
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement