Demo flow (use CTRL+I to import)
[{"id":"f6d053113d3d718b","type":"inject","z":"229f5611c9af1f6e","name":"increment","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"demo/machne/1/counter","x":1240,"y":480,"wires":[["169ba4e86618828b"]]},{"id":"418b0286e9dddacd","type":"mqtt in","z":"229f5611c9af1f6e","name":"","topic":"demo/machne/1/counter","qos":"1","datatype":"auto-detect","broker":"ac55cebb5e5db9e6","nl":false,"rap":true,"rh":0,"inputs":0,"x":1270,"y":300,"wires":[["0d663af1cef5a447","09fd3c4eb16599ca"]]},{"id":"c76759c6848062e7","type":"mqtt out","z":"229f5611c9af1f6e","name":"","topic":"","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ac55cebb5e5db9e6","x":1570,"y":480,"wires":[]},{"id":"169ba4e86618828b","type":"function","z":"229f5611c9af1f6e","name":"increment","func":"let v = context.get(\"value\") || 0\nv++\ncontext.set(\"value\", v)\nmsg.payload = v\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1400,"y":480,"wires":[["c76759c6848062e7"]]},{"id":"0d663af1cef5a447","type":"change","z":"229f5611c9af1f6e","name":"copy payload to currentCount","rules":[{"t":"set","p":"currentCount","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"tareCount","pt":"msg","to":"tareCount","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1540,"y":300,"wires":[["e760c9d133d185c9"]]},{"id":"553d4775cd053fa3","type":"inject","z":"229f5611c9af1f6e","name":"7:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 07 * * *","once":false,"onceDelay":0.1,"topic":"tare","payload":"0","payloadType":"num","x":1230,"y":360,"wires":[["4e65434010a72b43"]]},{"id":"4e65434010a72b43","type":"change","z":"229f5611c9af1f6e","name":"copy currentCount -> tareCount","rules":[{"t":"set","p":"tareCount","pt":"flow","to":"currentCount","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1450,"y":360,"wires":[[]]},{"id":"50f3691f74bccc6f","type":"debug","z":"229f5611c9af1f6e","name":"Tared","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1930,"y":300,"wires":[]},{"id":"e760c9d133d185c9","type":"function","z":"229f5611c9af1f6e","name":"deduct tare","func":"msg.payload = msg.payload - (msg.tareCount || 0)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1770,"y":300,"wires":[["50f3691f74bccc6f"]]},{"id":"a0fd31bbe09c0cea","type":"comment","z":"229f5611c9af1f6e","name":"test code (simulate value increasing)","info":"","x":1290,"y":440,"wires":[]},{"id":"09fd3c4eb16599ca","type":"debug","z":"229f5611c9af1f6e","name":"Input Data","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1490,"y":240,"wires":[]},{"id":"ac55cebb5e5db9e6","type":"mqtt-broker","name":"","broker":"broker.hivemq.com","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]