Skip to content

Instantly share code, notes, and snippets.

@SoulOnFire
Created February 2, 2021 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoulOnFire/b959cd00c3d95e1c1572feda9ad44197 to your computer and use it in GitHub Desktop.
Save SoulOnFire/b959cd00c3d95e1c1572feda9ad44197 to your computer and use it in GitHub Desktop.
[
{
"id": "853f1020.0e997",
"type": "tab",
"label": "Rega",
"disabled": false,
"info": ""
},
{
"id": "a614550a.bf8e58",
"type": "server-state-changed",
"z": "853f1020.0e997",
"name": "irrigation enabled",
"server": "d4b3797c.627ba8",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "input_boolean.irrigation_enable",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 2,
"output_only_on_state_change": true,
"for": "",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"x": 640,
"y": 120,
"wires": [
[
"904fc43e.45e828"
],
[]
]
},
{
"id": "9d7f9aa2.dadae8",
"type": "server-state-changed",
"z": "853f1020.0e997",
"name": "cycle input changed value",
"server": "d4b3797c.627ba8",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "(input_select\\.irrigation_cycle[1-3]_schedule_time)|(input_boolean.day_.*)",
"entityidfiltertype": "regex",
"outputinitially": false,
"state_type": "str",
"haltifstate": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 1,
"output_only_on_state_change": true,
"for": "",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"x": 650,
"y": 180,
"wires": [
[
"904fc43e.45e828"
]
]
},
{
"id": "add8b388.ab4c3",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "get cycle1 time state",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 2,
"halt_if": "^([0-2][0-9]:[0-5][0-9]|Desativado)$",
"halt_if_type": "re",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "input_select.irrigation_cycle1_schedule_time",
"state_type": "str",
"state_location": "irrigation.cycle[0]",
"override_payload": "msg",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 320,
"y": 180,
"wires": [
[
"9477625c.895c2"
],
[]
]
},
{
"id": "9477625c.895c2",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "get cycle2 time state",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 2,
"halt_if": "^([0-2][0-9]:[0-5][0-9]|Desativado)$",
"halt_if_type": "re",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "input_select.irrigation_cycle2_schedule_time",
"state_type": "str",
"state_location": "irrigation.cycle[1]",
"override_payload": "msg",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 320,
"y": 240,
"wires": [
[
"1584b7ec.8c2e38"
],
[]
]
},
{
"id": "1584b7ec.8c2e38",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "get cycle3 time state",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 2,
"halt_if": "^([0-2][0-9]:[0-5][0-9]|Desativado)$",
"halt_if_type": "re",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "input_select.irrigation_cycle3_schedule_time",
"state_type": "str",
"state_location": "irrigation.cycle[2]",
"override_payload": "msg",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 320,
"y": 300,
"wires": [
[
"ff758b0.353fb78"
],
[]
]
},
{
"id": "171bee93.d73281",
"type": "function",
"z": "853f1020.0e997",
"name": "logic",
"func": "function addZero(i) {\n if (i < 10) {\n i = \"0\" + i;\n }\n return i;\n}\n\nvar current_date = new Date();\nvar current_time = addZero(current_date.getHours()) + \":\" + addZero(current_date.getMinutes());\n\nvar result = [];\nvar day;\nvar time_lowest = \"24:00\";\nvar tmp;\nvar i;\n\nif (msg.weekdays.some(w => w.state == 'on') && msg.irrigation.cycle.some(c => c != 'Desativado' )){\n msg.irrigation.cycle.forEach(function(element){\n \n if (element != \"Desativado\" && msg.weekdays[current_date.getDay()].state == 'on'){\n if (current_time <= element){\n result.push(element);\n day = \"today\";\n }\n }\n });\n if (day == 'today'){\n for (i=result.length-1; i>=0; i--) {\n tmp = result[i];\n if (tmp < time_lowest) time_lowest = tmp;\n }\n } else {\n var aux = 0;\n do {\n current_date.setDate(current_date.getDate()+1); \n aux++;\n }\n while(aux > 8 || msg.weekdays[current_date.getDay()].state != 'on')\n \n for (i=msg.irrigation.cycle.length-1; i>=0; i--) {\n tmp = msg.irrigation.cycle[i];\n if (tmp < time_lowest) time_lowest = tmp;\n }\n }\n msg.time = time_lowest+\":00\";\n msg.date = current_date.getFullYear()+\"-\"+(addZero(current_date.getMonth()+1))+\"-\"+addZero(current_date.getDate());\n reset = {};\n reset.reset = true;\n return [null, reset, msg];\n} else {\n return [msg, null, null];\n}",
"outputs": 3,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 670,
"y": 360,
"wires": [
[
"201769dc.101716"
],
[
"201769dc.101716"
],
[
"8883f670.18c648"
]
]
},
{
"id": "8883f670.18c648",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "set next irrigation date time",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "input_datetime",
"service": "set_datetime",
"entityId": "input_datetime.irrigation_next_run_time",
"data": "{\"date\":\"{{date}}\",\"time\":\"{{time}}\"}",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 900,
"y": 420,
"wires": [
[]
]
},
{
"id": "7dd71b5.44838e4",
"type": "inject",
"z": "853f1020.0e997",
"name": "every 5 minutes",
"repeat": "300",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 130,
"y": 120,
"wires": [
[
"add8b388.ab4c3",
"3cdb7142.90c7de"
]
]
},
{
"id": "904fc43e.45e828",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"ba13e501.ddfeb8",
"e7241119.397ee"
],
"x": 815,
"y": 140,
"wires": []
},
{
"id": "ba13e501.ddfeb8",
"type": "link in",
"z": "853f1020.0e997",
"name": "",
"links": [
"904fc43e.45e828",
"77b03464.3d94ec"
],
"x": 55,
"y": 60,
"wires": [
[
"7296ccb2.0b1c84"
]
]
},
{
"id": "7296ccb2.0b1c84",
"type": "stoptimer",
"z": "853f1020.0e997",
"duration": "50",
"units": "Millisecond",
"payloadtype": "num",
"payloadval": "0",
"name": "",
"x": 220,
"y": 60,
"wires": [
[
"add8b388.ab4c3"
],
[]
]
},
{
"id": "8335e9cb.790e08",
"type": "comment",
"z": "853f1020.0e997",
"name": "irrigate zone",
"info": "",
"x": 70,
"y": 720,
"wires": []
},
{
"id": "76600e1f.2d2c6",
"type": "link in",
"z": "853f1020.0e997",
"name": "",
"links": [
"6e569955.0cc0e8"
],
"x": 15,
"y": 1060,
"wires": [
[
"2e1030cf.0c9c2"
]
]
},
{
"id": "cd4a5856.8cdfa8",
"type": "stoptimer",
"z": "853f1020.0e997",
"duration": "10",
"units": "Second",
"payloadtype": "num",
"payloadval": "0",
"name": "wait 10 sec",
"x": 690,
"y": 1060,
"wires": [
[
"940539d7.725d28"
],
[]
]
},
{
"id": "1d751c63.c92a14",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "update status",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "input_text",
"service": "set_value",
"entityId": "input_text.irrigation_status",
"data": "{\"value\":\"A regar: Sector {{irrigation.zone}}\"}",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 80,
"y": 1140,
"wires": [
[
"cf2b51dd.1df8c"
]
]
},
{
"id": "a5a7bd92.e7c16",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn valve on",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "switch",
"service": "turn_on",
"entityId": "switch.irrigation_zone{{irrigation.zone}}_valve",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 1110,
"y": 1060,
"wires": [
[
"1d751c63.c92a14"
]
]
},
{
"id": "4e59050d.cc585c",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"d8839773.fb7fc8"
],
"x": 475,
"y": 1020,
"wires": []
},
{
"id": "5824331e.eea41c",
"type": "comment",
"z": "853f1020.0e997",
"name": "set next irrigation time",
"info": "",
"x": 100,
"y": 20,
"wires": []
},
{
"id": "60d42afc.7c0ba4",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn valve off",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "switch",
"service": "turn_off",
"entityId": "switch.irrigation_zone{{irrigation.zone}}_valve",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 550,
"y": 1140,
"wires": [
[
"95b9c55.fa56e38"
]
]
},
{
"id": "abcac6c1.8a45e8",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "update status",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "input_text",
"service": "set_value",
"entityId": "input_text.irrigation_status",
"data": "{\"value\":\"A alterar sector...\"}",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 940,
"y": 1140,
"wires": [
[
"6cb5ac4a.0fe2a4"
]
]
},
{
"id": "6cb5ac4a.0fe2a4",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"d8839773.fb7fc8"
],
"x": 1055,
"y": 1140,
"wires": []
},
{
"id": "f49a686e.73fcb8",
"type": "switch",
"z": "853f1020.0e997",
"name": "zones left?",
"property": "irrigation.irrigate",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 330,
"y": 880,
"wires": [
[
"6e569955.0cc0e8"
],
[
"905d84a2.94a398"
]
]
},
{
"id": "d8839773.fb7fc8",
"type": "link in",
"z": "853f1020.0e997",
"name": "",
"links": [
"4e59050d.cc585c",
"6cb5ac4a.0fe2a4",
"c81fb210.a833",
"db965fec.bcf16",
"ea17ae82.d498a"
],
"x": 55,
"y": 780,
"wires": [
[
"20ddfcbe.2ae214"
]
]
},
{
"id": "6e569955.0cc0e8",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"76600e1f.2d2c6"
],
"x": 475,
"y": 840,
"wires": []
},
{
"id": "5a260750.45b338",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "update status",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "input_text",
"service": "set_value",
"entityId": "input_text.irrigation_status",
"data": "{\"value\":\"Parado\"}",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 780,
"y": 880,
"wires": [
[
"f067557.b2587a8"
]
]
},
{
"id": "77b03464.3d94ec",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"ba13e501.ddfeb8"
],
"x": 595,
"y": 940,
"wires": []
},
{
"id": "3a8897b5.45b258",
"type": "function",
"z": "853f1020.0e997",
"name": "set/update vars",
"func": "if (typeof msg.irrigation == 'undefined'){\n msg.irrigation = {};\n msg.irrigation.zone = 1;\n msg.irrigation.total_zones = 4;\n msg.irrigation.total_time = 0;\n msg.irrigation.irrigate = true;\n} else {\n msg.irrigation.zone++;\n msg.irrigation.total_time += msg.irrigation.duration;\n if (msg.irrigation.zone > msg.irrigation.total_zones){\n msg.irrigation.irrigate = false;\n msg.irrigation.zone = null;\n }\n}\nmsg.payload={};\n(msg.irrigation.zone === null) ? delete msg.payload.entity_id : msg.payload.entity_id = 'input_number.irrigation_zone'+msg.irrigation.zone+'_duration' ;\n// msg.payload.entity_id = 'input_number.irrigation_zone'+msg.irrigation.zone+'_duration';\nnode.status({fill:'blue',shape:'dot',text:msg.irrigation.zone});\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 140,
"y": 880,
"wires": [
[
"f49a686e.73fcb8"
]
]
},
{
"id": "5076c19c.1d414",
"type": "inject",
"z": "853f1020.0e997",
"name": "every minute",
"repeat": "60",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 580,
"wires": [
[
"47b5169e.8d28f8"
]
]
},
{
"id": "e9539709.1967b8",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "get next run time ",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "input_datetime.irrigation_next_run_time",
"state_type": "str",
"state_location": "nextrt",
"override_payload": "msg",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 90,
"y": 640,
"wires": [
[
"2fff8878.bbad28"
]
]
},
{
"id": "710fe6f3.2f0a18",
"type": "moment",
"z": "853f1020.0e997",
"name": "format time",
"topic": "",
"input": "now",
"inputType": "msg",
"inTz": "ETC/GMT",
"adjAmount": 0,
"adjType": "days",
"adjDir": "add",
"format": "HH:mm",
"locale": "en_US",
"output": "now",
"outputType": "msg",
"outTz": "Europe/Lisbon",
"x": 870,
"y": 580,
"wires": [
[
"e9539709.1967b8"
]
]
},
{
"id": "41af1a31.79a744",
"type": "switch",
"z": "853f1020.0e997",
"name": "time equals",
"property": "now",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "nextrt",
"vt": "msg"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 470,
"y": 640,
"wires": [
[
"8170972f.7feb48"
]
]
},
{
"id": "528b2296.6e50cc",
"type": "change",
"z": "853f1020.0e997",
"name": "set to now",
"rules": [
{
"t": "set",
"p": "now",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 710,
"y": 580,
"wires": [
[
"710fe6f3.2f0a18"
]
]
},
{
"id": "2fff8878.bbad28",
"type": "moment",
"z": "853f1020.0e997",
"name": "format time",
"topic": "",
"input": "nextrt",
"inputType": "msg",
"inTz": "Europe/Lisbon",
"adjAmount": 0,
"adjType": "days",
"adjDir": "add",
"format": "HH:mm",
"locale": "en_US",
"output": "nextrt",
"outputType": "msg",
"outTz": "Europe/Lisbon",
"x": 290,
"y": 640,
"wires": [
[
"41af1a31.79a744"
]
]
},
{
"id": "92874975.fcc868",
"type": "comment",
"z": "853f1020.0e997",
"name": "cheking if it's time to start irrigate",
"info": "",
"x": 130,
"y": 520,
"wires": []
},
{
"id": "47b5169e.8d28f8",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "is enabled?",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "input_boolean.irrigation_enable",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 290,
"y": 580,
"wires": [
[
"641c3c8c.30ad34"
],
[]
]
},
{
"id": "db965fec.bcf16",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"d8839773.fb7fc8"
],
"x": 795,
"y": 640,
"wires": []
},
{
"id": "65d1f2e3.61b06c",
"type": "moment",
"z": "853f1020.0e997",
"name": "set time",
"topic": "",
"input": "",
"inputType": "date",
"inTz": "ETC/GMT",
"adjAmount": 0,
"adjType": "days",
"adjDir": "add",
"format": "HH:mm",
"locale": "en_US",
"output": "time",
"outputType": "msg",
"outTz": "Europe/Lisbon",
"x": 240,
"y": 960,
"wires": [
[
"2d27f951.043076"
]
]
},
{
"id": "b8570bfb.19b528",
"type": "moment",
"z": "853f1020.0e997",
"name": "set date",
"topic": "",
"input": "",
"inputType": "date",
"inTz": "ETC/GMT",
"adjAmount": 0,
"adjType": "days",
"adjDir": "add",
"format": "YYYY-MM-DD",
"locale": "en_US",
"output": "date",
"outputType": "msg",
"outTz": "Europe/Lisbon",
"x": 80,
"y": 960,
"wires": [
[
"65d1f2e3.61b06c"
]
]
},
{
"id": "2d27f951.043076",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "set last time irrigated",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_datetime",
"service": "set_datetime",
"entityId": "input_datetime.irrigation_last_time_irrigated",
"data": "{\"date\":\"{{date}}\",\"time\":\"{{time}}\"}",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 440,
"y": 960,
"wires": [
[
"77b03464.3d94ec",
"5c14f4f1.e50e8c",
"979ca791.527408"
]
]
},
{
"id": "ec45de34.2edbe",
"type": "server-state-changed",
"z": "853f1020.0e997",
"name": "turn on manual activation",
"server": "d4b3797c.627ba8",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "input_boolean.irrigation_manual_run",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 2,
"output_only_on_state_change": true,
"for": "",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"x": 110,
"y": 1280,
"wires": [
[
"1c8a8d60.e81173"
],
[
"b4ae520f.44537"
]
]
},
{
"id": "ea17ae82.d498a",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"d8839773.fb7fc8"
],
"x": 735,
"y": 1360,
"wires": []
},
{
"id": "a8c44304.c026d",
"type": "comment",
"z": "853f1020.0e997",
"name": "manual activation",
"info": "",
"x": 80,
"y": 1220,
"wires": []
},
{
"id": "905d84a2.94a398",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn off manual run switch",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_manual_run",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 550,
"y": 880,
"wires": [
[
"5a260750.45b338"
]
]
},
{
"id": "b1aa3f30.83265",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "notify",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "notify",
"service": "alexa_media",
"entityId": "media_player.fernando_s_echo_dot",
"data": "{\"message\":\"Acabou a rega. Tempo total de rega: {{irrigation.total_time}} min\",\"data\":{\"type\":\"tts\"}}",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 890,
"y": 1000,
"wires": [
[]
]
},
{
"id": "65734a9a.1da264",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn valves off",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "switch",
"service": "turn_off",
"entityId": "group.irrigation_valves",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 560,
"y": 1240,
"wires": [
[
"da4d7c3d.5eb54"
]
]
},
{
"id": "52097031.a98aa",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "fetch duration",
"server": "d4b3797c.627ba8",
"version": "1",
"outputs": 2,
"halt_if": "^([^0]|[^0][0])$",
"halt_if_type": "re",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "",
"state_type": "num",
"state_location": "irrigation.duration",
"override_payload": "msg",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 340,
"y": 1060,
"wires": [
[
"ed6830d1.4f29a"
],
[
"4e59050d.cc585c"
]
]
},
{
"id": "cf2b51dd.1df8c",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "start timer",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "timer",
"service": "start",
"entityId": "timer.irrigation_cycle_zone_duration",
"data": "{\"duration\":\"00:{{irrigation.duration}}:00\"}",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 240,
"y": 1140,
"wires": [
[
"8c6313f9.a7759"
]
]
},
{
"id": "8c6313f9.a7759",
"type": "ha-wait-until",
"z": "853f1020.0e997",
"name": "",
"server": "d4b3797c.627ba8",
"outputs": 2,
"entityId": "timer.irrigation_cycle_zone_duration",
"entityIdFilterType": "exact",
"property": "state",
"comparator": "is",
"value": "idle",
"valueType": "str",
"timeout": "11",
"timeoutType": "num",
"timeoutUnits": "minutes",
"entityLocation": "",
"entityLocationType": "none",
"checkCurrentState": true,
"blockInputOverrides": true,
"x": 380,
"y": 1140,
"wires": [
[
"60d42afc.7c0ba4"
],
[
"60d42afc.7c0ba4"
]
]
},
{
"id": "ff758b0.353fb78",
"type": "function",
"z": "853f1020.0e997",
"name": "check if ordered",
"func": "msg.irrigation.sorted_cycle = msg.irrigation.cycle.slice(0).sort();\n\nif (msg.irrigation.cycle.toString() == msg.irrigation.sorted_cycle.toString()){\n msg.payload = \"time input sorted\";\n node.status({fill:'green',shape:'ring',text:msg.payload});\n return [msg, null];\n} else {\n msg.payload = \"time input NOT sorted\";\n node.status({fill:'red',shape:'ring',text:msg.payload});\n return [null, msg];\n}",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 120,
"y": 380,
"wires": [
[
"11dc32a4.0b024d"
],
[
"473e2ded.25a7d4"
]
]
},
{
"id": "11dc32a4.0b024d",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "is enabled?",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "input_boolean.irrigation_enable",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 330,
"y": 380,
"wires": [
[
"37088107.c0ac1e"
],
[]
]
},
{
"id": "5fb837e1.2ff708",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "set cycles option",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "input_select",
"service": "select_option",
"entityId": "{{payload.entity_id}}",
"data": "{\"option\":\"{{payload.value}}\"}",
"dataType": "json",
"mergecontext": "",
"output_location": "payload",
"output_location_type": "msg",
"mustacheAltTags": false,
"x": 260,
"y": 460,
"wires": [
[]
]
},
{
"id": "473e2ded.25a7d4",
"type": "function",
"z": "853f1020.0e997",
"name": "split ",
"func": "function value(n){\n n = parseInt(n-1);\n return msg.irrigation.sorted_cycle[n];\n}\nfunction entity(n){\n return \"input_select.irrigation_cycle\"+n+\"_schedule_time\";\n}\n\nr1 = {\n \"value\": value(1),\n \"entity_id\": entity(1)\n };\nr2 = {\n \"value\": value(2),\n \"entity_id\": entity(2)\n };\nr3 = {\n \"value\": value(3),\n \"entity_id\": entity(3)\n };\nreturn ([{payload: r1}, {payload: r2}, {payload: r3}]);",
"outputs": 3,
"noerr": 0,
"x": 90,
"y": 460,
"wires": [
[
"5fb837e1.2ff708"
],
[
"5fb837e1.2ff708"
],
[
"5fb837e1.2ff708"
]
]
},
{
"id": "a5bab4f1.9cf828",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "notify",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "notify",
"service": "alexa_media",
"entityId": "",
"data": "{\"target\":\"media_player.fernando_s_echo_dot\",\"message\":\"Tempos dos ciclos não definidos\",\"data\":{\"type\":\"tts\"}}",
"dataType": "json",
"mergecontext": "",
"output_location": "payload",
"output_location_type": "msg",
"mustacheAltTags": false,
"x": 990,
"y": 340,
"wires": [
[]
]
},
{
"id": "201769dc.101716",
"type": "trigger",
"z": "853f1020.0e997",
"name": "",
"op1": "",
"op2": "",
"op1type": "pay",
"op2type": "nul",
"duration": "2",
"extend": false,
"overrideDelay": false,
"units": "hr",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 850,
"y": 260,
"wires": [
[
"a5bab4f1.9cf828"
]
]
},
{
"id": "b4ae520f.44537",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "is irrigation on?",
"server": "d4b3797c.627ba8",
"version": "1",
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "binary_sensor.irrigation_running",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 350,
"y": 1240,
"wires": [
[
"65734a9a.1da264"
],
[]
]
},
{
"id": "1c8a8d60.e81173",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "is irrigation off?",
"server": "d4b3797c.627ba8",
"version": "1",
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "binary_sensor.irrigation_running",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 340,
"y": 1340,
"wires": [
[
"c7465875.b91bd8"
],
[
"45192709.b89bf8"
]
]
},
{
"id": "8d4e43b8.ab4ad",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "cancel timer",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "timer",
"service": "cancel",
"entityId": "timer.irrigation_cycle_zone_duration",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 950,
"y": 1240,
"wires": [
[]
]
},
{
"id": "95b9c55.fa56e38",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "irrigation canceled?",
"server": "d4b3797c.627ba8",
"version": "1",
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "input_boolean.irrigation_cancel",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 730,
"y": 1140,
"wires": [
[
"97464d2f.bbe6f"
],
[
"abcac6c1.8a45e8"
]
]
},
{
"id": "97464d2f.bbe6f",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"272e0aa9.edcfa6"
],
"x": 875,
"y": 1180,
"wires": []
},
{
"id": "272e0aa9.edcfa6",
"type": "link in",
"z": "853f1020.0e997",
"name": "",
"links": [
"97464d2f.bbe6f",
"2648fcc.2333904"
],
"x": 155,
"y": 840,
"wires": [
[
"628fba5.23dc044"
]
]
},
{
"id": "5c14f4f1.e50e8c",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "set off irrigation running",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_running",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 750,
"y": 940,
"wires": [
[]
]
},
{
"id": "da4d7c3d.5eb54",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn on cancel switch",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_on",
"entityId": "input_boolean.irrigation_cancel",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 760,
"y": 1240,
"wires": [
[
"8d4e43b8.ab4ad"
]
]
},
{
"id": "628fba5.23dc044",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn off cancel switch",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_cancel",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 300,
"y": 840,
"wires": [
[
"905d84a2.94a398"
]
]
},
{
"id": "f067557.b2587a8",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn valves off",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "switch",
"service": "turn_off",
"entityId": "group.irrigation_valves",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 980,
"y": 880,
"wires": [
[
"b8570bfb.19b528"
]
]
},
{
"id": "45192709.b89bf8",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn off manual switch",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_manual_run",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 580,
"y": 1300,
"wires": [
[]
]
},
{
"id": "940539d7.725d28",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "irrigation canceled?",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "input_boolean.irrigation_cancel",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 890,
"y": 1060,
"wires": [
[
"2648fcc.2333904"
],
[
"a5a7bd92.e7c16"
]
]
},
{
"id": "2648fcc.2333904",
"type": "link out",
"z": "853f1020.0e997",
"name": "",
"links": [
"272e0aa9.edcfa6"
],
"x": 1055,
"y": 1020,
"wires": []
},
{
"id": "2e1030cf.0c9c2",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn valves off",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "switch",
"service": "turn_off",
"entityId": "group.irrigation_valves",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 140,
"y": 1060,
"wires": [
[
"52097031.a98aa"
]
]
},
{
"id": "20ddfcbe.2ae214",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "set on irrigation running",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_on",
"entityId": "input_boolean.irrigation_running",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 210,
"y": 780,
"wires": [
[
"3a8897b5.45b258"
]
]
},
{
"id": "ed6830d1.4f29a",
"type": "change",
"z": "853f1020.0e997",
"name": "del entity_id",
"rules": [
{
"t": "delete",
"p": "payload.entity_id",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 1060,
"wires": [
[
"cd4a5856.8cdfa8"
]
]
},
{
"id": "979ca791.527408",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn off cancel switch",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_cancel",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 720,
"y": 1000,
"wires": [
[
"b1aa3f30.83265"
]
]
},
{
"id": "bf88e300.4958",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn off cancel switch",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_cancel",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 560,
"y": 60,
"wires": [
[]
]
},
{
"id": "3cdb7142.90c7de",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "is irrigation off?",
"server": "d4b3797c.627ba8",
"version": "1",
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "binary_sensor.irrigation_running",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 380,
"y": 120,
"wires": [
[
"bf88e300.4958"
],
[]
]
},
{
"id": "8170972f.7feb48",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn off cancel switch",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_cancel",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 660,
"y": 640,
"wires": [
[
"db965fec.bcf16"
]
]
},
{
"id": "c7465875.b91bd8",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn off cancel switch",
"server": "d4b3797c.627ba8",
"version": "1",
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_cancel",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 580,
"y": 1360,
"wires": [
[
"ea17ae82.d498a"
]
]
},
{
"id": "32d9d3cb.9d3cbc",
"type": "server-state-changed",
"z": "853f1020.0e997",
"name": "irrigation cancel ON",
"server": "d4b3797c.627ba8",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "input_boolean.irrigation_cancel",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 2,
"output_only_on_state_change": true,
"for": "",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"x": 90,
"y": 1460,
"wires": [
[
"4330b7af.1eb8f8"
],
[]
]
},
{
"id": "4330b7af.1eb8f8",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "is irrigation off?",
"server": "d4b3797c.627ba8",
"version": "1",
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "binary_sensor.irrigation_running",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 310,
"y": 1460,
"wires": [
[
"98bad5d3.0e57c8"
],
[]
]
},
{
"id": "98bad5d3.0e57c8",
"type": "api-call-service",
"z": "853f1020.0e997",
"name": "turn off cancel switch",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"service_domain": "input_boolean",
"service": "turn_off",
"entityId": "input_boolean.irrigation_cancel",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 530,
"y": 1460,
"wires": [
[]
]
},
{
"id": "8fb664cc.9cde98",
"type": "comment",
"z": "853f1020.0e997",
"name": "cancel irrigation",
"info": "",
"x": 80,
"y": 1400,
"wires": []
},
{
"id": "37088107.c0ac1e",
"type": "ha-get-entities",
"z": "853f1020.0e997",
"server": "d4b3797c.627ba8",
"name": "get weekdays ",
"rules": [
{
"property": "entity_id",
"logic": "is",
"value": "^input_boolean.day_.*$",
"valueType": "re"
}
],
"output_type": "array",
"output_empty_results": false,
"output_location_type": "msg",
"output_location": "weekdays",
"output_results_count": 1,
"x": 500,
"y": 400,
"wires": [
[
"ed92bbec.1f1b28"
]
]
},
{
"id": "ed92bbec.1f1b28",
"type": "sort",
"z": "853f1020.0e997",
"name": "",
"order": "ascending",
"as_num": true,
"target": "weekdays",
"targetType": "msg",
"msgKey": "$map(entity_id, function($value){\t$value = 'input_boolean.day_sunday' ? '0' :\t$value = 'input_boolean.day_monday' ? '1':\t$value = 'input_boolean.day_tuesday' ? '2':\t$value = 'input_boolean.day_wednesday' ? '3':\t$value = 'input_boolean.day_thursday' ? '4':\t$value = 'input_boolean.day_friday' ? '5':\t$value = 'input_boolean.day_saturday' ? '6': '-1'\t})",
"msgKeyType": "jsonata",
"seqKey": "payload",
"seqKeyType": "msg",
"x": 570,
"y": 300,
"wires": [
[
"171bee93.d73281"
]
]
},
{
"id": "8118033f.b4afc",
"type": "inject",
"z": "853f1020.0e997",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "3600",
"crontab": "",
"once": true,
"onceDelay": "10",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 90,
"y": 1560,
"wires": [
[
"50f6e0b6.6346d"
]
]
},
{
"id": "50f6e0b6.6346d",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "weather.home",
"state_type": "str",
"state_location": "weather",
"override_payload": "msg",
"entity_location": "weather_entity",
"override_data": "msg",
"blockInputOverrides": false,
"x": 320,
"y": 1560,
"wires": [
[
"cd3e3039.d4387"
]
]
},
{
"id": "cd3e3039.d4387",
"type": "function",
"z": "853f1020.0e997",
"name": "",
"func": "msg.precipitation_probability = msg.weather_entity.attributes.forecast.map(f => parseFloat(f.precipitation_probability)).reduce((p,c) => p + c) / msg.weather_entity.attributes.forecast.length;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 540,
"y": 1560,
"wires": [
[
"15a52b11.c5c565"
]
]
},
{
"id": "15a52b11.c5c565",
"type": "http request",
"z": "853f1020.0e997",
"name": "Precipitation",
"method": "GET",
"ret": "txt",
"paytoqs": "ignore",
"url": "https://api.ipma.pt/open-data/observation/climate/precipitation-total/aveiro/mrrto-0113-oliveira-de-azemeis.csv",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 670,
"y": 1640,
"wires": [
[
"e1954472.3ad0d8"
]
]
},
{
"id": "e1954472.3ad0d8",
"type": "function",
"z": "853f1020.0e997",
"name": "Csv to Json",
"func": "// Code added here will be run once\n// whenever the node is deployed.\nfunction csvJSON(csv){\n\n var lines=csv.split(\"\\n\");\n\n var result = [];\n\n // NOTE: If your columns contain commas in their values, you'll need\n // to deal with those before doing the next step \n // (you might convert them to &&& or something, then covert them back later)\n // jsfiddle showing the issue https://jsfiddle.net/\n var headers=lines[0].split(\",\");\n\n for(var i=1;i<lines.length;i++){\n\n var obj = {};\n var currentline=lines[i].split(\",\");\n\n for(var j=0;j<headers.length;j++){\n obj[headers[j]] = currentline[j];\n }\n\n result.push(obj);\n\n }\n\n return result; //JavaScript object\n // return JSON.stringify(result); //JSON\n}\n\nvar ultimosDias = 10;\nvar json = csvJSON(msg.payload);\nmsg.payload = json;\nmsg.how_many_days = ultimosDias;\nmsg.precipitation_yesterday = json.filter(v => !!v.date).slice(-1).map(v => parseFloat(v.mean)).reduce((p,c) => p + c);\nmsg.precipitation_history = json.filter(v => !!v.date).slice(-ultimosDias).map(v => parseFloat(v.mean)).reduce((p,c) => p + c);\nmsg.precipitation_history_average = json.filter(v => !!v.date).slice(-ultimosDias).map(v => parseFloat(v.mean)).reduce((p,c) => p + c) / ultimosDias;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "// Code added here will be run once\n// whenever the node is deployed.\nfunction csvJSON(csv){\n\n var lines=csv.split(\"\\n\");\n\n var result = [];\n\n // NOTE: If your columns contain commas in their values, you'll need\n // to deal with those before doing the next step \n // (you might convert them to &&& or something, then covert them back later)\n // jsfiddle showing the issue https://jsfiddle.net/\n var headers=lines[0].split(\",\");\n\n for(var i=1;i<lines.length;i++){\n\n var obj = {};\n var currentline=lines[i].split(\",\");\n\n for(var j=0;j<headers.length;j++){\n obj[headers[j]] = currentline[j];\n }\n\n result.push(obj);\n\n }\n\n //return result; //JavaScript object\n return JSON.stringify(result); //JSON\n}\n",
"finalize": "",
"x": 830,
"y": 1640,
"wires": [
[
"6b672b3f.4315c4",
"76a649f9.322158"
]
]
},
{
"id": "6b672b3f.4315c4",
"type": "ha-entity",
"z": "853f1020.0e997",
"name": "yesterday precipitation",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"outputs": 1,
"entityType": "sensor",
"config": [
{
"property": "name",
"value": "yesterday_precipitation"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "hass:weather-rainy"
},
{
"property": "unit_of_measurement",
"value": "mm  "
}
],
"state": "$round(precipitation_yesterday, 2)",
"stateType": "jsonata",
"attributes": [
{
"property": "Acumulado últimos dias",
"value": "$round(precipitation_history, 2)&\"mm\"",
"valueType": "jsonata"
},
{
"property": "Média últimos dias",
"value": "$round(precipitation_history_average, 2)&\"mm\"",
"valueType": "jsonata"
},
{
"property": "Probabilidade Precipitação",
"value": "precipitation_probability&\"%\"",
"valueType": "jsonata"
},
{
"property": "Número dias",
"value": "how_many_days",
"valueType": "jsonata"
}
],
"resend": true,
"outputLocation": "",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1100,
"y": 1640,
"wires": [
[]
]
},
{
"id": "76a649f9.322158",
"type": "ha-entity",
"z": "853f1020.0e997",
"name": "irrigation needed",
"server": "d4b3797c.627ba8",
"version": 1,
"debugenabled": false,
"outputs": 1,
"entityType": "binary_sensor",
"config": [
{
"property": "name",
"value": "irrigation_needed"
},
{
"property": "device_class",
"value": ""
},
{
"property": "icon",
"value": "hass:sprinkler-variant"
},
{
"property": "unit_of_measurement",
"value": ""
}
],
"state": "precipitation_yesterday < 1 and precipitation_history < 1 and precipitation_history_average < 1 and $number(probabilidadePrecipitacao) < 50",
"stateType": "jsonata",
"attributes": [],
"resend": true,
"outputLocation": "",
"outputLocationType": "none",
"inputOverride": "allow",
"outputOnStateChange": false,
"outputPayload": "",
"outputPayloadType": "str",
"x": 1090,
"y": 1700,
"wires": [
[]
]
},
{
"id": "2909b66a.68aaea",
"type": "comment",
"z": "853f1020.0e997",
"name": "irrigation nedded based on precipitation and forecast",
"info": "",
"x": 200,
"y": 1520,
"wires": []
},
{
"id": "641c3c8c.30ad34",
"type": "api-current-state",
"z": "853f1020.0e997",
"name": "is irrigation needed?",
"server": "d4b3797c.627ba8",
"version": 1,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "binary_sensor.irrigation_needed",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 500,
"y": 580,
"wires": [
[
"528b2296.6e50cc"
],
[]
]
},
{
"id": "d518ddfa.d4a84",
"type": "comment",
"z": "853f1020.0e997",
"name": "Change here the url of the precipitation api",
"info": "[https://api.ipma.pt/open-data/observation/climate/precipitation-total/](API IPMA)\n\nEncontrar o distrito/conselho e alterar o url.",
"x": 800,
"y": 1580,
"wires": [],
"icon": "node-red/alert.svg"
},
{
"id": "d4b3797c.627ba8",
"type": "server",
"name": "Home Assistant",
"legacy": false,
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment