pufferfish-tech / octopus-agile-pi-prices

Display the upcoming prices on the Octopus Energy "Agile" tariff.
Apache License 2.0
84 stars 27 forks source link

cron issue #4

Open Chiny91 opened 4 years ago

Chiny91 commented 4 years ago

Firstly, @pufferfish-tech said:

I must stress that I'm sharing this code for you to expand on, and while it is fully operational (I hope!) it doesn't come with the blessing of having been security audited nor is it supported by octopus energy. It is just something I wrote, that people asked me to share. /disclaimer.

Many thanks for your efforts, much appreciated. I'm not sure I could get my mind in Python around the inky pHAT display.

I had a problem getting the cron jobs to run. The problem was that I had tidied all the project files, into a project sub-directory /home/my_user/agile/, which broke the crontab. In short, the problem says here,

cron runs your command with cwd == $HOME.

It's nice to have individual projects separated in the user dir, into individual sub-dirs, saves much confusion. I fixed my installation by adding at the top of octoprice_main_inky.py:

# Change working directory; added by Chiny
import os
os.chdir("/home/my_user/agile")

Also, I provided the full path to commands in the crontab. Works fine.

Chiny91 commented 4 years ago

Forgot to add, do you have a referral code ? I've just signed up but Octopus still allow me to show my appreciation properly 😄

pufferfish-tech commented 4 years ago

Phew, I hope to get a day this week to catch up and fix the issues so far - good to see a few people using this now!

This looks like a documentation issue for the front page / readme on the face of it?

referral code: indeed I do - https://share.octopus.energy/rust-heron-863 - much appreciated too.

Cheers

Chiny91 commented 4 years ago

Your call re cron; doc addition good for me.

I've used your referral. Perhaps add that to your documentation 😄

Chiny91 commented 4 years ago

Hmm, I suppose that was asking for trouble. Today, the daily update ran as usual at 16:05 but the display continued to run out of graph bars. I inspected the sqlite DB but no update had occurred. I manually ran the store_prices.py from time to time but it did not update until around 19:00. At each check, I went back to this site, which had the same problem, so not a bug here.

Obviously without manual intervention, the system would fail. This is not wife friendly 😦

I think we need a new mechanism for checking that the price DB is properly updated at 16:05, and if not, repeat at intervals until it does.

plasma-tech commented 4 years ago

@Chiny91 - I've hacked the script to incorporate a simple retry method as I found the update was failing regularly.

I'm sure this could be made a lot better, but I'm a relative github/python noob so just learning as I go!

@pufferfish-tech - many thanks for sharing this great project!

pufferfish-tech commented 4 years ago

Guys, sorry I somehow missed this issue 8 days ago. I personally changed the cron to run twice to deal with this. A bit of a hack but if you set it to run again later at say 9pm or 10pm, it usually catches any days when the data was missing earlier.

I'll check your code - we're all noobs here, I'm not a python coder myself as it happens, if that wasn't evident from the code :) I skimmed your changes, you have it set to wait and try every 5 mins? I think it's a good idea but perhaps more like every hour - as the data can be very late sometimes on octopus' end. I think it can come in as late as 10-11pm sometimes. Perhaps that could be a flag / cron thing. I'm just wary of coding anything that polls the octopus API every 5 minutes. Probably not an issue but who knows, if we had 10000 people doing it, it might annoy them.

I'll add it to the list of things to look into. For the time being either your solution with a longer delay, or just add a later cron time into crontab, should sort this out.

plasma-tech commented 4 years ago

Yes maybe a bit too aggressive! 1 hour seems more sensible

Chiny91 commented 4 years ago

@plasma-tech said - I've hacked the script to incorporate a simple retry method as I found the update was failing regularly.

I've also had a couple of mystery update failures, in addition to the late prices from Octopus issue. Anyway, your hacked script has just worked fine on its first try.

Re cron, to avoid us all hammering Octopus every hour from 16:05, I've shifted the cron to 16:nn. No display update occurs until 16:30, so no change is noticed in practice. I've also added the conventional 2>&1 to the end of each crontab line, and for good measure, made the names of each cron log (reboot, daily, half-hourly) different, so perhaps make fault finding easier next time.

And... I've been coding since 1972 (Fortran IV), never professionally and I most certainly would not call myself a coder, still a Python newbie occasionally bodging scripts 😄