So with this as a starting block/point.
[{"id":"7259b305663811d4","type":"inject","z":"f838263ce79e696b","name":"Create attendance array","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"RESET","payloadType":"str","x":220,"y":300,"wires":[["b335992cc023d801","7d23bb2bbef09cf3"]]},{"id":"3debcbb5496f6fa6","type":"inject","z":"f838263ce79e696b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Andrew","payloadType":"str","x":180,"y":440,"wires":[["b64d03446caae4fb"]]},{"id":"dfeb03e0598f9afc","type":"inject","z":"f838263ce79e696b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Barney","payloadType":"str","x":180,"y":480,"wires":[["b64d03446caae4fb"]]},{"id":"16ec9f717ac04713","type":"inject","z":"f838263ce79e696b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Barry","payloadType":"str","x":180,"y":520,"wires":[["b64d03446caae4fb"]]},{"id":"6301dc94c94613ad","type":"inject","z":"f838263ce79e696b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Clive","payloadType":"str","x":180,"y":560,"wires":[["b64d03446caae4fb"]]},{"id":"0782f361710d99e1","type":"inject","z":"f838263ce79e696b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Colin","payloadType":"str","x":180,"y":600,"wires":[["b64d03446caae4fb"]]},{"id":"7d23bb2bbef09cf3","type":"function","z":"f838263ce79e696b","name":"try 2","func":"const name = msg.payload\n\nif (name == \"RESET\")\n{\n // Really a bit more to be done here.\n // But for now.\n flow.set('attendance',{});\n node.status({text:\"NEW DAY\"})\n return;\n}\n\n// Assuming the msg payload contains the name of someone entering\nconst attendance = flow.get('attendance') || {}\n\nlet now = new Date().toLocaleString()\n\nlet x = attendance[name]?.present\nif (x == undefined)\n{\n //\n node.status({text:\"IN\"})\n attendance[name] = { \"time\": now, \"present\": \"in\" }\n flow.set('attendance', attendance)\n}\nelse\n{\n //\n node.status({text:\"OUT\"})\n attendance[msg.payload] = { \"time\": now, \"present\": \"out\" }\n flow.set('attendance', attendance)\n}\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":440,"wires":[[]]}]
No foreign nodes.
I added a RESET
just to help in testing.
So, where I'm stuck.
Different node.
I need it to load the attendance
from the flow and make a list of all who have NOT signed out that day.
Again, I have NO IDEA what to do or even how to.
Hints?
EDIT
New code for the function
node:
Helps with keeping track of what's going on.
Maybe not too important, but ....
const name = msg.payload
if (name == "RESET")
{
// Really a bit more to be done here.
// But for now.
flow.set('attendance',{});
node.status({text:"NEW DAY"})
context.set("count",0)
context.set("ppl",0)
return;
}
let ppl = context.get("ppl") || 0
context.set("ppl", ppl)
let count = context.get("count") || 0
let text = ""
// Assuming the msg payload contains the name of someone entering
const attendance = flow.get('attendance') || {}
let now = new Date().toLocaleString()
let x = attendance[name]?.present
if (x == undefined)
{
//
//node.status({text:"IN"})
text = "IN"
ppl = ppl + 1
context.set("ppl", ppl)
count = count + 1
context.set("count", count)
attendance[name] = { "time": now, "present": "in" }
flow.set('attendance', attendance)
}
else
{
//
//node.status({text:"OUT"})
text = "OUT"
ppl = ppl - 1
context.set("ppl", ppl)
attendance[msg.payload] = { "time": now, "present": "out" }
flow.set('attendance', attendance)
}
node.status({text:ppl + " " + text + " " + count})