-
Wise decision. I just don't get why other people don't also go for the imo straight forward (central wired) way like home automation systems do, when they approach a self-made smart home project. Maybe I'm biased, but most people's idea of smart home seems to be "Wow, I can switch that bulky plug in socket with my phone", or they stick ugly wireless buttons next to their switches for their lights. I don't get it! That kind of esthetics just collides with my womans acceptance factor. If I start such a project, I'd need stuff to be seamlessly integrated and that means wired. Node-Red is sooo powerful for like exactly that and you'd think there are some existing how to do's or examples, but... Sorry for the rant.
-
I'm really, really interested in these 2 lines of code in that .ino file (firmata sketch?) you mentioned. Please share! Pretty please! That would have spared me many weeks trying to find a solution, before I was like screw it (like literally) and reverted back to that hardware based override I've described.
-
Yeah... huh... it's... blinking..... ¯_(ツ)_/¯
I've nothing connected to pin 13, so... no trouble for me. I use it to (make it blink) identify the Arduino to which the nodes are actually connected to, in case It gets wrecked again. Haven't really noticed before that it does that on startup. lol It does look kinda cool! Sorry... it's just such a non-issue for me.
-
Me neither. But at least they all connect to the right pins on the right one now, every time, like on every reboot. I always have some backup SD-cards in case things don't work again, because reimporting the arduino nodes from whole saved flows never works, or not entirely. I can tell you more if you want to.
-
Hmm... Guess that explains it! Although, I've tried an active one and it didn't work reliably. Maybe that thing was crap. (and yeah I've plugged that thingy into the socket).
-
Same. unbelievable somehow. I find markost 's response very interesting. I'm not good at coding though.
-
Not so much of a problem with the old arduino node version I've mentioned. It works fine on full deploy and everything. As soon as I update --> problem. That's why I still use the old one. Haven't really got the time to try, if I can get the new version to work the same way I succeeded with the old version in the first place, because with so many pins/nodes that's a lot of work. My first attempts failed and why change it when it "works", kinda. hmm....
-
I still have node red running on openhabian, because of the arduino node problem. I also had that "just click Discover moment" btw. facepalm lmao
Ok, here they are:
But I have to warn you. I never posted any code and all I know about javascript is the little I've learned in like middle school, because I was bored and didn't have friends, or should I say, they were more interested in makeup and stuff than I was. Anyways, my code in those function nodes may look alike that, so if you find mistakes you can keep them.
At first I couldn't get things working so I tried different approaches, which then led to different functionalities. Take a pick! Some don't output on push-down, only on release, which makes them unsuitable for continuous dimming, others however do. They all expect msg.payload true for pushbutton pushed, false for released, output likewise, everything else should pass trough. You can set the time frame for them all globally with a global.awaitRetouch (type number) else its 600 (milliseconds). The inner workings is pretty obvious, so it should be easy to adjust stuff like number of outputs. Have fun!
[{"id":"ba6d3fbf.d68c1","type":"subflow","name":"short long times","info":"","category":"","in":[{"x":140,"y":100,"wires":[{"id":"776fb18.b36efd"}]}],"out":[{"x":660,"y":100,"wires":[{"id":"776fb18.b36efd","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"776fb18.b36efd","type":"function","z":"ba6d3fbf.d68c1","name":"short long times","func":"clearTimeout(context.retouchTimer);\nmsg.timespushed = context.get(\"count\") || 0;\nif(msg.payload) context.set(\"count\", msg.timespushed +=1);\nelse if(msg.timespushed === 0) {\n msg.longpress = true;\n msg.timespushed = context.get(\"lastlongpress\");\n context.set(\"lastlongpress\", 0);\n return msg;\n}\ncontext.retouchTimer = setTimeout(function() {\n context.set(\"count\", 0);\n msg.longpress = msg.payload;\n if(msg.longpress) context.set(\"lastlongpress\", msg.timespushed);\n else{\n msg.payload = true;\n //node.send(msg); // send\n //msg.payload = false; // short released\n }\n node.send(msg, false);\n}, global.get(\"awaitRetouch\") || 600);\n","outputs":1,"noerr":0,"x":400,"y":100,"wires":[[]],"outputLabels":["short"],"icon":"node-red/timer.svg"},{"id":"51c4402.953584","type":"subflow","name":"doubleclick long","info":"","category":"","in":[{"x":160,"y":180,"wires":[{"id":"36f46f30.43663"}]}],"out":[{"x":980,"y":120,"wires":[{"id":"352d3c0d.36ab54","port":0}]},{"x":980,"y":180,"wires":[{"id":"352d3c0d.36ab54","port":1}]},{"x":980,"y":240,"wires":[{"id":"36f46f30.43663","port":1}]}],"env":[],"color":"#DDAA99","outputLabels":["single","double","long press released"]},{"id":"36f46f30.43663","type":"function","z":"51c4402.953584","name":"count","func":"const awaitRetouch = global.get(\"awaitRetouch\") || 600;\nconst now = new Date().getTime();\nif(msg.payload) {\n context.set(\"touched\", now);\n flow.set(\"times\", (flow.get(\"times\") || 0) +1);\n return [{reset: true}, null]; // my finger is on the button\n}else{\n msg.payload = true;\n if(now > context.get(\"touched\") + awaitRetouch) {\n flow.set(\"times\", 0);\n return [null, msg]; // pushed it looong\n }else{\n msg.delay = awaitRetouch;\n return [msg, null]; // pushed the button\n }\n}\n","outputs":2,"noerr":0,"x":310,"y":180,"wires":[["86f068be.134d18"],[]]},{"id":"352d3c0d.36ab54","type":"function","z":"51c4402.953584","name":"output","func":"delete msg.delay;\nconst out = flow.get(\"times\") > 1 ? [null, msg] : [msg, null];\nflow.set(\"times\", 0);\nreturn out;\n","outputs":2,"noerr":0,"x":740,"y":180,"wires":[[],[]]},{"id":"86f068be.134d18","type":"delay","z":"51c4402.953584","name":"","pauseType":"delayv","timeout":"600","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":540,"y":180,"wires":[["352d3c0d.36ab54"]]},{"id":"ff5195f9.b5d7e","type":"subflow","name":"multiclick long","info":"","category":"","in":[{"x":140,"y":160,"wires":[{"id":"7c6b1881.f94c8"}]}],"out":[{"x":900,"y":200,"wires":[{"id":"ab365874.0aefc8","port":1}]},{"x":900,"y":280,"wires":[{"id":"ab365874.0aefc8","port":2}]},{"x":900,"y":360,"wires":[{"id":"ab365874.0aefc8","port":3}]},{"x":900,"y":440,"wires":[{"id":"ab365874.0aefc8","port":4}]},{"x":1000,"y":100,"wires":[{"id":"ab365874.0aefc8","port":0}]}],"env":[],"color":"#DDAA99","outputLabels":["single","double","triple","more times","long press"]},{"id":"7c6b1881.f94c8","type":"function","z":"ff5195f9.b5d7e","name":"count","func":"msg.delay = global.get(\"awaitRetouch\") || 600;\nlet times = flow.get(\"times\") || 0;\nif(msg.payload && times < 4) flow.set(\"times\", times +=1); // if < number of outputs: increment\n// msg.timespushed = times;\nreturn times ? [[{reset: true}, msg], null] : [null, msg]; // if 0 long released\n","outputs":2,"noerr":0,"x":290,"y":160,"wires":[["e120ace8.2c4e8"],["ab365874.0aefc8"]]},{"id":"ab365874.0aefc8","type":"function","z":"ff5195f9.b5d7e","name":"output","func":"const out = [];\nconst index = msg.payload ? 0 : flow.get(\"times\");\nflow.set(\"times\", 0);\nif(index) msg.payload = true;\n// msg.longpress = !index;\ndelete msg.delay;\nout[index] = msg;\nreturn out;\n","outputs":5,"noerr":0,"x":710,"y":180,"wires":[[],[],[],[],[]]},{"id":"e120ace8.2c4e8","type":"delay","z":"ff5195f9.b5d7e","name":"","pauseType":"delayv","timeout":"600","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":140,"wires":[["ab365874.0aefc8"]]},{"id":"f4e04705.a4b84","type":"subflow","name":"short or long","info":"","category":"","in":[{"x":140,"y":160,"wires":[{"id":"7091f356.1403e4"}]}],"out":[{"x":480,"y":120,"wires":[{"id":"7091f356.1403e4","port":0}]},{"x":480,"y":200,"wires":[{"id":"7091f356.1403e4","port":1}]}],"env":[],"color":"#DDAA99","outputLabels":["short","long"]},{"id":"7091f356.1403e4","type":"function","z":"f4e04705.a4b84","name":"short or long","func":"const awaitRetouch = global.get(\"awaitRetouch\") || 600;\nconst now = new Date().getTime();\nif(msg.payload) context.set(\"touched\", now); // no output on touched\nelse{\n msg.payload = true;\n if(now > context.get(\"touched\") + awaitRetouch) return [null, msg] // long\n else return [msg, null]; // short\n}\n","outputs":2,"noerr":0,"x":290,"y":160,"wires":[[],[]]},{"id":"a574854b.81773","type":"subflow","name":"multicklick multilong","info":"","category":"","in":[{"x":180,"y":320,"wires":[{"id":"33fd466.8f3aaba"}]}],"out":[{"x":720,"y":80,"wires":[{"id":"38b80536.7064ba","port":0}]},{"x":720,"y":140,"wires":[{"id":"38b80536.7064ba","port":1}]},{"x":720,"y":200,"wires":[{"id":"38b80536.7064ba","port":2}]},{"x":720,"y":260,"wires":[{"id":"38b80536.7064ba","port":3}]},{"x":720,"y":380,"wires":[{"id":"38b80536.7064ba","port":4}]},{"x":720,"y":440,"wires":[{"id":"38b80536.7064ba","port":5}]},{"x":720,"y":500,"wires":[{"id":"38b80536.7064ba","port":6}]},{"x":720,"y":560,"wires":[{"id":"38b80536.7064ba","port":7}]}],"env":[],"color":"#DDAA99","outputLabels":["short 1x","short 2x","short 3x","short 4x","long 1x","long 2x","long 3x","long 4x"]},{"id":"33fd466.8f3aaba","type":"function","z":"a574854b.81773","name":"count","func":"clearTimeout(context.retouchTimer);\nif(msg.payload) flow.set(\"count\", (flow.get(\"count\") || 0) +1);\nelse if(flow.get(\"lastlongpress\")) return msg;\ncontext.retouchTimer = setTimeout(function() {\n node.send(msg, false);\n}, global.get(\"awaitRetouch\") || 600);\n","outputs":1,"noerr":0,"x":310,"y":320,"wires":[["38b80536.7064ba"]],"icon":"node-red/timer.svg"},{"id":"38b80536.7064ba","type":"function","z":"a574854b.81773","name":"output","func":"const maxcount = 4; // half the outputs, other half long press\nconst count = Math.min(flow.get(\"count\"), maxcount);\nflow.set(\"count\", 0);\nconst out = [];\nconst outputnumber = flow.get(\"lastlongpress\") || (msg.payload ? maxcount + count : count);\nif(outputnumber > maxcount) flow.set(\"lastlongpress\", msg.payload ? outputnumber : 0);\nelse msg.payload = true;\nout[outputnumber -1] = msg;\nreturn out;\n","outputs":8,"noerr":0,"x":490,"y":320,"wires":[[],[],[],[],[],[],[],[]],"icon":"node-red/switch.svg"},{"id":"4a9f2d8.38632d4","type":"subflow:a574854b.81773","z":"cf56d87c.939b8","name":"","env":[],"x":390,"y":620,"wires":[[],[],[],[],[],[],[],[]]},{"id":"350b25bc.d42aca","type":"subflow:f4e04705.a4b84","z":"cf56d87c.939b8","name":"","env":[],"x":370,"y":300,"wires":[[],[]]},{"id":"c7557adb.7fa498","type":"subflow:ff5195f9.b5d7e","z":"cf56d87c.939b8","name":"","env":[],"x":370,"y":480,"wires":[[],[],[],[],[]]},{"id":"153fa4ba.33f123","type":"subflow:51c4402.953584","z":"cf56d87c.939b8","name":"","env":[],"x":380,"y":380,"wires":[[],[],[]]},{"id":"b5b41a3d.c09f1","type":"subflow:ba6d3fbf.d68c1","z":"cf56d87c.939b8","name":"short + long times","env":[],"x":390,"y":760,"wires":[["606f19e5.e2a21"]]},{"id":"606f19e5.e2a21","type":"switch","z":"cf56d87c.939b8","name":"times pushed","property":"timespushed","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"gte","v":"3","vt":"num"}],"checkall":"false","repair":false,"outputs":3,"x":640,"y":760,"wires":[["4a84e4ce.a183e4"],["8faf506e.8d4b8"],["c47662f9.670988"]]},{"id":"4a84e4ce.a183e4","type":"switch","z":"cf56d87c.939b8","name":"long?","property":"longpress","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"false","repair":false,"outputs":2,"x":840,"y":720,"wires":[[],[]]},{"id":"8faf506e.8d4b8","type":"switch","z":"cf56d87c.939b8","name":"long?","property":"longpress","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"false","repair":false,"outputs":2,"x":840,"y":760,"wires":[[],[]]},{"id":"c47662f9.670988","type":"switch","z":"cf56d87c.939b8","name":"long?","property":"longpress","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"false","repair":false,"outputs":2,"x":840,"y":800,"wires":[[],[]]}]