Create simple if then flow

Hello,
I've been trying to build a simple IF THEN logic for a few days now. But do not get it. The idea is that if one value is over 40 and the other value is "ON" something should be done. Somewhere is still the worm in it :frowning: Can someone help me?

Here is my Try:

[{"id":"7419f1f4.3e9738","type":"switch","z":"75b2223b.041e54","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"brightness","vt":"str"},{"t":"cont","v":"switch","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":200,"wires":[["e34034ec.12b678","e8e30a8a.39a7a8"],["3cccf729.f457","e8e30a8a.39a7a8"]]},{"id":"e34034ec.12b678","type":"switch","z":"75b2223b.041e54","name":"","property":"payload.value","propertyType":"msg","rules":[{"t":"gt","v":"40","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":160,"wires":[["658b2098.307928","6c632cc2.16d534"]]},{"id":"658b2098.307928","type":"change","z":"75b2223b.041e54","name":"","rules":[{"t":"set","p":"dummy","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":160,"wires":[["9c5545c3.c2fe18","ca216d67.2f438"]]},{"id":"ed54a45b.9f5da8","type":"change","z":"75b2223b.041e54","name":"","rules":[{"t":"set","p":"dummy2","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":240,"wires":[["9c5545c3.c2fe18","ca216d67.2f438"]]},{"id":"3cccf729.f457","type":"switch","z":"75b2223b.041e54","name":"","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":240,"wires":[["ed54a45b.9f5da8","6c632cc2.16d534"]]},{"id":"9c5545c3.c2fe18","type":"switch","z":"75b2223b.041e54","name":"","property":"dummy","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":940,"y":198,"wires":[["db2c3abb.5ddc5"],[]]},{"id":"e8e30a8a.39a7a8","type":"debug","z":"75b2223b.041e54","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":493,"y":519,"wires":[]},{"id":"6c632cc2.16d534","type":"debug","z":"75b2223b.041e54","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":794,"y":529,"wires":[]},{"id":"ca216d67.2f438","type":"debug","z":"75b2223b.041e54","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1086,"y":517,"wires":[]},{"id":"db2c3abb.5ddc5","type":"debug","z":"75b2223b.041e54","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1327,"y":513,"wires":[]},{"id":"5e6032c.272094c","type":"inject","z":"75b2223b.041e54","name":"","topic":"brightness","payload":"45","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":105,"y":127,"wires":[["7419f1f4.3e9738"]]},{"id":"36389b1e.4ec74c","type":"inject","z":"75b2223b.041e54","name":"","topic":"switch","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":94,"y":285,"wires":[["7419f1f4.3e9738"]]},{"id":"209f6e74.7ea272","type":"inject","z":"75b2223b.041e54","name":"","topic":"switch","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":89,"y":322,"wires":[["7419f1f4.3e9738"]]},{"id":"fb83322f.688ef","type":"inject","z":"75b2223b.041e54","name":"","topic":"brightness","payload":"30","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":108,"y":168,"wires":[["7419f1f4.3e9738"]]}]

image

image

Start here... is the msg.payload not the msg.payload.value and below you should the type of message in this case one is a number and the other is a string,,,, respect the other part of the flow I'm not sure what you are trying to do.

Regards

I have 2 different values - number and string. If the number is > 40 and the other value is "ON" then the TRUE way should be taken at the last switch. If not then the output "Otherwise"

But the flow you posted above fails before you get to the last switch.

As David said, In the "Brightness" inject node you set msg.payload to be a value. But in your switch node you check for msg.payload.value > msg.40 it should be msg.payload > 40 (use the arrow down to select numbers as per Davids images)

You also never set your flow variables back to false

It's easier if you also add a name to your debug nodes it makes it easier to see which debug message comes from which node.

Also, create a seperate debug for each leg of the switches. That way you know what condition was met. And change them to display the entire msg object.

Hi, i think the only Problem i have now is the last Switch. Here i must check if both "FLOWS" are true (dummy and dummy2). I have create a IF Statement in this. But now there is an error.
Can somebody help?

Here is the complete flow:

[{"id":"be43a18d.a58e","type":"switch","z":"59b2c712.73a23","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"brightness","vt":"str"},{"t":"cont","v":"switch","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":338,"y":218,"wires":[["9d3fba46.bf69c8","72daba28.67861c"],["3ec872b1.c64b5e","72daba28.67861c"]]},{"id":"9d3fba46.bf69c8","type":"switch","z":"59b2c712.73a23","name":"brightness_flow","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"40","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":568,"y":178,"wires":[["a11dff76.0e2cd8","492f04c7.7a8c6c"]]},{"id":"a11dff76.0e2cd8","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":748,"y":178,"wires":[["56b81b68.e920c4","e34874db.75366"]]},{"id":"259ffe79.78c132","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy2","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":748,"y":258,"wires":[["56b81b68.e920c4","e34874db.75366"]]},{"id":"3ec872b1.c64b5e","type":"switch","z":"59b2c712.73a23","name":"switch_flow","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":558,"y":258,"wires":[["259ffe79.78c132","492f04c7.7a8c6c"]]},{"id":"56b81b68.e920c4","type":"switch","z":"59b2c712.73a23","name":"True or not","property":"(if (flow.dummy and flow.dummy2))","propertyType":"jsonata","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1008,"y":216,"wires":[["3da38131.1c71be"],[]]},{"id":"72daba28.67861c","type":"debug","z":"59b2c712.73a23","name":"AFter first Switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":561,"y":537,"wires":[]},{"id":"492f04c7.7a8c6c","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":842,"y":547,"wires":[]},{"id":"e34874db.75366","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1134,"y":535,"wires":[]},{"id":"3da38131.1c71be","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1375,"y":531,"wires":[]},{"id":"69ae5816.caa1f8","type":"inject","z":"59b2c712.73a23","name":"","topic":"brightness","payload":"45","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":153,"y":145,"wires":[["be43a18d.a58e"]]},{"id":"c5380475.9dc81","type":"inject","z":"59b2c712.73a23","name":"","topic":"switch","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":142,"y":303,"wires":[["be43a18d.a58e"]]},{"id":"57bae2bc.78fde4","type":"inject","z":"59b2c712.73a23","name":"","topic":"switch","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":137,"y":340,"wires":[["be43a18d.a58e"]]},{"id":"de50ecd4.246918","type":"inject","z":"59b2c712.73a23","name":"","topic":"brightness","payload":"30","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":156,"y":186,"wires":[["be43a18d.a58e","89a2d5ad.0a8048"]]},{"id":"89a2d5ad.0a8048","type":"debug","z":"59b2c712.73a23","name":"Brightness 30","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":293,"y":543,"wires":[]}]

Change your JSONata expression in the switch True or not to:

$flowContext('dummy') and $flowContext('dummy2')

Is still don't think this will do what you want it to. Where in your flow do you set the contexts back to false if the brightness falls below 40?

Hi.
Thank you for the info. How do I reset the status to false? I have now installed a second check and this output also connected to the next switch. Is that right or are there better ways?

[{"id":"be43a18d.a58e","type":"switch","z":"59b2c712.73a23","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"brightness","vt":"str"},{"t":"cont","v":"switch","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":338,"y":218,"wires":[["9d3fba46.bf69c8","72daba28.67861c"],["3ec872b1.c64b5e","72daba28.67861c"]]},{"id":"9d3fba46.bf69c8","type":"switch","z":"59b2c712.73a23","name":"brightness_flow","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"40","vt":"num"},{"t":"lt","v":"40","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":532,"y":108,"wires":[["a11dff76.0e2cd8","492f04c7.7a8c6c"],["78635aa6.3c4ae4"]]},{"id":"a11dff76.0e2cd8","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":814,"y":102,"wires":[["56b81b68.e920c4","e34874db.75366"]]},{"id":"259ffe79.78c132","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy2","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":821,"y":263,"wires":[["56b81b68.e920c4","e34874db.75366"]]},{"id":"3ec872b1.c64b5e","type":"switch","z":"59b2c712.73a23","name":"switch_flow","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":522,"y":257,"wires":[["259ffe79.78c132","492f04c7.7a8c6c"],["f6c198d4.f7037"]]},{"id":"56b81b68.e920c4","type":"switch","z":"59b2c712.73a23","name":"True or not","property":"($flowContext('dummy') and $flowContext('dummy2'))","propertyType":"jsonata","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1139,"y":201,"wires":[["3da38131.1c71be"],[]]},{"id":"72daba28.67861c","type":"debug","z":"59b2c712.73a23","name":"AFter first Switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":575,"y":616,"wires":[]},{"id":"492f04c7.7a8c6c","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":865,"y":608,"wires":[]},{"id":"e34874db.75366","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1160,"y":597,"wires":[]},{"id":"3da38131.1c71be","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1376,"y":608,"wires":[]},{"id":"69ae5816.caa1f8","type":"inject","z":"59b2c712.73a23","name":"","topic":"brightness","payload":"45","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":153,"y":145,"wires":[["be43a18d.a58e"]]},{"id":"c5380475.9dc81","type":"inject","z":"59b2c712.73a23","name":"","topic":"switch","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":142,"y":303,"wires":[["be43a18d.a58e"]]},{"id":"57bae2bc.78fde4","type":"inject","z":"59b2c712.73a23","name":"","topic":"switch","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":137,"y":340,"wires":[["be43a18d.a58e"]]},{"id":"de50ecd4.246918","type":"inject","z":"59b2c712.73a23","name":"","topic":"brightness","payload":"30","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":156,"y":186,"wires":[["be43a18d.a58e","89a2d5ad.0a8048"]]},{"id":"89a2d5ad.0a8048","type":"debug","z":"59b2c712.73a23","name":"Brightness 30","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":300,"y":615,"wires":[]},{"id":"78635aa6.3c4ae4","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":814,"y":147,"wires":[["56b81b68.e920c4"]]},{"id":"f6c198d4.f7037","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy2","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":304,"wires":[["56b81b68.e920c4"]]}]

Hi,

this Flow is working after change some settings.
Is there a better way?

[{"id":"be43a18d.a58e","type":"switch","z":"59b2c712.73a23","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"brightness","vt":"str"},{"t":"cont","v":"switch","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":338,"y":218,"wires":[["9d3fba46.bf69c8","72daba28.67861c"],["3ec872b1.c64b5e","72daba28.67861c"]]},{"id":"9d3fba46.bf69c8","type":"switch","z":"59b2c712.73a23","name":"brightness_flow","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"40","vt":"num"},{"t":"lt","v":"40","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":532,"y":108,"wires":[["a11dff76.0e2cd8","492f04c7.7a8c6c"],["78635aa6.3c4ae4"]]},{"id":"a11dff76.0e2cd8","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":814,"y":102,"wires":[["56b81b68.e920c4","e34874db.75366"]]},{"id":"259ffe79.78c132","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy2","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":821,"y":263,"wires":[["56b81b68.e920c4","e34874db.75366"]]},{"id":"3ec872b1.c64b5e","type":"switch","z":"59b2c712.73a23","name":"switch_flow","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":522,"y":257,"wires":[["259ffe79.78c132","492f04c7.7a8c6c"],["f6c198d4.f7037"]]},{"id":"56b81b68.e920c4","type":"switch","z":"59b2c712.73a23","name":"True or not","property":"($flowContext('dummy') and $flowContext('dummy2'))","propertyType":"jsonata","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1139,"y":201,"wires":[["3da38131.1c71be"],[]]},{"id":"72daba28.67861c","type":"debug","z":"59b2c712.73a23","name":"AFter first Switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":575,"y":616,"wires":[]},{"id":"492f04c7.7a8c6c","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":865,"y":608,"wires":[]},{"id":"e34874db.75366","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1160,"y":597,"wires":[]},{"id":"3da38131.1c71be","type":"debug","z":"59b2c712.73a23","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1376,"y":608,"wires":[]},{"id":"69ae5816.caa1f8","type":"inject","z":"59b2c712.73a23","name":"","topic":"brightness","payload":"45","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":153,"y":145,"wires":[["be43a18d.a58e"]]},{"id":"c5380475.9dc81","type":"inject","z":"59b2c712.73a23","name":"","topic":"switch","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":142,"y":303,"wires":[["be43a18d.a58e"]]},{"id":"57bae2bc.78fde4","type":"inject","z":"59b2c712.73a23","name":"","topic":"switch","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":137,"y":340,"wires":[["be43a18d.a58e"]]},{"id":"de50ecd4.246918","type":"inject","z":"59b2c712.73a23","name":"","topic":"brightness","payload":"30","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":156,"y":186,"wires":[["be43a18d.a58e","89a2d5ad.0a8048"]]},{"id":"89a2d5ad.0a8048","type":"debug","z":"59b2c712.73a23","name":"Brightness 30","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":300,"y":615,"wires":[]},{"id":"78635aa6.3c4ae4","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":814,"y":147,"wires":[["56b81b68.e920c4"]]},{"id":"f6c198d4.f7037","type":"change","z":"59b2c712.73a23","name":"","rules":[{"t":"set","p":"dummy2","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":304,"wires":[["56b81b68.e920c4"]]}]

I know you are keen to promote your dsm node at every opportunity, but sometimes it is better to help show how the built-in nodes and concepts can be used, as that will be much more reusable to other tasks.

Not really, you can find more use cases in the Wiki.

The question was is there a better way?
So I couldn't resist :slight_smile:

But yes, I see!