Autostart Genset to have batteries charged by 9PM

Here is the NodeRed code I have so far:

[
{
“id”: “59d6996fb5f99ddd”,
“type”: “tab”,
“label”: “Flow 1”,
“disabled”: false,
“info”: “”,
“env”:
},
{
“id”: “f81820651ae8ac0d”,
“type”: “trigger”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“op1”: “1”,
“op2”: “0”,
“op1type”: “num”,
“op2type”: “num”,
“duration”: “1200”,
“extend”: false,
“overrideDelay”: true,
“units”: “s”,
“reset”: “”,
“bytopic”: “all”,
“topic”: “topic”,
“outputs”: 1,
“x”: 870,
“y”: 260,
“wires”: [
[
“1d16f09c18d7a9f1”,
“d18e40eaf346a9f3”
]
]
},
{
“id”: “4c44408db250b1b5”,
“type”: “http in”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“url”: “/GeneratorManualRun”,
“method”: “get”,
“upload”: false,
“swaggerDoc”: “”,
“x”: 130,
“y”: 260,
“wires”: [
[
“a086e9fbc2d19477”,
“dbd8e022c05f6859”
]
]
},
{
“id”: “a086e9fbc2d19477”,
“type”: “http response”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“statusCode”: “”,
“headers”: {},
“x”: 350,
“y”: 240,
“wires”:
},
{
“id”: “dbd8e022c05f6859”,
“type”: “function”,
“z”: “59d6996fb5f99ddd”,
“name”: “ConvertMessage”,
“func”: “t = msg.payload.RunTime * 1000;\nmsg.delay = t;\nreturn msg;”,
“outputs”: 1,
“timeout”: 0,
“noerr”: 0,
“initialize”: “”,
“finalize”: “”,
“libs”: ,
“x”: 510,
“y”: 260,
“wires”: [
[
“f81820651ae8ac0d”
]
]
},
{
“id”: “1d16f09c18d7a9f1”,
“type”: “debug”,
“z”: “59d6996fb5f99ddd”,
“name”: “GeneratorDebug”,
“active”: true,
“tosidebar”: true,
“console”: false,
“tostatus”: false,
“complete”: “payload”,
“targetType”: “msg”,
“statusVal”: “”,
“statusType”: “auto”,
“x”: 1090,
“y”: 200,
“wires”:
},
{
“id”: “d18e40eaf346a9f3”,
“type”: “victron-output-generator”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.generator/0”,
“path”: “/ManualStart”,
“serviceObj”: {
“service”: “com.victronenergy.generator/0”,
“name”: “Generator start/stop”
},
“pathObj”: {
“path”: “/ManualStart”,
“type”: “enum”,
“name”: “Manual Start”,
“enum”: {
“0”: “Stop generator”,
“1”: “Start generator”
},
“writable”: true
},
“initial”: “”,
“name”: “”,
“onlyChanges”: false,
“x”: 1140,
“y”: 260,
“wires”:
},
{
“id”: “12e862d66cb84895”,
“type”: “victron-input-vebus”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.vebus/289”,
“path”: “/Ac/Out/L1/P”,
“serviceObj”: {
“service”: “com.victronenergy.vebus/289”,
“name”: “Quattro 48/5000/70-2x100 120V”
},
“pathObj”: {
“path”: “/Ac/Out/L1/P”,
“type”: “float”,
“name”: “Output power phase 1 (W)”
},
“name”: “”,
“onlyChanges”: false,
“x”: 240,
“y”: 20,
“wires”: [
[
“d6474a8a4a2c2e97”
]
]
},
{
“id”: “6bb662cd5b79154b”,
“type”: “victron-input-battery”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.battery/288”,
“path”: “/ConsumedAmphours”,
“serviceObj”: {
“service”: “com.victronenergy.battery/288”,
“name”: “SmartShunt IP65 500A/50mV”
},
“pathObj”: {
“path”: “/ConsumedAmphours”,
“type”: “float”,
“name”: “Consumed Amphours (Ah)”
},
“name”: “”,
“onlyChanges”: false,
“x”: 230,
“y”: 80,
“wires”: [
[
“d6474a8a4a2c2e97”
]
]
},
{
“id”: “d6474a8a4a2c2e97”,
“type”: “join”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“mode”: “custom”,
“build”: “object”,
“property”: “payload”,
“propertyType”: “msg”,
“key”: “topic”,
“joiner”: “\n”,
“joinerType”: “str”,
“accumulate”: true,
“timeout”: “”,
“count”: “4”,
“reduceRight”: false,
“reduceExp”: “”,
“reduceInit”: “”,
“reduceInitType”: “”,
“reduceFixup”: “”,
“x”: 590,
“y”: 200,
“wires”: [
[
“b1e84b9f84d84386”
]
]
},
{
“id”: “7d42a47b9ffbfd4a”,
“type”: “debug”,
“z”: “59d6996fb5f99ddd”,
“name”: “CalcDebug”,
“active”: true,
“tosidebar”: true,
“console”: false,
“tostatus”: false,
“complete”: “payload”,
“targetType”: “msg”,
“statusVal”: “”,
“statusType”: “auto”,
“x”: 870,
“y”: 200,
“wires”:
},
{
“id”: “58e2880f0de41fa8”,
“type”: “victron-input-vebus”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.vebus/289”,
“path”: “/Ac/ActiveIn/ActiveInput”,
“serviceObj”: {
“service”: “com.victronenergy.vebus/289”,
“name”: “Quattro 48/5000/70-2x100 120V”
},
“pathObj”: {
“path”: “/Ac/ActiveIn/ActiveInput”,
“type”: “enum”,
“name”: “Active input”,
“enum”: {
“0”: “AC Input 1”,
“1”: “AC Input 2”,
“240”: “Disconnected”
}
},
“initial”: “”,
“name”: “”,
“onlyChanges”: false,
“x”: 190,
“y”: 140,
“wires”: [
[
“d6474a8a4a2c2e97”
]
]
},
{
“id”: “b1e84b9f84d84386”,
“type”: “function”,
“z”: “59d6996fb5f99ddd”,
“name”: “Calc”,
“func”: “// Get the current time\nvar currentTime = new Date();\nvar currentHour = currentTime.getHours();\nvar currentMinutes = currentTime.getMinutes();\n\n// Set the target hour for 9 PM\nvar targetHour = 21;\nvar targetMinutes = 0;\n\nif(msg.payload["Quattro 48/5000/70-2x100 120V - Active input"]==240)\n{\n var aa = (5000 - msg.payload["Quattro 48/5000/70-2x100 120V - Output power phase 1 (W)"])/msg.payload["SmartShunt IP65 500A/50mV - Battery voltage (V)"];\n if(aa > 55) {aa=55;}\n var rt=(Math.abs(msg.payload["SmartShunt IP65 500A/50mV - Consumed Amphours (Ah)"]) / aa) * 3600;\n rt=rt1.25;\n msg.delay = rt1000;\n \n // Calculate the estimated finish time by adding ‘rt’ to the current time\n var finishTime = new Date(currentTime.getTime() + rt * 1000);\n var finishHour = finishTime.getHours();\n var finishMinutes = finishTime.getMinutes();\n \n if (finishHour === targetHour && finishMinutes === targetMinutes && rt > 1200) {\n msg.payload = rt;\n msg.delay = rt * 1000; // Return the delay time in milliseconds\n return msg;\n }\n}\n\n”,
“outputs”: 1,
“timeout”: 0,
“noerr”: 0,
“initialize”: “”,
“finalize”: “”,
“libs”: ,
“x”: 690,
“y”: 200,
“wires”: [
[
“7d42a47b9ffbfd4a”,
“f81820651ae8ac0d”
]
]
},
{
“id”: “362f7ebe941130d0”,
“type”: “victron-input-battery”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.battery/288”,
“path”: “/Dc/0/Voltage”,
“serviceObj”: {
“service”: “com.victronenergy.battery/288”,
“name”: “SmartShunt IP65 500A/50mV”
},
“pathObj”: {
“path”: “/Dc/0/Voltage”,
“type”: “float”,
“name”: “Battery voltage (V)”
},
“name”: “”,
“onlyChanges”: false,
“x”: 210,
“y”: 200,
“wires”: [
[
“d6474a8a4a2c2e97”
]
]
},
{
“id”: “82fefbf8926832fb”,
“type”: “victron-input-vebus”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.vebus/289”,
“path”: “/VebusChargeState”,
“serviceObj”: {
“service”: “com.victronenergy.vebus/289”,
“name”: “Quattro 48/5000/70-2x100 120V”
},
“pathObj”: {
“path”: “/VebusChargeState”,
“type”: “enum”,
“name”: “Charge state”,
“enum”: {
“0”: “Initialising”,
“1”: “Bulk”,
“2”: “Absorption”,
“3”: “Float”,
“4”: “Storage”,
“5”: “Absorb repeat”,
“6”: “Forced absorb”,
“7”: “Equalise”,
“8”: “Bulk stopped”,
“9”: “Unknown”
}
},
“initial”: “”,
“name”: “”,
“onlyChanges”: false,
“x”: 200,
“y”: 360,
“wires”: [
[
“0bf3cfe98ac2222f”
]
]
},
{
“id”: “0b83d12bb5b9aa35”,
“type”: “inject”,
“z”: “59d6996fb5f99ddd”,
“name”: “Reset”,
“props”: [
{
“p”: “reset”,
“v”: “true”,
“vt”: “bool”
}
],
“repeat”: “”,
“crontab”: “”,
“once”: false,
“onceDelay”: 0.1,
“topic”: “”,
“x”: 710,
“y”: 240,
“wires”: [
[
“f81820651ae8ac0d”
]
]
},
{
“id”: “0455a7ea1ae5b3db”,
“type”: “smart_logic”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“logic”: “AND”,
“logic_inputs”: “3”,
“inverts”: “”,
“invert_output”: false,
“out_false”: “{"topic": ""}”,
“out_false_type”: “json”,
“out_true”: “{"topic": ""}”,
“out_true_type”: “json”,
“send_only_change”: “true”,
“outputs”: 1,
“save_state”: false,
“resend_on_start”: true,
“x”: 790,
“y”: 320,
“wires”: [
[
“d5eefec961f4709e”
]
]
},
{
“id”: “d5eefec961f4709e”,
“type”: “trigger”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“op1”: “1”,
“op2”: “”,
“op1type”: “num”,
“op2type”: “payl”,
“duration”: “250”,
“extend”: false,
“overrideDelay”: false,
“units”: “ms”,
“reset”: “”,
“bytopic”: “all”,
“topic”: “topic”,
“outputs”: 1,
“x”: 940,
“y”: 320,
“wires”: [
[
“255e5c529f770149”
]
]
},
{
“id”: “255e5c529f770149”,
“type”: “function”,
“z”: “59d6996fb5f99ddd”,
“name”: “reset”,
“func”: “msg.payload = "reset";\nmsg.reset = true;\nreturn msg;”,
“outputs”: 1,
“timeout”: 0,
“noerr”: 0,
“initialize”: “”,
“finalize”: “”,
“libs”: ,
“x”: 1070,
“y”: 320,
“wires”: [
[
“f81820651ae8ac0d”,
“7aa9870284468666”
]
]
},
{
“id”: “0bf3cfe98ac2222f”,
“type”: “function”,
“z”: “59d6996fb5f99ddd”,
“name”: “RCM”,
“func”: “msg.topic = 1;\nreturn msg;”,
“outputs”: 1,
“timeout”: 0,
“noerr”: 0,
“initialize”: “”,
“finalize”: “”,
“libs”: ,
“x”: 430,
“y”: 320,
“wires”: [
[
“44c56fb6d04d9239”,
“86152e89cd67d896”,
“2841bb27f4f936ab”
]
]
},
{
“id”: “d2f8cf7adb87bb53”,
“type”: “victron-input-battery”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.battery/288”,
“path”: “/Soc”,
“serviceObj”: {
“service”: “com.victronenergy.battery/288”,
“name”: “SmartShunt IP65 500A/50mV”
},
“pathObj”: {
“path”: “/Soc”,
“type”: “float”,
“name”: “State of charge (%)”
},
“name”: “”,
“onlyChanges”: false,
“roundValues”: “2”,
“x”: 710,
“y”: 20,
“wires”: [

]
},
{
“id”: “e8af94f4d88d4e87”,
“type”: “victron-input-generator”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.generator/0”,
“path”: “/RunningByConditionCode”,
“serviceObj”: {
“service”: “com.victronenergy.generator/0”,
“name”: “Generator start/stop”
},
“pathObj”: {
“path”: “/RunningByConditionCode”,
“type”: “enum”,
“name”: “Condition that started the generator”,
“enum”: {
“0”: “Stopped”,
“1”: “Manual”,
“2”: “TestRun”,
“3”: “LossOfComms”,
“4”: “Soc”,
“5”: “AcLoad”,
“6”: “BatteryCurrent”,
“7”: “BatteryVoltage”,
“8”: “InverterTemperatur”,
“9”: “InverterOverload”,
“10”: “StopOnAc1”
}
},
“initial”: “”,
“name”: “”,
“onlyChanges”: false,
“x”: 730,
“y”: 80,
“wires”: [

]
},
{
“id”: “554638cc76949055”,
“type”: “victron-input-generator”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.generator/0”,
“path”: “/ServiceCounter”,
“serviceObj”: {
“service”: “com.victronenergy.generator/0”,
“name”: “Generator start/stop”
},
“pathObj”: {
“path”: “/ServiceCounter”,
“type”: “float”,
“name”: “Service countdown counter (seconds until next generator service)”
},
“name”: “”,
“onlyChanges”: false,
“x”: 820,
“y”: 140,
“wires”: [

]
},
{
“id”: “44c56fb6d04d9239”,
“type”: “debug”,
“z”: “59d6996fb5f99ddd”,
“name”: “debug 1”,
“active”: false,
“tosidebar”: true,
“console”: false,
“tostatus”: false,
“complete”: “false”,
“statusVal”: “”,
“statusType”: “auto”,
“x”: 480,
“y”: 400,
“wires”:
},
{
“id”: “2841bb27f4f936ab”,
“type”: “debug”,
“z”: “59d6996fb5f99ddd”,
“name”: “debug 2”,
“active”: false,
“tosidebar”: true,
“console”: false,
“tostatus”: false,
“complete”: “false”,
“statusVal”: “”,
“statusType”: “auto”,
“x”: 680,
“y”: 400,
“wires”:
},
{
“id”: “46b6fec7172b2624”,
“type”: “inject”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“props”: [
{
“p”: “payload”
},
{
“p”: “topic”,
“vt”: “str”
}
],
“repeat”: “5”,
“crontab”: “”,
“once”: true,
“onceDelay”: 0.1,
“topic”: “2”,
“payload”: “2”,
“payloadType”: “num”,
“x”: 310,
“y”: 400,
“wires”: [
[
“86152e89cd67d896”
]
]
},
{
“id”: “86152e89cd67d896”,
“type”: “smart_compare”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“comparator”: “GREATER_EQUAL”,
“value1”: “2”,
“value1_type”: “num”,
“value2”: “2”,
“value2_type”: “num”,
“out_false”: “{"topic": "1"}”,
“out_false_type”: “json”,
“out_true”: “{"topic": "1"}”,
“out_true_type”: “json”,
“send_only_change”: “false”,
“outputs”: 1,
“save_state”: true,
“resend_on_start”: true,
“x”: 610,
“y”: 320,
“wires”: [
[
“0455a7ea1ae5b3db”
]
]
},
{
“id”: “7aa9870284468666”,
“type”: “debug”,
“z”: “59d6996fb5f99ddd”,
“name”: “debug 3”,
“active”: true,
“tosidebar”: true,
“console”: false,
“tostatus”: false,
“complete”: “false”,
“statusVal”: “”,
“statusType”: “auto”,
“x”: 1240,
“y”: 320,
“wires”:
},
{
“id”: “27e41d3e61ba4e6e”,
“type”: “victron-input-generator”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.generator/0”,
“path”: “/ManualStart”,
“serviceObj”: {
“service”: “com.victronenergy.generator/0”,
“name”: “Generator start/stop”
},
“pathObj”: {
“path”: “/ManualStart”,
“type”: “enum”,
“name”: “Manual Start”,
“enum”: {
“0”: “Stop generator”,
“1”: “Start generator”
}
},
“initial”: “”,
“name”: “”,
“onlyChanges”: false,
“x”: 160,
“y”: 300,
“wires”: [
[
“327c5ef211c82cd0”
]
]
},
{
“id”: “327c5ef211c82cd0”,
“type”: “function”,
“z”: “59d6996fb5f99ddd”,
“name”: “t”,
“func”: “msg.topic = 2;\nreturn msg;”,
“outputs”: 1,
“timeout”: 0,
“noerr”: 0,
“initialize”: “”,
“finalize”: “”,
“libs”: ,
“x”: 390,
“y”: 280,
“wires”: [
[
“0455a7ea1ae5b3db”
]
]
},
{
“id”: “37011cc2755cc8a1”,
“type”: “victron-input-vebus”,
“z”: “59d6996fb5f99ddd”,
“service”: “com.victronenergy.vebus/289”,
“path”: “/Ac/ActiveIn/ActiveInput”,
“serviceObj”: {
“service”: “com.victronenergy.vebus/289”,
“name”: “Quattro 48/5000/70-2x100 120V”
},
“pathObj”: {
“path”: “/Ac/ActiveIn/ActiveInput”,
“type”: “enum”,
“name”: “Active input”,
“enum”: {
“0”: “AC Input 1”,
“1”: “AC Input 2”,
“240”: “Disconnected”
}
},
“initial”: “”,
“name”: “”,
“onlyChanges”: false,
“x”: 190,
“y”: 480,
“wires”: [
[
“37db6e1f5295287d”
]
]
},
{
“id”: “d11d57dee40846da”,
“type”: “inject”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“props”: [
{
“p”: “payload”
},
{
“p”: “topic”,
“vt”: “str”
}
],
“repeat”: “5”,
“crontab”: “”,
“once”: true,
“onceDelay”: 0.1,
“topic”: “2”,
“payload”: “1”,
“payloadType”: “num”,
“x”: 350,
“y”: 560,
“wires”: [
[
“77e917ccb39928f7”
]
]
},
{
“id”: “37db6e1f5295287d”,
“type”: “function”,
“z”: “59d6996fb5f99ddd”,
“name”: “RCM”,
“func”: “msg.topic = 1;\nreturn msg;”,
“outputs”: 1,
“timeout”: 0,
“noerr”: 0,
“initialize”: “”,
“finalize”: “”,
“libs”: ,
“x”: 470,
“y”: 480,
“wires”: [
[
“77e917ccb39928f7”
]
]
},
{
“id”: “77e917ccb39928f7”,
“type”: “smart_compare”,
“z”: “59d6996fb5f99ddd”,
“name”: “”,
“comparator”: “EQUAL”,
“value1”: “2”,
“value1_type”: “num”,
“value2”: “2”,
“value2_type”: “num”,
“out_false”: “{"topic": "3"}”,
“out_false_type”: “json”,
“out_true”: “{"topic": "3"}”,
“out_true_type”: “json”,
“send_only_change”: “false”,
“outputs”: 1,
“save_state”: true,
“resend_on_start”: true,
“x”: 620,
“y”: 480,
“wires”: [
[
“0455a7ea1ae5b3db”
]
]
}
]

It basically has a hard set limit of 5000w for the 6000w generator, calculates when the correct moment to start the batteries to have them charged at 9pm, then shuts off the genset if the batteries go into absorption mode.

Still testing… but it all makes me think there would be an easier way. Plus, if anyone is listening that can make these changes, the inverter had better control than the venusos, it would start on voltage and stop on absorption. Moreover, a “charge the batteries with the generator” button manual mode would be awesome.