heraldb / heatpump-logger

Logs data from Alpha Innotec heatpump to file and to Domoticz
Apache License 2.0
0 stars 0 forks source link

IndexError: list index out of range #1

Open Stelvio76 opened 1 year ago

Stelvio76 commented 1 year ago

Hello,

I'm busy with the scritpt for my Alpha Innotec heatpump.

When i run the Pythonscript i got this error. My experience with Python is basics. Anybody an idea?

Traceback (most recent call last): File "/home/pi/heatpump-logger.py", line 135, in values = parse_page(menu_status_id, pages['status']) File "/home/pi/heatpump-logger.py", line 108, in parse_page return parse_items(root, page) File "/home/pi/heatpump-logger.py", line 93, in parse_items item = items[n] IndexError: list index out of range

heraldb commented 1 year ago

Hi Stelvio, Nice to see you found this script.

What is happening on line 93 is that of "items" (= the items from the webpage of the heatpump) does not have a value at position "n", which means that one of the two values (or both values) are not as expected. I would suggest to insert a line above line 93, to get some debug information. e.g. print(items, n)

Maybe good to remember that the numbering is zero based, so e.g. the 7th item on the webpage corresponds to items[6].

Another thing you will probably run into is that my heatpump runs in dutch mode, which is why the code is checking the content on dutch words/titles. You will need to change that to the corresponding titles on the webpages of your heatpump.

Success!

Stelvio76 commented 1 year ago

Hello Herald,

Thanks for your reply! I'm dutch as well by the way. :) So my pump is in dutch too,

I add the print command like you suggested and i got this return.

[<Element 'item' at 0xb5ef3b90>, <Element 'item' at 0xb5ef3c58>, <Element 'item' at 0xb5ef3ca8>, <Element 'item' at 0xb5ef3e60>, <Element 'item' at 0xb5ef39b0>] 5

Looks like n=5 but can't find where i can set the array size.
Hope you can help me further. Thanks in advance.

heraldb commented 1 year ago

Hi Stelvio,

Ah, this output shows that the webpage has 5 items (index numbers from 0 to 4). With n=5 it would try to get the 6th item on the page, which is does not exist.

Best thing to do is to check the web pages of your heatpump and check if they reflect what is specified in the pages dictionary (line 33 - 57). Clearly this needs correction for at least one page.

heraldb commented 1 year ago

Hi Stelvio,

Maybe also helpful: replace the debug line you added by this one:

print(n, label, [item[0].text for item in items])

In my case, I see a line like this

0 Verwarmen ['Verwarmen', 'Warmwater', 'Gezamelijk', '2e warm.opwek', 'vanaf : 27. 1.2022', 'sinds reset:']

Note that n and label are specified in the pages dictionary and the array that is printed is showing the fields from the web page. So if in the printed array the label is at another position than (in this case) 0, you know you need to change the number (field number on page) in the pages dictionary on line 33-57.

I hope this all is clear. In case it does not work out for you: I might consider to write a configuration helper script.

Stelvio76 commented 1 year ago

Hello Herold,

Sorry to bother you again. :) I got this return 5 Bedrijfstoestand ['Warmtepomp Type', 'Softwareversie', 'Bivalente trap', 'Bedrijfstoestand', 'Vermogen']

It's the 'Installatiestatus' menu and yours is the ' energie' menu.

I played around with the pages dictionary n numbers but got this

0 Aanvoer ['Aanvoer', 'Retour', 'Retour berekend', 'Heetgas', 'Buitentemperatuur', 'Tapwater gemeten', 'Tapwater ingesteld', 'Bron-in', 'Bron-uit', 'Menggroep1-aanvoer', 'Menggr1-aanv.ingest.', 'Aanvoer max.', 'Zuiggasleiding VD', 'VD-verwarming', 'Oververhitting'] (<class 'urllib.error.HTTPError'>, <HTTPError 403: 'Forbidden'>, <traceback object at 0xb5df6328>) 1 Retour ['Aanvoer', 'Retour', 'Retour berekend', 'Heetgas', 'Buitentemperatuur', 'Tapwater gemeten', 'Tapwater ingesteld', 'Bron-in', 'Bron-uit', 'Menggroep1-aanvoer', 'Menggr1-aanv.ingest.', 'Aanvoer max.', 'Zuiggasleiding VD', 'VD-verwarming', 'Oververhitting'] (<class 'urllib.error.HTTPError'>, <HTTPError 403: 'Forbidden'>, <traceback object at 0xb5df6348>) 2 Retour berekend ['Aanvoer', 'Retour', 'Retour berekend', 'Heetgas', 'Buitentemperatuur', 'Tapwater gemeten', 'Tapwater ingesteld', 'Bron-in', 'Bron-uit', 'Menggroep1-aanvoer', 'Menggr1-aanv.ingest.', 'Aanvoer max.', 'Zuiggasleiding VD', 'VD-verwarming', 'Oververhitting'] (<class 'urllib.error.HTTPError'>, <HTTPError 403: 'Forbidden'>, <traceback object at 0xb5df64c8>) 4 Buitentemperatuur ['Aanvoer', 'Retour', 'Retour berekend', 'Heetgas', 'Buitentemperatuur', 'Tapwater gemeten', 'Tapwater ingesteld', 'Bron-in', 'Bron-uit', 'Menggroep1-aanvoer', 'Menggr1-aanv.ingest.', 'Aanvoer max.', 'Zuiggasleiding VD', 'VD-verwarming', 'Oververhitting'] (<class 'urllib.error.HTTPError'>, <HTTPError 403: 'Forbidden'>, <traceback object at 0xb5dea168>) 5 Tapwater gemeten ['Aanvoer', 'Retour', 'Retour berekend', 'Heetgas', 'Buitentemperatuur', 'Tapwater gemeten', 'Tapwater ingesteld', 'Bron-in', 'Bron-uit', 'Menggroep1-aanvoer', 'Menggr1-aanv.ingest.', 'Aanvoer max.', 'Zuiggasleiding VD', 'VD-verwarming', 'Oververhitting'] (<class 'urllib.error.HTTPError'>, <HTTPError 403: 'Forbidden'>, <traceback object at 0xb5df64c8>) 7 Bron-in ['Aanvoer', 'Retour', 'Retour berekend', 'Heetgas', 'Buitentemperatuur', 'Tapwater gemeten', 'Tapwater ingesteld', 'Bron-in', 'Bron-uit', 'Menggroep1-aanvoer', 'Menggr1-aanv.ingest.', 'Aanvoer max.', 'Zuiggasleiding VD', 'VD-verwarming', 'Oververhitting'] (<class 'urllib.error.HTTPError'>, <HTTPError 403: 'Forbidden'>, <traceback object at 0xb5df6328>) 8 Bron-uit ['Aanvoer', 'Retour', 'Retour berekend', 'Heetgas', 'Buitentemperatuur', 'Tapwater gemeten', 'Tapwater ingesteld', 'Bron-in', 'Bron-uit', 'Menggroep1-aanvoer', 'Menggr1-aanv.ingest.', 'Aanvoer max.', 'Zuiggasleiding VD', 'VD-verwarming', 'Oververhitting'] (<class 'urllib.error.HTTPError'>, <HTTPError 403: 'Forbidden'>, <traceback object at 0xb5df6408>)

Stelvio76 commented 1 year ago

Where can i find the field numbers? I cannot find them in the HTML code in and advanced mode of the browser

Stelvio76 commented 1 year ago

Looks like i got it working! Solution was in the pages dictionary at 'Status' It's on position 3 and 4 on my webpage

Thanks for your help Herald!

heraldb commented 1 year ago

Ah, good to hear you succeeded in finding the right numbers and getting the script working!

Stelvio76 commented 1 year ago

Hello Herald, I don't know how to DM you so i put it here again. But i have a small easy question. Hopefully you don't mind. ;) I want to put the data in a specific database. How can i print 1 value only from the pages directory. For example the ' tapwater gemeten' temperature only. Thanks in advance.

heraldb commented 1 year ago

Hi Stelvio,

Indeed, Github does not offer a way to send DM's.

For this purpose I have created a temporary email address. If you send me a mail to QZWvaGkp@vdbreggen.com, I'll answer your question. BTW, any preference for type of database (sqlite, mariadb, postgresql)? You can write me in Dutch, if you like ;-)

Herald