If ( var1 = true and var2 = true ) then / else

hi

in my project, node-red is for me complete new, but I like it very very much

but in this case, I'm not able to finde a way out to solve the following function

a) it is a scheduler where is set the time to start a sequence automatically

b) a switch, for manually start (without scheduler) or for automatic start (with scheduler)

I have tried several ways without any success - what is there wrong ???

I would be very thankful for any help

Max

I would be very thankful for any help

Max

Please see this post and then edit the flow in your post above

Very hard to make out what you are doing but a quick glance seems to show that you have === "true" - are your true/false entries actually strings? If not, it should probably be === true

Once you repost as per the above it will be easier to see - but i would suggest before you go much further - have a look at

  1. Schedex
  2. MyTimeout - ncherry
  3. BigTimer - Peter scargill

All of these are programmable timers that can operate at slightly different levels and in slightly different ways - i have yet to find a home automation scheduing problem that i am not able to manage with one of these three nodes

Craig

thank you

MyTimeout by "ncherry" I have seen, but this timer is for my project much, to much complex

I'm worry about only of this problem, why I can not make a decision like,

if (var1 = 1 AND var2 = 1) then 1, else 0 (when one of this var are 0)

but may be this "AND" would be a problem, I think

Max

Repost your flow as the other guys have said so we can import it.

Then document in plain english (words) what real world problem you are trying to solve and your thoughts on the logic that you are using to approach it.

We may be able to come up with something for you.

Here is an example of how i am using Mytimeout in a simple scenario

[{"id":"6ea69ec4.cfb7c","type":"ui_button","z":"a78930fe.ed232","name":"Manual 8hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":3,"width":0,"height":0,"passthru":false,"label":"Manual CP 8 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 28800,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":780,"wires":[["a3177923.ca0018"]]},{"id":"868c3c0f.4264d","type":"mqtt out","z":"a78930fe.ed232","name":"","topic":"topic/circulatingpumpoverride","qos":"","retain":"","broker":"389dd264.7716de","x":940,"y":900,"wires":[]},{"id":"da81147e.1b8758","type":"inject","z":"a78930fe.ed232","name":"Turn off CP Override","topic":"topic/circulatingpumpoverride","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":170,"y":940,"wires":[["a3177923.ca0018"]]},{"id":"45112e1b.eb1e7","type":"ui_button","z":"a78930fe.ed232","name":"Manual 4hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":2,"width":0,"height":0,"passthru":false,"label":"Manual CP 4 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 14400,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":820,"wires":[["a3177923.ca0018"]]},{"id":"467580d3.350e2","type":"ui_button","z":"a78930fe.ed232","name":"Turn off Manual Override of CP","group":"2b345d73.f4d042","order":4,"width":0,"height":0,"passthru":false,"label":"Turn off Manual Override of CP","color":"","bgcolor":"","icon":"","payload":"0","payloadType":"str","topic":"topic/circulatingpumpoverride","x":190,"y":900,"wires":[["a3177923.ca0018"]]},{"id":"a3177923.ca0018","type":"mytimeout","z":"a78930fe.ed232","name":"Circulatiing Pump Manual Turn on","outtopic":"topic/circulatingpumpoverride","outsafe":"1","outwarning":"","outunsafe":"0","warning":"5","timer":"3600","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":640,"y":860,"wires":[["868c3c0f.4264d","7e21acd2.904284"],["8511d477.998b38","e516bdb2.36da9"]]},{"id":"b6dc0aa1.e05c68","type":"ui_button","z":"a78930fe.ed232","name":"Manual 2hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":1,"width":0,"height":0,"passthru":false,"label":"Manual CP 2 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 7200,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":860,"wires":[["a3177923.ca0018"]]},{"id":"7e21acd2.904284","type":"debug","z":"a78930fe.ed232","name":"CP Fire up - Node 1","active":false,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","x":920,"y":860,"wires":[]},{"id":"8511d477.998b38","type":"debug","z":"a78930fe.ed232","name":"CP Fire up - Node 2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":920,"y":960,"wires":[]},{"id":"e516bdb2.36da9","type":"change","z":"a78930fe.ed232","name":"Set Variable to get it onto Dashboard","rules":[{"t":"set","p":"CIrculatingPumpTimeToRun","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":1020,"wires":[["caf1a13f.d8d6"]]},{"id":"caf1a13f.d8d6","type":"change","z":"a78930fe.ed232","name":"Take Variable and Put into Payload","rules":[{"t":"move","p":"CIrculatingPumpTimeToRun","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1080,"wires":[["d5602c1e.081f4"]]},{"id":"d5602c1e.081f4","type":"ui_text_input","z":"a78930fe.ed232","name":"","label":"Manual Pump - Time to run (Sec)","group":"2b345d73.f4d042","order":0,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":960,"y":1080,"wires":[[]]},{"id":"2b345d73.f4d042","type":"ui_group","z":"","name":"Circulating Pump Control","tab":"c9d53e06.a95c8","order":4,"disp":true,"width":"5"},{"id":"389dd264.7716de","type":"mqtt-broker","z":"a78930fe.ed232","broker":"localhost","port":"1883","clientid":"Node-Red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c9d53e06.a95c8","type":"ui_tab","z":"","name":"CURTIN house main page","icon":"dashboard","order":1}]

Nothing fancy in here and fairly straight forward

Here is an example i am doing now with Schedex that is equally as simple

[{"id":"c27bb157.46dde","type":"debug","z":"6865126d.1bde1c","name":"Raw MQTT from the Pump Relay","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":480,"y":720,"wires":[]},{"id":"c82a1ddf.22956","type":"mqtt in","z":"6865126d.1bde1c","name":"Incoming MQTT from Tank Pump","topic":"Tank_Top_Up_Pump/Tank_Relay/Switch","qos":"2","broker":"e2ed99fb.aa45d8","x":190,"y":640,"wires":[["c27bb157.46dde","99ce6aa4.7369b8"]]},{"id":"8ddc3312.3b0ff","type":"mqtt out","z":"6865126d.1bde1c","name":"Water Tank Top Up","topic":"Tank_Top_Up_Pump/GPIO/12","qos":"","retain":"","broker":"e2ed99fb.aa45d8","x":470,"y":580,"wires":[]},{"id":"b1246216.6755b","type":"inject","z":"6865126d.1bde1c","name":"Turn off Relay","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":400,"wires":[["8ddc3312.3b0ff"]]},{"id":"63fea32f.f1fd2c","type":"inject","z":"6865126d.1bde1c","name":"Turn on Relay","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":460,"wires":[["8ddc3312.3b0ff"]]},{"id":"7d8236d1.3c4ac8","type":"schedex","z":"6865126d.1bde1c","name":"Timer to Top up Water Tank","suspended":true,"lat":"","lon":"","ontime":"3:15","ontopic":"","onpayload":"1","onoffset":0,"onrandomoffset":0,"offtime":"3:35","offtopic":"","offpayload":"0","offoffset":0,"offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":180,"y":580,"wires":[["8ddc3312.3b0ff","3c4dd8f5.c34618","e4b7f9a0.8f9b68"]]},{"id":"2914711a.99b39e","type":"comment","z":"6865126d.1bde1c","name":"Automatic Control","info":"","x":150,"y":540,"wires":[]},{"id":"99ce6aa4.7369b8","type":"function","z":"6865126d.1bde1c","name":"Build Message for LogFile","func":"var topic = msg.topic;\nif (msg.payload === \"1\") {\n    var p = \"On\";\n    } \nelse if (msg.payload === \"0\") { \n    var p = \"Off\";\n    }\nelse var p = \"Unknown\";\n\nvar d = flow.get(\"MyDateTime\") || \"0\";\n//var myCount = flow.get(\"count\", storeName);\n\n//create message to write to the log file\nvar payload1 = (d + \" Tank Pump is \" + p + \" Topic is: \" + msg.topic);\n//Store message so it can be output on output 1\nvar msg1 = { payload:payload1 };\n\n//Create 2nd message for screen writing on scrolling table\nvar payload2 = (d + \" Tank Pump is \" + p);\n//Store message so it can be output on output 2\nvar msg2 = { payload:payload2 };\n\nif (p == \"On\") {\nvar msg3 = { payload:'<i class=\"fa fa-refresh fa-spin fa-3x fa-fw\"></i>' };\n}\n\nif (p == \"Off\") {\nvar msg3 = { payload:'<i class=\"fa fa-stop-circle-o fa-3x fa-fw\"></i>' };\n}\n\n//End Function and return two messages on two outputs\nreturn [msg1, msg2, msg3,];\n\n","outputs":3,"noerr":0,"x":490,"y":640,"wires":[["9fda007f.37ac4","9c9c07be.2df6a8"],["6add9bdb.1edc64"],["abf71e7c.4fb0c"]]},{"id":"9fda007f.37ac4","type":"debug","z":"6865126d.1bde1c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":600,"wires":[]},{"id":"9c9c07be.2df6a8","type":"file","z":"6865126d.1bde1c","name":"Log info to the file","filename":"/home/pi/logs/Tank_Pump_Run_Stats","appendNewline":true,"createDir":true,"overwriteFile":"false","x":790,"y":640,"wires":[[]]},{"id":"b6bf6503.a904d8","type":"comment","z":"6865126d.1bde1c","name":"Send MQTT to the Sonoff (ESPEasy)","info":"The ESPEasy firmware will echo back when it gets the command\nThats what we are looking for to then log to the file","x":530,"y":540,"wires":[]},{"id":"c48484b9.6be268","type":"ui_template","z":"6865126d.1bde1c","group":"c4fb7801.2972a8","name":"Water Tank Pump Status","order":0,"width":"10","height":"5","format":"<style>\n\n    #tex1 {\n        font-weight:bolder;\n        font-size: 12;\n        letter-spacing: 4px;\n        fill: white;\n    }\n    \n</style>\n\n\n<svg height=\"300\" width=\"400\" >\n\n<text id=\"tex1\" x=\"10\" y=\"30\" > {{msg.payload[0]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"50\" > {{msg.payload[1]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"70\" > {{msg.payload[2]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"90\" > {{msg.payload[3]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"110\" > {{msg.payload[4]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"130\" > {{msg.payload[5]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"150\" > {{msg.payload[6]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"170\" > {{msg.payload[7]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"190\" > {{msg.payload[8]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"210\" > {{msg.payload[9]}} </text>\n</svg>\n\n","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":1070,"y":680,"wires":[[]]},{"id":"6add9bdb.1edc64","type":"function","z":"6865126d.1bde1c","name":"Add word to scrolling table","func":"let pay = msg.payload;\n\n// Read scrolling table from context\nlet sctab = flow.get(\"sctab\");\n\n// Modify scrolling table by adding msg.payload as first element\nlet size = sctab.unshift(pay);\n\n// Remove last element from scrolling table\nif (size >9) sctab.pop();\n\n// Update context for scrolling text\nflow.set(\"sctab\",sctab);\n\n// Shalow copy updated scrolling table to msg.payload\nmsg.payload = [...sctab];\n\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":680,"wires":[["c48484b9.6be268"]]},{"id":"89d5b067.7701c","type":"inject","z":"6865126d.1bde1c","name":"","topic":"press","payload":"<i class=\"fa fa-refresh fa-spin fa-3x fa-fw\"></i>","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":570,"y":820,"wires":[["abf71e7c.4fb0c"]]},{"id":"abf71e7c.4fb0c","type":"ui_text","z":"6865126d.1bde1c","group":"c4fb7801.2972a8","order":1,"width":"1","height":"1","name":"Water Tank Pump Running Status","label":"","format":"{{msg.payload}}","layout":"row-center","x":840,"y":740,"wires":[]},{"id":"90919ebb.9e648","type":"inject","z":"6865126d.1bde1c","name":"","topic":"","payload":"<i class=\"fa fa-stop-circle-o fa-3x\" aria-hidden=\"true\"</i>","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":570,"y":780,"wires":[["abf71e7c.4fb0c"]]},{"id":"7b3f27b9.cb89d8","type":"inject","z":"6865126d.1bde1c","name":"Test for Output of Schedex node","topic":"","payload":"info","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":760,"wires":[["7d8236d1.3c4ac8"]]},{"id":"3c4dd8f5.c34618","type":"debug","z":"6865126d.1bde1c","name":"Schedex output","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","x":510,"y":440,"wires":[]},{"id":"e4b7f9a0.8f9b68","type":"ui_text","z":"6865126d.1bde1c","group":"c4fb7801.2972a8","order":0,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload.state}}","layout":"row-spread","x":750,"y":780,"wires":[]},{"id":"e2ed99fb.aa45d8","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c4fb7801.2972a8","type":"ui_group","z":"","name":"Status Messages","tab":"7ded32a1.cf8ccc","order":2,"disp":true,"width":"10","collapse":false},{"id":"7ded32a1.cf8ccc","type":"ui_tab","z":"","name":"Water Tank","icon":"","order":2}]

Both are only using basic features of each of the nodes

Craig

basic Javascript

if (var1 ==1 ) && (var2==1) {
var 3 = 1;
}
else {
(var3 =0);
}

regards

Craig

1 Like

And if you don't want to use a function node, use a couple switch nodes
sw1 - if (var1 = 1) true go to sw2 - default go and send a 0
sw2 - if (var2 = 1) send 1 - default send a 0

thank you

how I have to repost the flow
I'm not understand how I have to do to post the flow
(copy the flow in the clipboard "for export" and then... ?

thank you, may be this will help, I will try

If you read the link I posted in the first response it explains what you need to do and why you need to do it.

Try copying your flow from your post and try importing it into Node-RED (Import > Clipboard) you will find that it doesn't recognise it as a valid file.

yes I can see this, but sorry about, I don't understand the procedure, that I have to do, also I can not follow in the guide there is mention
please help me

wrap the code with ``` - three back-tick characters.

On an english (US) keyboard) that is the character below the ~ key next to the 1 key at the top of the keyboard

Craig

[{„id":"638487e4.8d98e8","type":"timerswitch","z":"9c52b872.61fc1","name":"Irrigation-Plan","ontopic":"","offtopic":"","onpayload":"true","offpayload":"false","disabled":false,"schedules":[{"on_h":"16","on_m":"16","on_s":"00","off_h":"21","off_m":"00","off_s":"00","valid":true}],"x":118,"y":162,"wires":[[]]},{"id":"e278d309.8e1f6","type":"ui_switch","z":"9c52b872.61fc1","name":"Automatik","label":"Zeitschaltung","group":"48fa5d97.39c614","order":1,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"Auto","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":103,"y":109,"wires":[["1f6e9bd.cf13ee4"]]},{"id":"c1b974bc.b0be08","type":"debug","z":"9c52b872.61fc1","name":"Automatik","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":770.5,"y":109,"wires":[]},{"id":"86a77438.16cc1","type":"function","z":"9c52b872.61fc1","name":"Auto","func":"var timerActive = flow.get('timerActive');\nvar timeOn = flow.get('timeOn');\n\n\n if(timerActive === 0 ) {\n msg.payload = 0;\n } \n else {\n if(timeOn === 1 ) {\n msg.payload = true;\n}\n}\n\n\t\n\treturn msg;\n","outputs":1,"noerr":0,"x":557.5,"y":109,"wires":[["c1b974bc.b0be08"]]},{"id":"1ac82da.b390dd2","type":"debug","z":"9c52b872.61fc1","name":"TimerON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":758,"y":151,"wires":[]},{"id":"3b4b2d57.b952aa","type":"debug","z":"9c52b872.61fc1","name":"Timer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":748.5,"y":193,"wires":[]},{"id":"856185e4.e35d6","type":"function","z":"9c52b872.61fc1","name":"Flow Set","func":"var newMsg = { payload: msg.payload};\nflow.set('timeOn',newMsg);\nreturn newMsg;","outputs":1,"noerr":0,"x":356,"y":156,"wires":[["86a77438.16cc1","3b4b2d57.b952aa"]]},{"id":"1f6e9bd.cf13ee4","type":"function","z":"9c52b872.61fc1","name":"Flow Set","func":"var newMsg = { payload: msg.payload};\nflow.set('timerActive',newMsg);\nreturn newMsg;","outputs":1,"noerr":0,"x":263,"y":109,"wires":[["86a77438.16cc1","1ac82da.b390dd2"]]},{"id":"7c2da188.e4c5e8","type":"inject","z":"9c52b872.61fc1","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":145.5,"y":214,"wires":[["856185e4.e35d6"]]},{"id":"48fa5d97.39c614","type":"ui_group","z":"","name":"Automation","tab":"4db4f194.142aa","order":1,"disp":true,"width":"6","collapse":false},{"id":"4db4f194.142aa","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order“:1}]

yes, on this script I was looking but get ERROR

var timerActive = flow.get('timerActive');
var timeOn = flow.get('timeOn');

if (timerActive === true ) && (timeOn === true) {
msg.payload = 1;
}
else {
msg.payload = 0;
}
return msg;

(2x identifier, operator, assignment) = SyntaxError: Unexpected token &&

regards
Max

In your if statement the brackets need to contain the entire condition you are testing for

see the && example here
https://www.w3schools.com/js/js_comparisons.asp

thank you

but something most be wrong, the in any case I get a 0

var timerActive = flow.get('timerActive');
var timeOn = flow.get('timeOn');

if (timerActive === true && timeOn === true) {
msg.payload = 1;
}
else {
msg.payload = 0;
}
return msg;

23.9.2018, 12:42:21node: Automatikmsg.payload : number

0

23.9.2018, 12:42:21node: TimerONmsg : Object

{ payload: false, _msgid: "f37e5644.a73298" }

23.9.2018, 12:42:24node: Automatikmsg.payload : number

0

23.9.2018, 12:42:24node: TimerONmsg : Object

{ payload: true, _msgid: "7f50f980.2015a8" }

23.9.2018, 12:42:30node: Automatikmsg.payload : number

0

23.9.2018, 12:42:30node: Timermsg : Object

{ payload: true, _msgid: "761f1233.8b5b1c" }

regards
Max

Insert after these lines something like

node.warn("timerActive is " + timerActive)
node.warn("timerOn is " + timeOn)

to see what those are set to. Those messages will be displayed in the debug tab.

23.9.2018, 12:58:53node: Autofunction : (warn)

"timerActive is [object Object]"

{"payload":true,"_msgid":"dee46967.6a0958"}

23.9.2018, 12:58:53node: Autofunction : (warn)

"timerOn is [object Object]"

{"payload":true,"_msgid":"6d29f3be.09a72c"}