Need to build a logic but kinda stuck

Trying to build a flow sending temperature settings based on lot of different inputs. I of course get stuck on the first one. The first logic I need to build is like this: If "pris" is less than "snittpris" and forbruk is less than 5000 and time is between 01.30 - 06.00, then set temp 86. The inputs comes through the linked out nodes and only give the values thats why I have tried to add topics. I have tried to solve the first part of it first and then add the time trough a within-time node later. The values do not come at the same time, "pris" arrives every minute, "forbruk" arrives every 1.5 sec, and "snittpris" arrives only once a day.

[
    {
        "id": "446b4632c7eaca9b",
        "type": "link in",
        "z": "683fd7.e63da028",
        "name": "link in 1",
        "links": [
            "ea301395736731bf"
        ],
        "x": 75,
        "y": 3120,
        "wires": [
            [
                "d6947f05384f3ee4"
            ]
        ]
    },
    {
        "id": "8c5b8ae1edbcdb33",
        "type": "link in",
        "z": "683fd7.e63da028",
        "name": "link in 2",
        "links": [
            "f1f999daca97edb5"
        ],
        "x": 75,
        "y": 3200,
        "wires": [
            [
                "02cede781de14387",
                "b229cb2c8862d5d6"
            ]
        ]
    },
    {
        "id": "d1f4cbfa5632c61d",
        "type": "link in",
        "z": "683fd7.e63da028",
        "name": "link in 3",
        "links": [
            "b8f1ab2a6b155daa"
        ],
        "x": 45,
        "y": 3280,
        "wires": [
            [
                "54e0c97b726967eb",
                "cffe14a268ada410"
            ]
        ]
    },
    {
        "id": "684abf2d96f6b199",
        "type": "debug",
        "z": "683fd7.e63da028",
        "name": "Melding går hit i tidspunktet",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1100,
        "y": 3060,
        "wires": []
    },
    {
        "id": "af3075e66ada41e3",
        "type": "debug",
        "z": "683fd7.e63da028",
        "name": "Melding går hit utenfor tidspunktet",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1100,
        "y": 3220,
        "wires": []
    },
    {
        "id": "074d0bb7fa796381",
        "type": "within-time-switch",
        "z": "683fd7.e63da028",
        "name": "Styring natt",
        "nameInt": "",
        "positionConfig": "21d53856841feeed",
        "startTime": "10:29",
        "startTimeType": "entered",
        "startOffset": 0,
        "startOffsetType": "none",
        "startOffsetMultiplier": 60000,
        "endTime": "06:00",
        "endTimeType": "entered",
        "endOffset": 0,
        "endOffsetType": "none",
        "endOffsetMultiplier": 60000,
        "timeRestrictions": 0,
        "timeRestrictionsType": "none",
        "timeDays": "*",
        "timeOnlyOddDays": false,
        "timeOnlyEvenDays": false,
        "timeOnlyOddWeeks": false,
        "timeOnlyEvenWeeks": false,
        "timeMonths": "*",
        "timedatestart": "",
        "timedateend": "",
        "propertyStart": "",
        "propertyStartType": "none",
        "propertyStartCompare": "true",
        "propertyStartThreshold": "",
        "propertyStartThresholdType": "num",
        "startTimeAlt": "",
        "startTimeAltType": "entered",
        "startOffsetAlt": 0,
        "startOffsetAltType": "none",
        "startOffsetAltMultiplier": 60000,
        "propertyEnd": "",
        "propertyEndType": "none",
        "propertyEndCompare": "true",
        "propertyEndThreshold": "",
        "propertyEndThresholdType": "num",
        "endTimeAlt": "",
        "endTimeAltType": "entered",
        "endOffsetAlt": 0,
        "endOffsetAltType": "none",
        "endOffsetAltMultiplier": 60000,
        "withinTimeValue": "true",
        "withinTimeValueType": "msgInput",
        "outOfTimeValue": "false",
        "outOfTimeValueType": "msgInput",
        "tsCompare": "0",
        "x": 1110,
        "y": 3380,
        "wires": [
            [
                "684abf2d96f6b199"
            ],
            [
                "af3075e66ada41e3"
            ]
        ]
    },
    {
        "id": "d2857a3635747777",
        "type": "function",
        "z": "683fd7.e63da028",
        "name": "function 1",
        "func": "if (msg.topic === 'Pris' && msg.topic === 'Forbruk' && msg.payload < 5000) {\n    return msg; // Output the message as is\n} else {\n    return null; // Do not output anything\n}\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 580,
        "y": 3160,
        "wires": [
            [
                "48826394d01e8c20"
            ]
        ]
    },
    {
        "id": "48826394d01e8c20",
        "type": "debug",
        "z": "683fd7.e63da028",
        "name": "Test varme natt",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 3120,
        "wires": []
    },
    {
        "id": "cffe14a268ada410",
        "type": "change",
        "z": "683fd7.e63da028",
        "name": "snittpris_minne",
        "rules": [
            {
                "t": "set",
                "p": "snittpris",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 160,
        "y": 3340,
        "wires": [
            [
                "bdf8a57cb4717d7f"
            ]
        ]
    },
    {
        "id": "65abc4234fa4029a",
        "type": "change",
        "z": "683fd7.e63da028",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "snittpris",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 3340,
        "wires": [
            [
                "9bed3a81297afbbb"
            ]
        ]
    },
    {
        "id": "02cede781de14387",
        "type": "debug",
        "z": "683fd7.e63da028",
        "name": "Forbruk inneværende time i W",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 250,
        "y": 3180,
        "wires": []
    },
    {
        "id": "54e0c97b726967eb",
        "type": "debug",
        "z": "683fd7.e63da028",
        "name": "Snittpris med nettleie",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 240,
        "y": 3260,
        "wires": []
    },
    {
        "id": "d6947f05384f3ee4",
        "type": "change",
        "z": "683fd7.e63da028",
        "name": "Topic: Pris",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Pris",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 250,
        "y": 3120,
        "wires": [
            [
                "d2857a3635747777"
            ]
        ]
    },
    {
        "id": "b229cb2c8862d5d6",
        "type": "change",
        "z": "683fd7.e63da028",
        "name": "Topic: Forbruk",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Forbruk",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 260,
        "y": 3220,
        "wires": [
            [
                "d2857a3635747777"
            ]
        ]
    },
    {
        "id": "bdf8a57cb4717d7f",
        "type": "delay",
        "z": "683fd7.e63da028",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 340,
        "y": 3340,
        "wires": [
            [
                "65abc4234fa4029a"
            ]
        ]
    },
    {
        "id": "9bed3a81297afbbb",
        "type": "change",
        "z": "683fd7.e63da028",
        "name": "Topic: Pris",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Pris",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 650,
        "y": 3260,
        "wires": [
            [
                "d2857a3635747777"
            ]
        ]
    },
    {
        "id": "21d53856841feeed",
        "type": "position-config",
        "name": "",
        "isValide": "true",
        "angleType": "deg",
        "timeZoneOffset": "99",
        "timeZoneDST": "0",
        "stateTimeFormat": "3",
        "stateDateFormat": "12",
        "contextStore": ""
    }
]

You need to save the incoming data to be able to compare them.
Either create flow context variables flow.pris, flow.forbruk and flow.snittpris or (better) use a join node to combine all three values into a single message.

Assuming that you join them all into the same message, your logic becomes something like

IF msg.payload.forbruk < 5000
   THEN IF msg.payload.pris < msg.payload.snittpris
      THEN msg.temperature = 86

You can achieve this with two switch nodes

Regarding the time window, perhaps a node-red-contrib-simple-gate node which you can open and close with two injects at 01:30 and 06:00

Maybe this will help

[{"id":"790cdb535e4c1a4d","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":90,"y":3500,"wires":[["d6947f05384f3ee4"]]},{"id":"d6947f05384f3ee4","type":"change","z":"b9860b4b9de8c8da","name":"Topic: Pris","rules":[{"t":"set","p":"topic","pt":"msg","to":"Pris","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":3520,"wires":[["8659b9eb8fb0fb4b"]]},{"id":"6924e505acd0bc0a","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":90,"y":3540,"wires":[["d6947f05384f3ee4"]]},{"id":"8659b9eb8fb0fb4b","type":"join","z":"b9860b4b9de8c8da","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":390,"y":3620,"wires":[["b5e11709765874b9"]]},{"id":"b229cb2c8862d5d6","type":"change","z":"b9860b4b9de8c8da","name":"Topic: Forbruk","rules":[{"t":"set","p":"topic","pt":"msg","to":"Forbruk","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":3620,"wires":[["8659b9eb8fb0fb4b"]]},{"id":"cffe14a268ada410","type":"change","z":"b9860b4b9de8c8da","name":"topic snittpris","rules":[{"t":"set","p":"topic","pt":"msg","to":"snittpris","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":3700,"wires":[["8659b9eb8fb0fb4b"]]},{"id":"b5e11709765874b9","type":"switch","z":"b9860b4b9de8c8da","name":"","property":"payload.Forbruk","propertyType":"msg","rules":[{"t":"lt","v":"5000","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":3620,"wires":[["381dc879f60b6fa6"]]},{"id":"95a05a9d1bb9753d","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4000","payloadType":"num","x":90,"y":3640,"wires":[["b229cb2c8862d5d6"]]},{"id":"2a9f426201abee33","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5000","payloadType":"num","x":90,"y":3600,"wires":[["b229cb2c8862d5d6"]]},{"id":"4526279955cc2c6f","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":90,"y":3720,"wires":[["cffe14a268ada410"]]},{"id":"68fa66b6459bd0ba","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":90,"y":3760,"wires":[["cffe14a268ada410"]]},{"id":"381dc879f60b6fa6","type":"switch","z":"b9860b4b9de8c8da","name":"","property":"payload.Pris","propertyType":"msg","rules":[{"t":"lt","v":"payload.snittpris","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":3620,"wires":[["29ae939925594d9d"]]},{"id":"29ae939925594d9d","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload.time","pt":"msg","to":"$number($moment().format(\"H.mm\"))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":3680,"wires":[["25c7a069d7cab50c","91bbaea5a1ee887c"]]},{"id":"25c7a069d7cab50c","type":"switch","z":"b9860b4b9de8c8da","name":"","property":"payload.time","propertyType":"msg","rules":[{"t":"btwn","v":"1.3","vt":"num","v2":"6","v2t":"num"}],"checkall":"true","repair":false,"outputs":1,"x":670,"y":3680,"wires":[["91bbaea5a1ee887c"]]},{"id":"91bbaea5a1ee887c","type":"debug","z":"b9860b4b9de8c8da","name":"debug 299","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":3500,"wires":[]}]

Low code just one JSONata expression to get time in a numeric format.

Thank you both of you, can build something on this.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.