Help with switch node

I cannot get a switch node to work with my payload.
have ben trying al sort of things but it will not work.
I have a reterminal with 4 buttons. it will give payload on the press and the release.
I only want to do something with the pressed payload of the 4 buttons.
so F1 does A, F2 does B, F3 does C and 0 does 4

all I got was a reaction from both the payloads of a button.
so if I press F1 it triggers 2 times.
on the press and on the release.
can anybody help me to get the switch node working?

I'm getting this payload from the 4 buttons (F1, F2, F3 and 0:

msg.payload : Object

{ key: "F1", status: "pressed" }

msg.payload : Object

{ key: "F1", status: "released" }

msg.payload : Object

{ key: "F2", status: "pressed" }

msg.payload : Object

{ key: "F2", status: "released" }

msg.payload : Object

{ key: "F3", status: "pressed" }

msg.payload : Object

{ key: "F3", status: "released" }

msg.payload : Object

{ key: "O", status: "pressed" }

msg.payload : Object

{ key: "O", status: "released" }

Welcome to the forum @hattemp

Do you mean that you are trying to configure a Switch node that only passes messages where msg.payload.status is pressed?

If so then configure the switch like this

image

2 Likes

I suspect the problem is the payload going into the switch node is an object.
I'm not sure that is supported.

You could try making a TWO new part(s) of the msg. if that structure is needed else where down the flow.

So it could be something like:

msg = {
    "payload":{"key":key,"stats":status of key},
    "key":key,
    "stats":status of key}

I know it is painful, but.....

Then you edit the switch node and change payload to either key or status depending on which you want to parse.

But.....
I'm guessing you will have to use two switch nodes.
One to determine the key and one to determine the status.
Actually more than 2, but it is implied to be two LAYERS.
eg:

[{"id":"c729e8d30418e78a","type":"switch","z":"d83300ecf7ff5383","name":"Status","property":"status","propertyType":"msg","rules":[{"t":"eq","v":"pressed","vt":"str"},{"t":"eq","v":"relaesed","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":210,"y":2160,"wires":[["04c79baf1ff7bbad"],["c0e008e714aa0ea0"]]},{"id":"04c79baf1ff7bbad","type":"switch","z":"d83300ecf7ff5383","name":"Pressed","property":"key","propertyType":"msg","rules":[{"t":"eq","v":"F1","vt":"str"},{"t":"eq","v":"F2","vt":"str"},{"t":"eq","v":"F3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":410,"y":2080,"wires":[["6b0d19258d6fcf1e"],["48b6aab087dca819"],["dbc89f74b528d39a"]]},{"id":"c0e008e714aa0ea0","type":"switch","z":"d83300ecf7ff5383","name":"Released","property":"key","propertyType":"msg","rules":[{"t":"eq","v":"F1","vt":"str"},{"t":"eq","v":"F2","vt":"str"},{"t":"eq","v":"F3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":410,"y":2240,"wires":[["965719ac6288f021"],["d135f2c2e8f78074"],["a6d204638af7e3c8"]]},{"id":"6b0d19258d6fcf1e","type":"debug","z":"d83300ecf7ff5383","name":"F1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2040,"wires":[]},{"id":"48b6aab087dca819","type":"debug","z":"d83300ecf7ff5383","name":"F2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2080,"wires":[]},{"id":"dbc89f74b528d39a","type":"debug","z":"d83300ecf7ff5383","name":"F3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2120,"wires":[]},{"id":"965719ac6288f021","type":"debug","z":"d83300ecf7ff5383","name":"F1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2200,"wires":[]},{"id":"d135f2c2e8f78074","type":"debug","z":"d83300ecf7ff5383","name":"F2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2240,"wires":[]},{"id":"a6d204638af7e3c8","type":"debug","z":"d83300ecf7ff5383","name":"F3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2280,"wires":[]}]

Screenshot from 2023-01-24 08-50-43

Or:

[{"id":"c729e8d30418e78a","type":"switch","z":"d83300ecf7ff5383","name":"Key","property":"key","propertyType":"msg","rules":[{"t":"eq","v":"F1","vt":"str"},{"t":"eq","v":"F2","vt":"str"},{"t":"eq","v":"F3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":210,"y":2160,"wires":[["04c79baf1ff7bbad"],["c601f7f4b83f4121"],["f859749fba212f3f"]]},{"id":"04c79baf1ff7bbad","type":"switch","z":"d83300ecf7ff5383","name":"Status","property":"status","propertyType":"msg","rules":[{"t":"eq","v":"pressed","vt":"str"},{"t":"eq","v":"repleased","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":2080,"wires":[["6b0d19258d6fcf1e"],["965719ac6288f021"]]},{"id":"c601f7f4b83f4121","type":"switch","z":"d83300ecf7ff5383","name":"Status","property":"status","propertyType":"msg","rules":[{"t":"eq","v":"pressed","vt":"str"},{"t":"eq","v":"repleased","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":2160,"wires":[["48b6aab087dca819"],["d135f2c2e8f78074"]]},{"id":"f859749fba212f3f","type":"switch","z":"d83300ecf7ff5383","name":"Status","property":"status","propertyType":"msg","rules":[{"t":"eq","v":"pressed","vt":"str"},{"t":"eq","v":"repleased","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":2260,"wires":[["dbc89f74b528d39a"],["a6d204638af7e3c8"]]},{"id":"6b0d19258d6fcf1e","type":"debug","z":"d83300ecf7ff5383","name":"F1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2040,"wires":[]},{"id":"965719ac6288f021","type":"debug","z":"d83300ecf7ff5383","name":"F1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2100,"wires":[]},{"id":"48b6aab087dca819","type":"debug","z":"d83300ecf7ff5383","name":"F2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2140,"wires":[]},{"id":"d135f2c2e8f78074","type":"debug","z":"d83300ecf7ff5383","name":"F2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2190,"wires":[]},{"id":"dbc89f74b528d39a","type":"debug","z":"d83300ecf7ff5383","name":"F3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2230,"wires":[]},{"id":"a6d204638af7e3c8","type":"debug","z":"d83300ecf7ff5383","name":"F3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":2280,"wires":[]}]

Screenshot from 2023-01-24 08-54-11

1 Like
[{"id":"2e165ac1725a1ff9","type":"inject","z":"c51f51da7ee02d68","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"switch\":\"pressed\"}","payloadType":"json","x":390,"y":1820,"wires":[["9b6f1fabd3c68a4c"]]},{"id":"9b6f1fabd3c68a4c","type":"switch","z":"c51f51da7ee02d68","name":"","property":"payload.switch","propertyType":"msg","rules":[{"t":"eq","v":"pressed","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":570,"y":1840,"wires":[["122134804a8b2c45"],["bc053bcf8c4d3521"]]},{"id":"122134804a8b2c45","type":"debug","z":"c51f51da7ee02d68","name":"debug 54","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":1820,"wires":[]},{"id":"bc053bcf8c4d3521","type":"debug","z":"c51f51da7ee02d68","name":"debug 55","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":1860,"wires":[]},{"id":"d007c27673d241d1","type":"inject","z":"c51f51da7ee02d68","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"switch\":\"caressed\"}","payloadType":"json","x":390,"y":1860,"wires":[["9b6f1fabd3c68a4c"]]}]

:slight_smile:

2 Likes

I stand corrected. :wink:

2 Likes

Yes now it works with the combined flows from @Trying_to_learn & @TotallyInformation
thank you all for your help and suggestions

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