Switch nodes problem - change nodes when certain value and reset

Hello All,

I wonder if anyone can help solving this. I can't for the life of me work out a solution.

When the raspberry switch node gets a 0 and it goes to the '66' switch node, I want it to be active until the value is greater than 69 and then switch to the '70' node and reseting to use '66' node when the raspberry node switches to 1.

I hope that makes sense.

Thanks in advance.

It may help everyone if you did NOT include the sonoff nodes.

Also include some inject nodes that inject the values above, below and equal to what you are wanting.

That way we can press the inject nodes and see what is happening.

Part of the possible problem is the first switch node looks at msg.payload.raspberry.

The second (mentoined) switch node looks at msg.payload.test

So unless BOTH of those are parts of the message, it won't work.

You seem to be making it complicated.

This may be of use.

I'm not sure.

[{"id":"9ca02b1571269132","type":"switch","z":"7f2f416d9e78b7fb","name":"Raspberry switch","property":"payload.raspberry","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":470,"wires":[["debe912c9a806cdd","2db82bb311c86903"],[]]},{"id":"545f2b6d0466fb4f","type":"junction","z":"7f2f416d9e78b7fb","x":570,"y":470,"wires":[["9ca02b1571269132","d78b19a8f58e55b5"]]},{"id":"debe912c9a806cdd","type":"switch","z":"7f2f416d9e78b7fb","name":"66","property":"payload.test","propertyType":"msg","rules":[{"t":"btwn","v":"1","vt":"num","v2":"63","v2t":"num"},{"t":"btwn","v":"64","vt":"num","v2":"100","v2t":"num"}],"checkall":"true","repair":false,"outputs":2,"x":890,"y":410,"wires":[["9f265664d400cc51","719fac3de4790af6"],["3356f23f37385155","27e3b90516fa3e30"]]},{"id":"2db82bb311c86903","type":"debug","z":"7f2f416d9e78b7fb","name":"debug 306","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.test","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":340,"wires":[]},{"id":"496fd9e9e862e46b","type":"function","z":"7f2f416d9e78b7fb","name":"function 36","func":"let msg1 = {};\n\nlet x = msg.payload;\n\nmsg1.payload = {\"raspberry\":0,\"test\":x};\n\n//node.warn(msg1);\n\nreturn msg1;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":470,"wires":[["545f2b6d0466fb4f"]]},{"id":"d78b19a8f58e55b5","type":"debug","z":"7f2f416d9e78b7fb","name":"debug 305","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":400,"wires":[]},{"id":"9f265664d400cc51","type":"change","z":"7f2f416d9e78b7fb","name":"payload off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":550,"wires":[["6cc39d704b5f95a1"]]},{"id":"719fac3de4790af6","type":"change","z":"7f2f416d9e78b7fb","name":"payload on","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":390,"wires":[["9689cb5b53fb22ea"]]},{"id":"3356f23f37385155","type":"change","z":"7f2f416d9e78b7fb","name":"payload off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":430,"wires":[["9689cb5b53fb22ea"]]},{"id":"27e3b90516fa3e30","type":"change","z":"7f2f416d9e78b7fb","name":"payload on","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":510,"wires":[["6cc39d704b5f95a1"]]},{"id":"2c995f110bcb3e56","type":"junction","z":"7f2f416d9e78b7fb","x":320,"y":470,"wires":[["496fd9e9e862e46b"]]},{"id":"1a347da86ce0a986","type":"switch","z":"7f2f416d9e78b7fb","name":"30","property":"payload.test","propertyType":"msg","rules":[{"t":"btwn","v":"1","vt":"num","v2":"30","v2t":"num"},{"t":"btwn","v":"31","vt":"num","v2":"100","v2t":"num"}],"checkall":"true","repair":false,"outputs":2,"x":890,"y":530,"wires":[["719fac3de4790af6","9f265664d400cc51"],["3356f23f37385155","27e3b90516fa3e30"]]},{"id":"6cc39d704b5f95a1","type":"debug","z":"7f2f416d9e78b7fb","name":"debug 304","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1300,"y":530,"wires":[]},{"id":"9689cb5b53fb22ea","type":"debug","z":"7f2f416d9e78b7fb","name":"debug 303","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":410,"wires":[]},{"id":"7741af307c5dcca9","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"65","payloadType":"num","x":190,"y":410,"wires":[["2c995f110bcb3e56"]]},{"id":"01ae580f9cb43a2e","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"66","payloadType":"num","x":190,"y":450,"wires":[["2c995f110bcb3e56"]]},{"id":"9292b064e410ebf8","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"67","payloadType":"num","x":190,"y":490,"wires":[["2c995f110bcb3e56"]]},{"id":"e98f580ef72ebc4b","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"68","payloadType":"num","x":190,"y":530,"wires":[["2c995f110bcb3e56"]]},{"id":"57523052acf0ef2f","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"69","payloadType":"num","x":190,"y":570,"wires":[["2c995f110bcb3e56"]]},{"id":"6fd47af761d226b6","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"70","payloadType":"num","x":190,"y":610,"wires":[["2c995f110bcb3e56"]]},{"id":"1b91dd0e75f154ab","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"64","payloadType":"num","x":190,"y":370,"wires":[["2c995f110bcb3e56"]]},{"id":"b4e0f6edec31c29e","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"63","payloadType":"num","x":190,"y":330,"wires":[["2c995f110bcb3e56"]]},{"id":"dd9f6d812efd2fe9","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"62","payloadType":"num","x":190,"y":290,"wires":[["2c995f110bcb3e56"]]},{"id":"8e9bab76ff1d0c35","type":"inject","z":"7f2f416d9e78b7fb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"61","payloadType":"num","x":190,"y":250,"wires":[["2c995f110bcb3e56"]]},{"id":"3507a88de0877375","type":"switch","z":"7f2f416d9e78b7fb","name":"70","property":"payload.test","propertyType":"msg","rules":[{"t":"btwn","v":"1","vt":"num","v2":"69","v2t":"num"},{"t":"btwn","v":"70","vt":"num","v2":"100","v2t":"num"}],"checkall":"true","repair":false,"outputs":2,"x":890,"y":290,"wires":[[],[]]}]

Hello, thank you very much for the reply.

Sorry that was unclear. I have revised the flow and will upload below.

I don't think I explained what I am trying to do properly.

When 'Raspberry Switch' gets a payload.raspberry 0 and payload.test <70 it will use switch node '66'

If then 'Raspberry Switch' gets a payload.raspberry 0 and payload.test =>70 it will use switch node '70' until 'Raspberry Switch' gets a payload.raspberry 1 which then uses '30' and also resets back to switch node '66' next time a payload.raspberry 0 sent.

I hope that makes more sense.

[
    {
        "id": "7f2f416d9e78b7fb",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "9ca02b1571269132",
        "type": "switch",
        "z": "7f2f416d9e78b7fb",
        "name": "Raspberry switch",
        "property": "payload.raspberry",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "1",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 450,
        "y": 200,
        "wires": [
            [
                "debe912c9a806cdd"
            ],
            [
                "1a347da86ce0a986"
            ]
        ]
    },
    {
        "id": "debe912c9a806cdd",
        "type": "switch",
        "z": "7f2f416d9e78b7fb",
        "name": "66",
        "property": "payload.test",
        "propertyType": "msg",
        "rules": [
            {
                "t": "btwn",
                "v": "1",
                "vt": "num",
                "v2": "63",
                "v2t": "num"
            },
            {
                "t": "btwn",
                "v": "64",
                "vt": "num",
                "v2": "100",
                "v2t": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 670,
        "y": 140,
        "wires": [
            [
                "9f265664d400cc51",
                "719fac3de4790af6"
            ],
            [
                "3356f23f37385155",
                "27e3b90516fa3e30"
            ]
        ]
    },
    {
        "id": "719fac3de4790af6",
        "type": "change",
        "z": "7f2f416d9e78b7fb",
        "name": "payload on 1",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "on",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 910,
        "y": 120,
        "wires": [
            [
                "bd43c590d23e78f1"
            ]
        ]
    },
    {
        "id": "3356f23f37385155",
        "type": "change",
        "z": "7f2f416d9e78b7fb",
        "name": "payload off 2",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "off",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 910,
        "y": 160,
        "wires": [
            [
                "bd43c590d23e78f1"
            ]
        ]
    },
    {
        "id": "27e3b90516fa3e30",
        "type": "change",
        "z": "7f2f416d9e78b7fb",
        "name": "payload on 3",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "on",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 910,
        "y": 240,
        "wires": [
            [
                "03481e5864a7e85f"
            ]
        ]
    },
    {
        "id": "9f265664d400cc51",
        "type": "change",
        "z": "7f2f416d9e78b7fb",
        "name": "payload off 4",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "off",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 910,
        "y": 280,
        "wires": [
            [
                "03481e5864a7e85f"
            ]
        ]
    },
    {
        "id": "3507a88de0877375",
        "type": "switch",
        "z": "7f2f416d9e78b7fb",
        "name": "70",
        "property": "payload.test",
        "propertyType": "msg",
        "rules": [
            {
                "t": "btwn",
                "v": "1",
                "vt": "num",
                "v2": "69",
                "v2t": "num"
            },
            {
                "t": "btwn",
                "v": "70",
                "vt": "num",
                "v2": "100",
                "v2t": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 770,
        "y": 60,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "1a347da86ce0a986",
        "type": "switch",
        "z": "7f2f416d9e78b7fb",
        "name": "30",
        "property": "payload.test",
        "propertyType": "msg",
        "rules": [
            {
                "t": "btwn",
                "v": "1",
                "vt": "num",
                "v2": "30",
                "v2t": "num"
            },
            {
                "t": "btwn",
                "v": "31",
                "vt": "num",
                "v2": "100",
                "v2t": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 670,
        "y": 260,
        "wires": [
            [
                "719fac3de4790af6",
                "9f265664d400cc51"
            ],
            [
                "3356f23f37385155",
                "27e3b90516fa3e30"
            ]
        ]
    },
    {
        "id": "c265b105186137a7",
        "type": "inject",
        "z": "7f2f416d9e78b7fb",
        "name": "R0 - 60",
        "props": [
            {
                "p": "payload.raspberry",
                "v": "0",
                "vt": "num"
            },
            {
                "p": "payload.test",
                "v": "60",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 100,
        "wires": [
            [
                "9ca02b1571269132"
            ]
        ]
    },
    {
        "id": "bd43c590d23e78f1",
        "type": "debug",
        "z": "7f2f416d9e78b7fb",
        "name": "debug 306",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1110,
        "y": 140,
        "wires": []
    },
    {
        "id": "03481e5864a7e85f",
        "type": "debug",
        "z": "7f2f416d9e78b7fb",
        "name": "debug 307",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1110,
        "y": 260,
        "wires": []
    },
    {
        "id": "53f9a4e635f358ec",
        "type": "inject",
        "z": "7f2f416d9e78b7fb",
        "name": "R1 - 60",
        "props": [
            {
                "p": "payload.raspberry",
                "v": "1",
                "vt": "num"
            },
            {
                "p": "payload.test",
                "v": "60",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 400,
        "wires": [
            [
                "9ca02b1571269132"
            ]
        ]
    },
    {
        "id": "f62007c40ba7b4f8",
        "type": "inject",
        "z": "7f2f416d9e78b7fb",
        "name": "R0 - 65",
        "props": [
            {
                "p": "payload.raspberry",
                "v": "0",
                "vt": "num"
            },
            {
                "p": "payload.test",
                "v": "65",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 140,
        "wires": [
            [
                "9ca02b1571269132"
            ]
        ]
    },
    {
        "id": "36f784e373f66a1b",
        "type": "inject",
        "z": "7f2f416d9e78b7fb",
        "name": "R0 - 72",
        "props": [
            {
                "p": "payload.raspberry",
                "v": "0",
                "vt": "num"
            },
            {
                "p": "payload.test",
                "v": "72",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 180,
        "wires": [
            [
                "9ca02b1571269132"
            ]
        ]
    },
    {
        "id": "a75bd4a9ee8a1b78",
        "type": "inject",
        "z": "7f2f416d9e78b7fb",
        "name": "R0 - 30",
        "props": [
            {
                "p": "payload.raspberry",
                "v": "1",
                "vt": "num"
            },
            {
                "p": "payload.test",
                "v": "30",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 360,
        "wires": [
            [
                "9ca02b1571269132"
            ]
        ]
    }
]

I think the word UNTIL is the problem.

The switch node works on a message by message basis.

NOT what the last one was, or UNTIL something else.

If you are wanting to use the 70, please wire it in how you think it needs to be done.

(And for me: please only export the nodes, not the entire flow. Each time I import your code it is another tab)

This it also a problem because of the switch node you call 66.

Screenshot from 2024-01-08 09-50-23

Where is the test of => 70?

You are saying if is between 64 and 100 send it to output 2.

So where does the => 70 fit in?

Just asking.

That's the issue I cannot think how to wire '70' in. or anyway to make it work. I presume it can be done, but no idea how.

After payload.test gets =>70 it needs to switch on/off as switch node '70' until the raspberry switch node changes. When raspberry switch node changes back it needs to use '66' again.

payload.test is usually around 65 when raspberry switch node gets its first '0'. This rises every input to around 73 and then drops down again. When it is dropping down I need it to follow '70' not '66'. Then when raspberry switch node changes back I need it to be reset to '66'

Its baffling me how to attempt to do it.

But you haven't shown that in any of the switch nodes.

On a side note:
The flow (screen shot) you posted.

It helps people if you group the inject nodes so they make sense.

Something like this:

Because you put the 30 at the bottom beside the one which is in an entirely different group/set.

The top two get an on and the bottom two get an off.

Mixing the inject nodes as you did kind of throws confusion into the mix.

Hang on and I will see if I can understand your last post with some code.

EDIT

Nah, you are really going to have to explain the 0 - 63 and 64 - 100.

What is the importance of this?

Because until I understand what that means, I am not really going to be able help you.

The two Sonos switches are effecting payload.test number. Payload on 1 making it go up, Payload on 3 slowly stopping it going up and then go down. Payload off 2 and 4 just turning the opposing item off.

I need payload on 3 to start at =>64 initially, but after going over payload.test =>70 I need it to turn off when =<69.9.

Why TWO sonos devices?
One.
If it is below 69, turn on.
If it is above 70, turn off.

Or am I still missing something?

I'm going to draw it so it makes sense.

Sorry the inject nodes were in the correct place, just didn't see that I labeled one wrong.

What is/are these 3, 2 and 4 you are mentioning?

And changing from payload.test to payload.(something else) isn't helping me understand what you are wanting to do.

Suggestion:

Forget (for now) that the reading/s sometimes go WAY OUT OF SPEC.
And forget the second (lower) debug node. Just leave it turned off for now.
You can leave it in the flow, but don't worry about what it is doing.

1 - what is the input range SUPPOSED TO BE? Min-Max
2 - at what values do you want things to change?
(Say < 40 off, =>40 on)

Just to establish a base line.

P.S.

This is the only part of the code (and I know I said forget about the flow for now) but to just establish the parts on which we are working now.

Well, I was half way through reading it and you deleted it.

Not helping.

SMALL SUGGESTION:

change msg.payload.test to msg.payload.temp (or better still msg.payload.temperature) if possible.

test is not really representing what it is giving you.

The flow was taken from a larger working flow. The two Sonos devices control two different bits of kit. This is not exactly what it is doing but hopefully this will make it make sense. Drawing didn't work.

Sonos device 1 = debug 306 = Heater

Sonos device 2 = debug 307 = Chiller

payload.test = temp

Raspberry switch (RS)

RS gets 0 goes to '66' 64-100 switches on chiller. Payload.test rises every 15 seconds.

might start at 66 then 69, 71, 73 then it goes back down. 72, 71, 69. It takes a few mins to start chilling properly and rises until it does.

This is fine until it hits 69 when I want the chiller to turn off now and the heater to turn on instead. Switching as per settings in '70'. If it doesn't change it carries on chilling down to whatever '66' is set to.

It can't be just '70' as it doesn't switch on in time.

Hope that is clearer.

Sorry I realised that I had written heater and chiller the wrong way around.

I should have done for this you are correct. I should make it as clear as possible. It's hard enough to explain any way.

Sorry and thank you for being patient.

Confusing.

gets....?????

RS.....???? Raspberry Switch - ok, you kind of did declare that above, but.....
gets?

If the temperature is RISING every 15 seconds and it is se to CHILL - your words - you have a bigger problem.

or do you mean the temperature VALUE is RECEIVED every 15 seconds?

BIG difference.

Sorry yes value received.