Hi,
I have a function with a basic counter that should count each time a door is opened. The door has a binary sensor so the counter only counts to 2 and then resets to 0.
The problem I have is the counter increments by 1 when the flow is deployed, even though the door isn’t opened (or closed).
I have a reset function that triggers when the sun goes down but it doesn’t seem to be changing flow.get("door_state_counter")
.
The script is in the “On Message” tab, but from the node.warn("Message: " + stringy)
line, it dumps a lot of messages on deployment.
node.warn("Door state counter: " + flow.get("door_state_counter"));
var stringy = new String
stringy = JSON.stringify(msg)
node.warn("Message: " + stringy)
var counter = flow.get("door_state_counter") || 0
counter ++
flow.set("door_state_counter", counter)
// convert counter output for 'join' node.
msg.topic = "counter";
msg.payload = counter;
return msg;
Any ideas and thanks in advance.
W.