Skip to content

Instantly share code, notes, and snippets.

@billerby
Created December 29, 2023 13:52
Show Gist options
  • Save billerby/d3d37d1198a1dc47cc6fc01ac192646a to your computer and use it in GitHub Desktop.
Save billerby/d3d37d1198a1dc47cc6fc01ac192646a to your computer and use it in GitHub Desktop.
mitt nodered-flöde
[
{
"id":"9dd9989baa8ff515",
"type":"tab",
"label":"Johans flow",
"disabled":false,
"info":"",
"env":[
]
},
{
"id":"4c850c4d2bc6431a",
"type":"api-call-service",
"z":"9dd9989baa8ff515",
"name":"Set ToU period",
"server":"27fecb90.ed0154",
"version":5,
"debugenabled":false,
"domain":"huawei_solar",
"service":"set_tou_periods",
"areaId":[
],
"deviceId":[
],
"entityId":[
],
"data":"{\t \"device_id\": \"9b80e4bb5e879c09ed84abe968ce937b\",\t \"periods\": payload \t}",
"dataType":"jsonata",
"mergeContext":"",
"mustacheAltTags":false,
"outputProperties":[
],
"queue":"none",
"x":1840,
"y":280,
"wires":[
[
"0bcd50ce9e0be50c",
"03719ed4e3c19cd1"
]
]
},
{
"id":"0bcd50ce9e0be50c",
"type":"debug",
"z":"9dd9989baa8ff515",
"name":"debug 5",
"active":true,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"false",
"statusVal":"",
"statusType":"auto",
"x":1840,
"y":460,
"wires":[
]
},
{
"id":"78a2c6fdc37822a6",
"type":"debug",
"z":"9dd9989baa8ff515",
"name":"debug 3",
"active":true,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"true",
"targetType":"full",
"statusVal":"",
"statusType":"auto",
"x":1860,
"y":560,
"wires":[
]
},
{
"id":"3a40fbefc10bf234",
"type":"ha-sensor",
"z":"9dd9989baa8ff515",
"name":"Optimized battery strategy",
"entityConfig":"0892be243503290e",
"version":0,
"state":"payload",
"stateType":"str",
"attributes":[
{
"property":"Schedule",
"value":"payload.schedule",
"valueType":"msg"
},
{
"property":"Price",
"value":"payload.priceData",
"valueType":"msg"
}
],
"inputOverride":"allow",
"outputProperties":[
],
"x":1650,
"y":560,
"wires":[
[
"78a2c6fdc37822a6"
]
]
},
{
"id":"dd8ad40fc5c9b51a",
"type":"function",
"z":"9dd9989baa8ff515",
"name":"Convert schedule to ToU pattern",
"func":"// Get day of the week (7 = Sunday, 1 = Monday, etc.)\nfunction getDayAsNumber(day) {\n return day === 0 ? 7 : day;\n}\n\nconst values = msg.payload.schedule\n .filter((e) => e.activity != 0)\n .reduce((total, e) => {\n const toTimeString = (date) => {\n const HH = date.getHours().toString().padStart(2, '0')\n const mm = date.getMinutes().toString().padStart(2, '0')\n return `${HH}:${mm}`\n }\n\n const touPattern = (start, end, charge) => {\n let pattern = toTimeString(start)\n pattern += '-'\n pattern += toTimeString(end)\n pattern += '/'\n pattern += getDayAsNumber(start.getDay());\n pattern += '/'\n pattern += charge\n return pattern\n }\n\n const startDate = new Date(e.start)\n const endDate = new Date(startDate.getTime() + (e.duration - 1) * 60000)\n const charge = e.activity == 1 ? '+' : '-'\n if (startDate.getDay() == endDate.getDay()) {\n total.push(touPattern(startDate, endDate, charge))\n } else {\n const endDateDay1 = new Date(startDate)\n endDateDay1.setHours(23)\n endDateDay1.setMinutes(59)\n total.push(touPattern(startDate, endDateDay1, charge))\n\n const startDateDay2 = new Date(endDate)\n startDateDay2.setHours(0)\n startDateDay2.setMinutes(0)\n total.push(touPattern(startDateDay2, endDate, charge))\n }\n return total\n }, [])\n\nmsg.payload = values.join('\\n')\nreturn msg;",
"outputs":1,
"noerr":0,
"initialize":"",
"finalize":"",
"libs":[
],
"x":1550,
"y":340,
"wires":[
[
"4c850c4d2bc6431a",
"d5aebfe8a18ab382"
]
]
},
{
"id":"9670fe306d6281da",
"type":"enell-strategy-genetic-charging",
"z":"9dd9989baa8ff515",
"name":"",
"populationSize":"200",
"generations":400,
"mutationRate":3,
"numberOfPricePeriods":8,
"batteryMaxEnergy":"15",
"batteryMaxInputPower":"4",
"averageConsumption":"1.5",
"x":1270,
"y":460,
"wires":[
[
"3a40fbefc10bf234",
"dd8ad40fc5c9b51a",
"345632cb07f17764"
]
]
},
{
"id":"8699b0a0287e6e12",
"type":"join",
"z":"9dd9989baa8ff515",
"name":"",
"mode":"custom",
"build":"merged",
"property":"payload",
"propertyType":"msg",
"key":"topic",
"joiner":"\\n",
"joinerType":"str",
"accumulate":false,
"timeout":"",
"count":"2",
"reduceRight":false,
"reduceExp":"",
"reduceInit":"",
"reduceInitType":"",
"reduceFixup":"",
"x":1070,
"y":460,
"wires":[
[
"9670fe306d6281da"
]
]
},
{
"id":"01c407dad663d0b5",
"type":"ps-receive-price",
"z":"9dd9989baa8ff515",
"name":"Price Receiver",
"x":900,
"y":420,
"wires":[
[
"8699b0a0287e6e12"
]
]
},
{
"id":"48ccc852643299cb",
"type":"tibber-query",
"z":"9dd9989baa8ff515",
"name":"Get prices",
"active":true,
"apiEndpointRef":"0ea0a234c2e66896",
"x":730,
"y":420,
"wires":[
[
"01c407dad663d0b5"
]
]
},
{
"id":"de7fda1a4fa36e8f",
"type":"api-current-state",
"z":"9dd9989baa8ff515",
"name":"Luna SOC",
"server":"27fecb90.ed0154",
"version":3,
"outputs":1,
"halt_if":"",
"halt_if_type":"str",
"halt_if_compare":"is",
"entity_id":"sensor.battery_state_of_capacity",
"state_type":"num",
"blockInputOverrides":false,
"outputProperties":[
{
"property":"payload.soc",
"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":710,
"y":540,
"wires":[
[
"8699b0a0287e6e12",
"4d3eff03336b53a4"
]
]
},
{
"id":"49a684159dcfd597",
"type":"function",
"z":"9dd9989baa8ff515",
"name":"Set tibber payload",
"func":"msg.payload = `{\n viewer {\n home(id: \"c62ef42e-7d42-4a7b-a828-d03161d9d453\") {\n currentSubscription {\n priceInfo {\n today {\n total\n energy\n tax\n startsAt\n }\n tomorrow {\n total\n energy\n tax\n startsAt\n }\n }\n }\n }\n }\n}`\nreturn msg",
"outputs":1,
"noerr":0,
"initialize":"",
"finalize":"",
"libs":[
],
"x":550,
"y":420,
"wires":[
[
"48ccc852643299cb"
]
]
},
{
"id":"6e26d15b1d889440",
"type":"inject",
"z":"9dd9989baa8ff515",
"name":"Inject",
"props":[
],
"repeat":"14400",
"crontab":"",
"once":false,
"onceDelay":0.1,
"topic":"",
"x":90,
"y":440,
"wires":[
[
"f47bd2d9b8b46420"
]
]
},
{
"id":"04f340048e39939d",
"type":"function",
"z":"9dd9989baa8ff515",
"name":"Clear periods",
"func":"// Get day of the week (7 = Sunday, 1 = Monday, etc.)\nfunction getDayAsNumber(day) {\n return day === 0 ? 7 : day;\n}\n\n// It wont accept an empty schedule.\nlet dayNumber = getDayAsNumber(new Date().getDay());\nlet dayBefore = dayNumber -1 ;\n\nmsg.payload = \"00:01-00:02/\" + dayBefore +\"/-\";\nreturn msg;",
"outputs":1,
"noerr":0,
"initialize":"",
"finalize":"",
"libs":[
],
"x":1290,
"y":260,
"wires":[
[
"4c850c4d2bc6431a",
"8a57aabe71cc5985"
]
]
},
{
"id":"f47bd2d9b8b46420",
"type":"api-current-state",
"z":"9dd9989baa8ff515",
"name":"Laddar bilen?",
"server":"d47a09d6.cf4748",
"version":3,
"outputs":2,
"halt_if":"charging",
"halt_if_type":"str",
"halt_if_compare":"is",
"entity_id":"sensor.easee_home_91929_status",
"state_type":"str",
"blockInputOverrides":false,
"outputProperties":[
{
"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":260,
"y":480,
"wires":[
[
"04f340048e39939d"
],
[
"49a684159dcfd597",
"de7fda1a4fa36e8f"
]
]
},
{
"id":"7b66a7956c514459",
"type":"server-state-changed",
"z":"9dd9989baa8ff515",
"name":"Bilen börjar ladda",
"server":"d47a09d6.cf4748",
"version":4,
"outputs":2,
"for":"0",
"forType":"num",
"forUnits":"minutes",
"ignorePrevStateNull":false,
"ignorePrevStateUnknown":false,
"ignorePrevStateUnavailable":false,
"ignoreCurrentStateUnknown":false,
"ignoreCurrentStateUnavailable":false,
"outputProperties":[
{
"property":"data",
"propertyType":"msg",
"value":"",
"valueType":"eventData"
},
{
"property":"topic",
"propertyType":"msg",
"value":"",
"valueType":"triggerId"
},
{
"property":"payload",
"propertyType":"msg",
"value":"entity state",
"valueType":"str"
}
],
"exposeToHomeAssistant":false,
"haConfig":[
{
"property":"name",
"value":""
},
{
"property":"icon",
"value":""
}
],
"entityidfilter":"sensor.easee_home_91929_status",
"entityidfiltertype":"exact",
"outputinitially":false,
"state_type":"str",
"haltifstate":"charging",
"halt_if_type":"str",
"halt_if_compare":"is",
"output_only_on_state_change":true,
"x":100,
"y":200,
"wires":[
[
"0bc07b1186c55173"
],
[
]
]
},
{
"id":"345632cb07f17764",
"type":"debug",
"z":"9dd9989baa8ff515",
"name":"debug 23",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"false",
"statusVal":"",
"statusType":"auto",
"x":1560,
"y":420,
"wires":[
]
},
{
"id":"4d3eff03336b53a4",
"type":"debug",
"z":"9dd9989baa8ff515",
"name":"debug 25",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"false",
"statusVal":"",
"statusType":"auto",
"x":780,
"y":700,
"wires":[
]
},
{
"id":"d5aebfe8a18ab382",
"type":"debug",
"z":"9dd9989baa8ff515",
"name":"debug 26",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"false",
"statusVal":"",
"statusType":"auto",
"x":2040,
"y":380,
"wires":[
]
},
{
"id":"bbfc0321e718a11c",
"type":"server-state-changed",
"z":"9dd9989baa8ff515",
"name":"Bilen slutar ladda",
"server":"d47a09d6.cf4748",
"version":4,
"outputs":2,
"for":"0",
"forType":"num",
"forUnits":"minutes",
"ignorePrevStateNull":false,
"ignorePrevStateUnknown":false,
"ignorePrevStateUnavailable":false,
"ignoreCurrentStateUnknown":false,
"ignoreCurrentStateUnavailable":false,
"outputProperties":[
{
"property":"data",
"propertyType":"msg",
"value":"",
"valueType":"eventData"
},
{
"property":"topic",
"propertyType":"msg",
"value":"",
"valueType":"triggerId"
}
],
"exposeToHomeAssistant":false,
"haConfig":[
{
"property":"name",
"value":""
},
{
"property":"icon",
"value":""
}
],
"entityidfilter":"sensor.easee_home_91929_status",
"entityidfiltertype":"exact",
"outputinitially":false,
"state_type":"str",
"haltifstate":"charging",
"halt_if_type":"str",
"halt_if_compare":"is_not",
"output_only_on_state_change":true,
"x":100,
"y":300,
"wires":[
[
"de7fda1a4fa36e8f",
"f3d624cf951e82e0"
],
[
]
]
},
{
"id":"8a57aabe71cc5985",
"type":"debug",
"z":"9dd9989baa8ff515",
"name":"debug 27",
"active":false,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"false",
"statusVal":"",
"statusType":"auto",
"x":1720,
"y":80,
"wires":[
]
},
{
"id":"03719ed4e3c19cd1",
"type":"mqtt out",
"z":"9dd9989baa8ff515",
"name":"",
"topic":"update-battery",
"qos":"0",
"retain":"",
"respTopic":"",
"contentType":"",
"userProps":"",
"correl":"",
"expiry":"",
"broker":"9612f6ee7cb3bc53",
"x":2080,
"y":180,
"wires":[
]
},
{
"id":"0bc07b1186c55173",
"type":"api-call-service",
"z":"9dd9989baa8ff515",
"name":"Disable battery discharge",
"server":"24cba002.90109",
"version":5,
"debugenabled":false,
"domain":"number",
"service":"set_value",
"areaId":[
],
"deviceId":[
"9b80e4bb5e879c09ed84abe968ce937b"
],
"entityId":[
"number.maximum_discharging_power"
],
"data":"{\"value\":0}",
"dataType":"jsonata",
"mergeContext":"",
"mustacheAltTags":false,
"outputProperties":[
],
"queue":"none",
"x":530,
"y":120,
"wires":[
[
"5a95c1577192efaf"
]
]
},
{
"id":"5a95c1577192efaf",
"type":"api-call-service",
"z":"9dd9989baa8ff515",
"name":"Disable battery Charge",
"server":"24cba002.90109",
"version":5,
"debugenabled":false,
"domain":"number",
"service":"set_value",
"areaId":[
],
"deviceId":[
"9b80e4bb5e879c09ed84abe968ce937b"
],
"entityId":[
"number.maximum_charging_power"
],
"data":"{\"value\":0}",
"dataType":"jsonata",
"mergeContext":"",
"mustacheAltTags":false,
"outputProperties":[
],
"queue":"none",
"x":800,
"y":120,
"wires":[
[
"e2056433eb762613"
]
]
},
{
"id":"e2056433eb762613",
"type":"api-call-service",
"z":"9dd9989baa8ff515",
"name":"Charge grid off",
"server":"24cba002.90109",
"version":5,
"debugenabled":false,
"domain":"switch",
"service":"turn_off",
"areaId":[
],
"deviceId":[
"9b80e4bb5e879c09ed84abe968ce937b"
],
"entityId":[
"switch.charge_from_grid"
],
"data":"",
"dataType":"jsonata",
"mergeContext":"",
"mustacheAltTags":false,
"outputProperties":[
],
"queue":"none",
"x":1080,
"y":120,
"wires":[
[
"04f340048e39939d"
]
]
},
{
"id":"f3d624cf951e82e0",
"type":"api-call-service",
"z":"9dd9989baa8ff515",
"name":"Enable battery discharge",
"server":"24cba002.90109",
"version":5,
"debugenabled":false,
"domain":"number",
"service":"set_value",
"areaId":[
],
"deviceId":[
"9b80e4bb5e879c09ed84abe968ce937b"
],
"entityId":[
"number.maximum_discharging_power"
],
"data":"{\"value\":5000}",
"dataType":"jsonata",
"mergeContext":"",
"mustacheAltTags":false,
"outputProperties":[
],
"queue":"none",
"x":330,
"y":240,
"wires":[
[
"8b448982520f82a8"
]
]
},
{
"id":"8b448982520f82a8",
"type":"api-call-service",
"z":"9dd9989baa8ff515",
"name":"Enable battery Charge",
"server":"24cba002.90109",
"version":5,
"debugenabled":false,
"domain":"number",
"service":"set_value",
"areaId":[
],
"deviceId":[
"9b80e4bb5e879c09ed84abe968ce937b"
],
"entityId":[
"number.maximum_charging_power"
],
"data":"{\"value\":5000}",
"dataType":"jsonata",
"mergeContext":"",
"mustacheAltTags":false,
"outputProperties":[
],
"queue":"none",
"x":620,
"y":220,
"wires":[
[
"bb7d7ea5408eeb92"
]
]
},
{
"id":"bb7d7ea5408eeb92",
"type":"api-call-service",
"z":"9dd9989baa8ff515",
"name":"Charge grid on",
"server":"24cba002.90109",
"version":5,
"debugenabled":false,
"domain":"switch",
"service":"turn_on",
"areaId":[
],
"deviceId":[
"9b80e4bb5e879c09ed84abe968ce937b"
],
"entityId":[
"switch.charge_from_grid"
],
"data":"",
"dataType":"jsonata",
"mergeContext":"",
"mustacheAltTags":false,
"outputProperties":[
],
"queue":"none",
"x":620,
"y":280,
"wires":[
[
"49a684159dcfd597"
]
]
},
{
"id":"27fecb90.ed0154",
"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":"friendlyName",
"deviceSelector":"friendlyName",
"entitySelector":"friendlyName",
"statusSeparator":"at: ",
"statusYear":"hidden",
"statusMonth":"short",
"statusDay":"numeric",
"statusHourCycle":"h23",
"statusTimeFormat":"h:m",
"enableGlobalContextStore":true
},
{
"id":"0892be243503290e",
"type":"ha-entity-config",
"server":"27fecb90.ed0154",
"deviceConfig":"9f15a33db81a5490",
"name":"optimized_battery_schedule",
"version":"6",
"entityType":"sensor",
"haConfig":[
{
"property":"name",
"value":"Optimized Battery Schedule"
},
{
"property":"icon",
"value":""
},
{
"property":"entity_category",
"value":""
},
{
"property":"device_class",
"value":""
},
{
"property":"unit_of_measurement",
"value":""
},
{
"property":"state_class",
"value":""
}
],
"resend":false,
"debugEnabled":false
},
{
"id":"0ea0a234c2e66896",
"type":"tibber-api-endpoint",
"queryUrl":"https://api.tibber.com/v1-beta/gql",
"feedTimeout":"60",
"name":""
},
{
"id":"d47a09d6.cf4748",
"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":"friendlyName",
"deviceSelector":"friendlyName",
"entitySelector":"friendlyName",
"statusSeparator":"at: ",
"statusYear":"hidden",
"statusMonth":"short",
"statusDay":"numeric",
"statusHourCycle":"h23",
"statusTimeFormat":"h:m",
"enableGlobalContextStore":true
},
{
"id":"9612f6ee7cb3bc53",
"type":"mqtt-broker",
"name":"",
"broker":"localhost",
"port":"1883",
"clientid":"",
"autoConnect":true,
"usetls":false,
"protocolVersion":"4",
"keepalive":"60",
"cleansession":true,
"birthTopic":"",
"birthQos":"0",
"birthPayload":"",
"birthMsg":{
},
"closeTopic":"",
"closeQos":"0",
"closePayload":"",
"closeMsg":{
},
"willTopic":"",
"willQos":"0",
"willPayload":"",
"willMsg":{
},
"userProps":"",
"sessionExpiry":""
},
{
"id":"24cba002.90109",
"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":"friendlyName",
"deviceSelector":"friendlyName",
"entitySelector":"friendlyName",
"statusSeparator":"at: ",
"statusYear":"hidden",
"statusMonth":"short",
"statusDay":"numeric",
"statusHourCycle":"h23",
"statusTimeFormat":"h:m",
"enableGlobalContextStore":true
},
{
"id":"9f15a33db81a5490",
"type":"ha-device-config",
"name":"Powersaver",
"hwVersion":"",
"manufacturer":"Node-RED",
"model":"",
"swVersion":""
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment