Closed pittbull closed 2 years ago
The functionality you need for this is already in place, in version 3.3.0.
Below is an example flow that gives you this to a debug node.
Send this payload to the strategy node:
{"commands":{"sendSchedule":true}}
Then the node will send its current schedule to output 3. If you connect that output to a function node with the following code:
const schedule = msg.payload.schedule
const next = schedule.filter(s => Date.parse(s.time) > Date.now())
return {payload: {next: next[0] || []}};
Then you will get the next scheduled event on the output.
How to use this in HA, you must ask someone else :-)
But if you reply it back here, maybe I can provide an example of the whole thing in the docs.
Example flow:
[
{
"id": "eb951b71bd6f752e",
"type": "ps-strategy-lowest-price",
"z": "13662a5a6c84b388",
"name": "Lowest Price",
"fromTime": "16",
"toTime": "00",
"hoursOn": "3",
"doNotSplit": false,
"sendCurrentValueWhenRescheduling": true,
"outputIfNoSchedule": "false",
"outputOutsidePeriod": "false",
"x": 330,
"y": 480,
"wires": [
[],
[],
[
"43d53d58a68ed92c"
]
]
},
{
"id": "4e47cfd447d053d6",
"type": "debug",
"z": "13662a5a6c84b388",
"name": "Schedule",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 660,
"y": 480,
"wires": []
},
{
"id": "ce748c7dd98d6156",
"type": "inject",
"z": "13662a5a6c84b388",
"name": "Output schedule",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"commands\":{\"sendSchedule\":true}}",
"payloadType": "json",
"x": 140,
"y": 480,
"wires": [
[
"eb951b71bd6f752e"
]
]
},
{
"id": "43d53d58a68ed92c",
"type": "function",
"z": "13662a5a6c84b388",
"name": "",
"func": "const schedule = msg.payload.schedule\nconst next = schedule.filter(s => Date.parse(s.time) > Date.now())\nreturn {payload: {next: next[0] || []}};",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 500,
"y": 480,
"wires": [
[
"4e47cfd447d053d6"
]
]
}
]
Thank you kindly for your input.
I was able to extract the time and display it in HA.
I've been using these nodes for a little while, and what I've come to do is to open Node-red to check when the next either saver or normal period will start. As I am still learning the ropes on coding within the function node I wonder if it possible to expose in the payload the time and action for the next event?
I believe you already send this data to node but I don't know how to pick it up and reuse in a Lovelace.