Reset accumulator feed at midnight via API?

It would be really useful to me to reset a generic accumulator feed at midnight.
Does anyone know if it’s possible to do this via cron and the API e.g.

Assuming I can replace the feed number correctly and generate unixtime

If anyone knows if I am barking up the wrong tree.
If not I guess trawling the source code for info to write a script being the only way??

Hi Daniel

Assuming this to be on the same setup you discuss on the [How to get correct kWh/W values from Pulse]
(How to get correct kWh/W values from Pulse - #18 by danielpugh) thread it would be easy to zero one or more feeds at midnight using cron, but you wouldn’t need to use any API calls.

Ad another line to the crontab

00 0 * * * /bin/bash -c 'echo -e "99 0\r" > /dev/tcp/localhost/50011'

(I’ve used node id 99 in the example but you can use any currently unused node id)

As you already have a [[cron]] socketinterfacer setup, if you run

printf "99 0\n" > /dev/tcp/localhost/50011

from the command line (assuming node 99 again) you should get a new input created in emoncms. In that new inputs processing just add
log to feed “feed1”
log to feed “feed2”
etc etc where feed1 and feed2 are the pre-existing feeds to be zeroed.

However this will not work reliably with fixed interval feeds if there is any chance of your regular inputs and processing changing any “zeroed” feeds before it is saved on it’s next occurrence of the interval. So best to avoid phpfina for these feeds.

All being well, at midnight the cron job will run sending a single zero to node 99 in emoncms via emonhub causing the processing to run and set all the defined feeds to zero regardless of whats happening in any parallel input processing for the same feeds.

That sounds perfect… I’m trying to reset a generic accumulator feed - wouldn’t an accumulator feed just take the value and increment that value?

I will experiment tomorrow.

Thanks and fingers crossed!


only if you use an “accumulator” process, if you “log to feed” the value directly you are not processing the value as such, just saving the value directly to the feed.

Fantastic - that sounds perfect!
Thank you very much - your cron is great - I love it!
Will try tomorrow

I couldn’t wait - tested and working perfectly so far
cron created and should run in 19 minutes
unfortunately I wont find out till tomorrow as need to sleep - fingers crossed and thanks again

ok it worked perfectly

this has raised several other ideas.
i am now thinking two accumulators
1 - resets daily for on-going daily costs
2. - no-reset which can be used for deltas e.g. last week, last month

it also means i can manually set an accumulator to match the meter and it should stay in sync in theory i assume.

thanks again - once again you have made my day!

one thing i have noticed is that if you reboot the pi the input is cleared
obviously this fixes itself at the next time interval, but in the meantime you get a flatline

my first thought was to add a startup script to set the current rate, but rc.local doesnt seem to execute (or maybe executes too quickly)

i thought i would ask to see you have any experience/ideas?

Yes, ideally you should log the input to a feed and use that rather than the input directly. This gives you a more robust operation and also a record of the changing status (tariff) for debugging or recreating new historical feeds etc.

If you use a phptmeseries feed that only updates 6 times per 24hrs, the space used by the additional feed(s) would be quite minimal.

you are a star!