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

No display :( #19

Open Fing086 opened 1 year ago

Fing086 commented 1 year ago

Well, im obviously doing something wrong but I have followed the instructions as far as I am aware, to the letter but when I reboot my Pi my Inkyphat screen just stays on its logo and nothing is happening!

The power/data light flashes for a good bit so I know the pi is doing something, but thats all I get.

Anyone else had this or can point me in a direction of how to test everything is installed correctly?

Only issue im getting is as follows:

python3 create_price_db.py

File "create_price_db.py", line 8 <!DOCTYPE html> ^ SyntaxError: invalid syntax

Thanks all

TinyBigJacko commented 1 year ago

Hiya @Fing086 - assuming your 'create_price_db.py' file is default, unchanged, line 8 is merely a comment and shouldn't generate any syntax errors. Have you modified this file at all? Perhaps it would be helpful to show us your file just to be sure nothing's crept in that shouldn't be there. With python, a misplaced tab or spurious comma anywhere in the file can make for hellish debugging! :)

Moreover, that file 'create_price_db.py' only needs running once, in order to create your SQLite prices database, which by default gets named octoprice.sqlite - can you confirm whether that exists or not? If you find it rename it to agileprices.sqlite - a change-request was introduced into the main script which altered the name of the database that was being looked-for, and this might well be your problem.

Alternatively, look at my fork of the code, and you'll see what's going on here - the database file needs to have the same name in create_price_db.py (line 5 ) octoprice_main_inky.py (line 28) and store_prices.py (lines 203, 211)

I do recall vaguely having some weird issues on at least one PiZeroW where it didn't create the database file in the correct directory location, which of course made everything fail to start later - so maybe check where yours has ended up, if indeed it has even been created. Again, you'll see in my fork, that I gave the database reference an explicit pathname to the file so all accesses of it were a known quantity! YMMV :)

Assuming you do have a correctly-named database in the right location where the other python scripts can find it, then your start-failure problem might be down to the cron jobs not starting? Did you set up your crontab? (see the Readme.MD file for that step)

Finally, I do recall that the main file 'octoprice_main_inky.py' won't actually do anything until the database file is created, but it's easy to miss the error message unless you're checking in SSH console via Putty or whatever. You actually have to run store_prices.py at least once prior to the main script, so there there are some prices in there for it to spit out during the half-hour refreshes during the day.

Hope this helps - let me know how you get on! It is worth having this running, imo. Even though I don't actually use the Agile tariff myself anymore (I'm on Octopus Go at the moment and have been since a couple of months after all the energy prices went nuts), I do like to keep an eye on what Agile is currently priced at, because there might come a time when it's safe to go back in the water, so to speak!

Fing086 commented 1 year ago

Hi, First of all thank you for your concise and thorough response, its very much appreciated. I decided to start again with a clean install, and went through both the instructions on site and also your updates. Everything seems to have worked and gone to plan with no errors in the installation or running of scripts etc.

At the moment my sticking point is the editing of the store_prices.py file.

In the instructions on site it simply says 'edit the top lines where you need to change the tariff code.' however, I cant seem to find anywhere to insert a code and also cant find the relevant code on my dashboard!

If you can point me in the direction of what line to edit and if you have a sample code I can use until I can find mine (Not bothered about what tariff its for, I just want to see it work) That would be great as at the moment im on the Inky Phat logo screen still :(

Thanks again D

Fing086 commented 1 year ago

Can anyone help with the above? I seem to be stuck at the very last hurdle!

TinyBigJacko commented 1 year ago

Hi again @Fing086 - sorry for the delay - I must have missed the notification about your reply.

OK, I'm guessing you're referring to the comment in the readme: Open store_prices.py (using nano or whatever) and edit the top lines where you need to change the tariff code. which is out of date now. It's similarly referred to on line7 in the main inky python script: https://github.com/pufferfish-tech/octopus-agile-pi-prices/blob/c02058204c95e0f7a22aa5f1320771dac327e2c4/octoprice_main_inky.py#L7

I think in earlier versions, we had to do this manually, and edit the store-prices script to create the 'Octopus API' fetch URL specific to our DNO region. Now, though, I think it's handled semi-automatically by the store-prices script, via the function here: https://github.com/pufferfish-tech/octopus-agile-pi-prices/blob/c02058204c95e0f7a22aa5f1320771dac327e2c4/store_prices.py#L170

If I remember right, you just invoke the store-prices script from the command prompt, with the DNO region as a commandline parameter (I think something like -r K would work (for south wales DNO, for example), but let me know if not. It's something like that. Remember you can invoke the store script with --help too, I think, and that will show you the region codes.

However - big caveat!

You'll have more issues with the fact that the original Agile tariff cited in these scripts is now defunct. I've got a little scraper set up in Node-Red, and that is telling me that today's most-recently available Agile based script is at

"https://api.octopus.energy/v1/products/AGILE-FLEX-BB-23-02-08/"

Interrogating that, I can see that to use that tariff, you'd have to change the humorously named lines here: https://github.com/pufferfish-tech/octopus-agile-pi-prices/blob/c02058204c95e0f7a22aa5f1320771dac327e2c4/store_prices.py#L17

to use:

AGILE_TARIFF_BASE = (
"https://api.octopus.energy/v1/products/AGILE-FLEX-BB-23-02-08/electricity-tariffs/E-1R-AGILE-FLEX-BB-23-02-08-')

instead.

There are other Agile tariffs on the Octopus system but without delving deeper I can't tell which ones are available now, and given that at the moment your investigation is academic, this one will probably do for now. But if you need an exact reference, either let me know, or have a dig on the main Octopus API website here: https://developer.octopus.energy/docs/api/#agile-octopus (though it will take a bit of effort to find historic tariffs, I think there is a method on there for finding current ones).

Hope this helps. Shout back if you need further assistance, though I can't promise I'll spot it immediately, evidently! Must get my github notifications sorted some day :)

Fing086 commented 1 year ago

Ok, that gets me a lot further than I was getting, the script now starts and looks for the tariff but then throws error:

Selected region K Requesting Agile prices from Octopus API... Connected to database... Database error: table prices has no column named valid_from

squaq200 commented 1 year ago

Hi @Fing086

I'm getting the same database error, did you (or has anyone else) manage to find a solution to this?

Fing086 commented 1 year ago

Unfortunately not, it seems octopus has changed the format in which it gives the data which is now incompatible with this software. It would be great if someone with more knowledge than I could update this and repost as the facility to see the prices would be extremely handy.

squaq200 commented 1 year ago

@Fing086 I've managed to get mine working. It wasn't a problem with the data format from Octopus, it was a problem with the agileprices.sqlite database. The prices table in the database didn't have a valid_from field, so I added this at the end (it's a text field). This allowed store_prices.py to populate the database and it's all working now.

Another thing to note, when running store_prices.py, I had to enter: python3 store_prices.py -r H with H being the DNO code.

Fing086 commented 1 year ago

Thats very interesting, any chance you can send me / upload the updated file(s) ? Or let me know what to add?

Glad you could get to the bottom of it :)

squaq200 commented 1 year ago

image

This is how it looked after I'd added the 'valid_from' field. Using https://sqlitebrowser.org/

Fing086 commented 1 year ago

Thanks, ill certainly take a look at that :) Hopefully I can work it all out.

mjeveritt commented 1 year ago

Unfortunately not, it seems octopus has changed the format in which it gives the data which is now incompatible with this software. It would be great if someone with more knowledge than I could update this and repost as the facility to see the prices would be extremely handy.

I'm watching this repository, but haven't quite got around to implementing my version of it, but noted the bugs posted here. I'll have a look at doing a few updates, and making a Pull-Request to get changes into the main repo, and you'll probably see my fork as soon as I've fixed it appear 'ahead' of this repo if it doesn't get merged... Watch this space! :eyes:

jerbzz commented 1 year ago

Hi all - I'm not sure that this repo is still active. I'm going to make PR which will fix the prices issue, which may or may not get merged, but you may perhaps find my similar project useful as well: https://github.com/jerbzz/pi-eco-indicator

jerbzz commented 1 year ago

Having looked into this a little, I'm not getting the same issue you guys are. Can you tell me a little more about your environments, specifically your Python version?

python --version

I get this error with the current version of this repo (fetched with git clone https://github.com/pufferfish-tech/octopus-agile-pi-prices), and the current version of Pimoroni's Inky pHat library, and Python 3.9.2...

Detected Yellow pHAT (SSD1608)
Traceback (most recent call last):
    File "/home/pi/octopus-agile-pi-prices/octoprice_main_inky.py", line 28, in <module>
        DB_URI = 'file:{}?mode=rw'.format(pathname2url('agileprices.sqlite'))
NameError: name 'pathname2url' is not defined

This is fixed by inserting from urrlib.request import pathname2url on line 19 of octoprice_main_inky.py and then the code works as expected for me.

pufferfish-tech commented 1 year ago

I'm still around if anyone has any PRs, I don't currently use this code so I can't offer a huge amount of assistance, I might be using it again in the near future though!

Fing086 commented 1 year ago

Im on Python 2.7.16 on my Pi if that helps any?

pufferfish-tech commented 1 year ago

you need python 3, I'm pretty sure.

Fing086 commented 1 year ago

I had tried Python 3 on a previous installation, I must have formatted and reinstalled a number of times, but had the same or similar issues. I'll give it another go whilst looking at some of the fixes above :)

squaq200 commented 1 year ago

Mine has python 2 and 3.

python --version gives 2.7.16 python3 --version gives 3.7.3

I'm using python 3

jerbzz commented 1 year ago

Database error: table prices has no column named valid_from

Was this the error you were getting @squaq200 ?

Fing086 commented 1 year ago

Yes thats correct

squaq200 commented 1 year ago

Was this the error you were getting @squaq200 ?

Yes, I added a valid_from field to the table and that fixed it