Hello,
I currently have several automations in Home Assistant that will roll down the covers and awning, they however rely on a poll state node which monitors one of my outdoor sensors (wind and rain).
I would like to refine the logic a bit and have NR count to three before triggering the action. I'm very new to function nodes (as a matter of fact I've been avoiding them for months) but I came up with this:
var count = flow.get('count')||0;
count++;
msg.payload=count;
flow.set('count',count);
if (count>=3) {
msg.payload=count;
count=0;
flow.set('count',count);
return msg;
}
I think it works but I'm not happy with the looks of it. I'm sure it can be done more efficiently and nicely, specially with the condition "count>=3"; I had to give in and include ">" because at some point I notice count had gone beyond 3, and I was in a forever loop.
Many thanks in advance,