node red and js noob here. I am using the smartmeter node to read the current power consumption as well as the total. I'm doing so every few seconds in order to display an up to date value of the current power consumption.
For the total however I'm basically only interesset in the value at 23:59:59 every day which I want to insert into an InfluxDB. I tried a calculate node but it's to much data since I poll every few seconds.
How about these (I'll let you code it as I have no Node-RED on this machine to test with - blush):
Create two flow variables - one for the date and one for the value
Set the date to the current date and the value to zero
If the current date is not the same as the variable date - write the variable date and value to the database
Set the current date to todays date
Set the variable value to the new read value
OR
Check if a record for todays date exists - if not create one with a value of zero
Update todays date value with the current value (well it is a database after all)
Repeat from step one when the next read is done in both cases.
ALWAYS store the current date in a variable at the start of the flow when doing things like this - its a real pain to debug things (esp in others code) where the date changes partway through the process as they read the system date and it rolls over midnight...
One warning - think about your meter looping around - they have a horrible habit of doing this sometimes and even the 'professional billing' packages cannot cope some days (even with a fine from the ombudsman to help me get it sorted)! This leads to horrible daily used figure of -9999xx units day on day (and a rather large bill in my case).
I ended up using a 'time range' node, that allows to split output into two time windows. So i created a time window from 23:59:50 to 23:59:59 and only connect this output to the influxdb node.
One concern that spring to mind is that if you do not get a reading durning that time (network error, hardware glitch etc) then you get nothing for the day at all. By tracking it throughout the day you will get a close measure towards the end of the day...
(Yes - OTT risk adverse but I come from a 24*7 business)