I’m still all new to NodeRed, started a week ago. This is a Work-in-Progress code, I already made some modifications for clarity.
Here is the current version of my NodeRed code, not sure if this is the format you are looking for, please let me know!
Also, you will notice I did not connect the “Disable/Enable”, which was originally disabling the Daily “Calibration” reset until 4AM, I decided to reset those every time I trigger 100%.
[
{
"id": "3efd09077d0129be",
"type": "tab",
"label": "SoC from Coulombmeter",
"disabled": false,
"info": "",
"env": []
},
{
"id": "0123ea899e205216",
"type": "trigger-state",
"z": "3efd09077d0129be",
"name": "PowMr 100% Batt",
"server": "17ce6379.07b5bd",
"version": 4,
"inputs": 1,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityId": "sensor.powmr_battery_soc",
"entityIdType": "exact",
"debugEnabled": false,
"constraints": [
{
"targetType": "this_entity",
"targetValue": "",
"propertyType": "current_state",
"propertyValue": "new_state.state",
"comparatorType": "is",
"comparatorValueDatatype": "num",
"comparatorValue": "100"
}
],
"customOutputs": [],
"outputInitially": false,
"stateType": "num",
"enableInput": true,
"x": 210,
"y": 300,
"wires": [
[
"f6f644a7beb05859",
"1c5612c3ec556e93",
"a072f1bb911879a4",
"d0e6d2bf7af1244e",
"3140e88f1f06f953",
"df5e43e91aa5c831"
],
[]
]
},
{
"id": "a072f1bb911879a4",
"type": "api-current-state",
"z": "3efd09077d0129be",
"name": "ResetSetCharge",
"server": "17ce6379.07b5bd",
"version": 3,
"outputs": 2,
"halt_if": "null",
"halt_if_type": "str",
"halt_if_compare": "is_not",
"entity_id": "sensor.powmr_battery_charging_energy",
"state_type": "num",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "setcharge",
"propertyType": "flow",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 520,
"y": 260,
"wires": [
[],
[]
]
},
{
"id": "e04ab094d7058f35",
"type": "inject",
"z": "3efd09077d0129be",
"name": "ManualReset 100%",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 150,
"y": 360,
"wires": [
[
"a072f1bb911879a4",
"d0e6d2bf7af1244e",
"3140e88f1f06f953",
"df5e43e91aa5c831"
]
]
},
{
"id": "d0e6d2bf7af1244e",
"type": "api-current-state",
"z": "3efd09077d0129be",
"name": "ResetSetDischarge",
"server": "17ce6379.07b5bd",
"version": 3,
"outputs": 2,
"halt_if": "null",
"halt_if_type": "str",
"halt_if_compare": "is_not",
"entity_id": "sensor.powmr_battery_discharge_energy",
"state_type": "num",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "setdischarge",
"propertyType": "flow",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 530,
"y": 320,
"wires": [
[],
[]
]
},
{
"id": "e8c8a526d160bc7f",
"type": "function",
"z": "3efd09077d0129be",
"name": "Math (TallyToday)",
"func": "var tday = (Number(flow.get(\"adjdischarge\"))) - (Number(flow.get(\"adjcharge\")));\nmsg.payload = tday;\nflow.set(\"tday\", tday);\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 650,
"y": 660,
"wires": [
[
"63797bfb2df3633a"
]
]
},
{
"id": "23556dba05eadb49",
"type": "inject",
"z": "3efd09077d0129be",
"name": "ManualPoll",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 240,
"y": 540,
"wires": [
[
"6fe9ad59b724bfdf"
]
]
},
{
"id": "63797bfb2df3633a",
"type": "function",
"z": "3efd09077d0129be",
"name": "Math (SoC)",
"func": "var cap = (Number(flow.get(\"cap\")));\nvar tday = (Number(flow.get(\"tday\")));\n\nvar soc = (cap - tday) / cap * 100;\n\nif (soc > 100) {\n soc = 100;\n} \n\nsoc = Math.round(soc * 100) / 100;\n\nflow.set(\"soc\", soc);\nmsg.payload = soc;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 720,
"wires": [
[
"1e0679d6d4451ff1"
]
]
},
{
"id": "1c5612c3ec556e93",
"type": "api-current-state",
"z": "3efd09077d0129be",
"name": "Set Capacity & Ineff. Factors",
"server": "17ce6379.07b5bd",
"version": 3,
"outputs": 2,
"halt_if": "null",
"halt_if_type": "str",
"halt_if_compare": "is_not",
"entity_id": "sensor.battery_capacity_kwh",
"state_type": "num",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "cap",
"propertyType": "flow",
"value": "",
"valueType": "entityState"
},
{
"property": "cineff",
"propertyType": "flow",
"value": "0.65",
"valueType": "num"
},
{
"property": "dineff",
"propertyType": "flow",
"value": "1.15",
"valueType": "num"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 560,
"y": 200,
"wires": [
[],
[]
]
},
{
"id": "f6f644a7beb05859",
"type": "change",
"z": "3efd09077d0129be",
"name": "Disable",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "disable",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 300,
"y": 140,
"wires": [
[
"fae461869872bdf9"
]
]
},
{
"id": "40b41615af9839d2",
"type": "change",
"z": "3efd09077d0129be",
"name": "Enable",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "enable",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 300,
"y": 100,
"wires": [
[
"fae461869872bdf9"
]
]
},
{
"id": "39ce607439285035",
"type": "inject",
"z": "3efd09077d0129be",
"name": "04:00",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "00 04 * * *",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 100,
"wires": [
[
"40b41615af9839d2"
]
]
},
{
"id": "fae461869872bdf9",
"type": "link out",
"z": "3efd09077d0129be",
"name": "SoC",
"mode": "link",
"links": [
"e6fe843f32415dc6"
],
"x": 455,
"y": 120,
"wires": []
},
{
"id": "e6fe843f32415dc6",
"type": "link in",
"z": "3efd09077d0129be",
"name": "SoC",
"links": [
"fae461869872bdf9"
],
"x": 75,
"y": 300,
"wires": [
[]
]
},
{
"id": "5688a4bd163e2138",
"type": "server-state-changed",
"z": "3efd09077d0129be",
"name": "PollCharge AutoUpdate",
"server": "17ce6379.07b5bd",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityId": "sensor.powmr_battery_charging_energy",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "num",
"ifState": "null",
"ifStateType": "str",
"ifStateOperator": "is_not",
"outputOnlyOnStateChange": true,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "pollcharge",
"propertyType": "flow",
"value": "",
"valueType": "entityState"
}
],
"x": 200,
"y": 600,
"wires": [
[
"6fe9ad59b724bfdf"
],
[]
]
},
{
"id": "c0d957fccdc048be",
"type": "server-state-changed",
"z": "3efd09077d0129be",
"name": "PollDischarge AutoUpdate",
"server": "17ce6379.07b5bd",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityId": "sensor.powmr_battery_discharge_energy",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "num",
"ifState": "null",
"ifStateType": "str",
"ifStateOperator": "is_not",
"outputOnlyOnStateChange": true,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "polldischarge",
"propertyType": "flow",
"value": "",
"valueType": "entityState"
}
],
"x": 210,
"y": 660,
"wires": [
[
"6fe9ad59b724bfdf"
],
[]
]
},
{
"id": "1e0679d6d4451ff1",
"type": "mqtt out",
"z": "3efd09077d0129be",
"name": "NR Battery SoC",
"topic": "NodeRed/nr_batt_soc",
"qos": "",
"retain": "true",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "ed661f0c78cde115",
"x": 960,
"y": 660,
"wires": []
},
{
"id": "7c1e0357217856e5",
"type": "mqtt out",
"z": "3efd09077d0129be",
"name": "Initial Setup (RunOnce)",
"topic": "homeassistant/sensor/nr_batt_soc/config",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "ed661f0c78cde115",
"x": 550,
"y": 40,
"wires": []
},
{
"id": "c1899e557f21381a",
"type": "inject",
"z": "3efd09077d0129be",
"name": "InitMQTT Sensor (RunONCE)",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"name\": \"Battery SoC\", \"object_id\": \"nr_batt_soc\", \"device_class\": \"battery\", \"unit_of_measurement\": \"%\", \"unique_id\": \"nr_batt_soc\", \"platform\": \"mqtt\", \"expire_after\": 3600, \"state_topic\": \"NodeRed/nr_batt_soc\", \"device\": {\"name\": \"Node Red\", \"identifiers\": \"NR_SOC_FLOW\"}}",
"payloadType": "str",
"x": 200,
"y": 40,
"wires": [
[
"7c1e0357217856e5"
]
]
},
{
"id": "3140e88f1f06f953",
"type": "api-current-state",
"z": "3efd09077d0129be",
"name": "ResetPollDischarge",
"server": "17ce6379.07b5bd",
"version": 3,
"outputs": 2,
"halt_if": "null",
"halt_if_type": "str",
"halt_if_compare": "is_not",
"entity_id": "sensor.powmr_battery_discharge_energy",
"state_type": "num",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "polldischarge",
"propertyType": "flow",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 530,
"y": 440,
"wires": [
[],
[]
]
},
{
"id": "df5e43e91aa5c831",
"type": "api-current-state",
"z": "3efd09077d0129be",
"name": "ResetPollCharge",
"server": "17ce6379.07b5bd",
"version": 3,
"outputs": 2,
"halt_if": "null",
"halt_if_type": "str",
"halt_if_compare": "is_not",
"entity_id": "sensor.powmr_battery_charging_energy",
"state_type": "num",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "pollcharge",
"propertyType": "flow",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 530,
"y": 380,
"wires": [
[],
[]
]
},
{
"id": "6fe9ad59b724bfdf",
"type": "function",
"z": "3efd09077d0129be",
"name": "Math - Deltas",
"func": "var deltacharge = (Number(flow.get(\"pollcharge\"))) - (Number(flow.get(\"setcharge\")));\nvar deltadischarge = (Number(flow.get(\"polldischarge\"))) - (Number(flow.get(\"setdischarge\")));\n\nflow.set(\"deltacharge\", deltacharge);\nflow.set(\"deltadischarge\", deltadischarge);\n\nmsg.payload = \"NextStep\";\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 540,
"wires": [
[
"1ee36c792884a552"
]
]
},
{
"id": "1ee36c792884a552",
"type": "function",
"z": "3efd09077d0129be",
"name": "Math (Ineff. Factor)",
"func": "var adjcharge = (Number(flow.get(\"deltacharge\"))) * (Number(flow.get(\"cineff\")));\nvar adjdischarge = (Number(flow.get(\"deltadischarge\"))) * (Number(flow.get(\"dineff\")));\n\nflow.set(\"adjcharge\", adjcharge);\nflow.set(\"adjdischarge\", adjdischarge);\n\nmsg.payload = \"NextStep\";\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 570,
"y": 600,
"wires": [
[
"e8c8a526d160bc7f"
]
]
},
{
"id": "87e7d9844bf2166c",
"type": "inject",
"z": "3efd09077d0129be",
"name": "ManualReset Cap&Ineff",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 160,
"y": 240,
"wires": [
[
"1c5612c3ec556e93"
]
]
},
{
"id": "17ce6379.07b5bd",
"type": "server",
"name": "Home Assistant",
"addon": true
},
{
"id": "ed661f0c78cde115",
"type": "mqtt-broker",
"name": "YourUserName",
"broker": "localhost",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]