Amber Electric (Australia) Custom Component

OK I think I’ve found the issue. In the 48th value being returned by the Amber API they don’t set a value for createdDate or ForecastedDate which is what was causing the issue.

Could you please try updating your version with this file: hass-amber-electric/ambermodel.py at dev · lewisbenge/hass-amber-electric (github.com) and let me know if it fixes your issue. If it does, I’ll commit this change back into the main branch.

doesnt look to be fixed for me sorry mate.

I can get a result using 3031 as a Postcode. Are you able to share yours so I can see if it’s a similar issue please?

I am at 3140 - Ausnet

also got this if it is helpful:

2020-10-06 12:56:21 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up amberelectric platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 201, in _async_setup_platform await asyncio.gather(*pending) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 310, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 481, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 522, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 296, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state sstate = self.state File "/config/custom_components/amberelectric/sensor.py", line 100, in state return abs(self.calc_amber_price(self.amber_data.data.static_prices.b1.totalfixed_kwh_price, self.amber_data.data.static_prices.b1.loss_factor, current_price[0].wholesale_kwh_price)) IndexError: list index out of range

OK thanks - I’ll keep looking. I’ve just tried again with both postcodes and it seems to work on for me (14.39/4.8 kw/c) and (19.25/4.92kw/c). Just checking your restarted when using that new code to ensure it had loaded correctly?

I’m writing some testing scripts now to try and help me diagnose what’s going on with the geo specific responses.

Yes, I restarted.

Scratch all that: I didn’t correctly add the correct new data to the Ambermodel file

This is what I now get in my log:

Seems the same as before - are we sure that linked file you attached has the updated values?

Yeah, I just double checked and the changes are there.

Let me work on setting up the testing scripts, and if that still leads to nowhere I’ll just re-write the way I’m handling the JSON response

could it be a non-updated core or OS? (mines 0.114.0/4.12) Updating now to see if this makes a difference

A quick question on downloading your updated files, is there an easier and more clean way than going to RAW and copy pasting it it? I can’t remember how I use to do it?

ie: how can I download the 4 files in this link to do a clean “install” in my amberelectric folder?

Okay, I now have it working! But only if I delete network_provider: 'Jemena' in the config file.
If this is included, a valid check results in it being an invalid option.

Edit: Im so confused. That link you provided to the updated ambermodel.py file, the rest of the files in that link seem to be outdated? They don’t have things like network_name and timperiod =5 in the sensor file?

I think I’m now trying to mix and match different aged files.

Any chance you could provide a link to the current 4 files I need, so I can paste them in my folder from scratch?’

And now its showing as entity not found again, with the same list index outside range :frowning: didn’t touch anything this time…

If you go here, https://github.com/lewisbenge/hass-amber-electric and click on the drop down next to the green button you can download them as a ZIP. That’ll give you the new set of files.

The above asks on HACS if the preferred solution to solve this - but I don’t know much about it, so hoping if there is interest someone will submit a PR.

Looks like it is still erroring for me, just downloaded and rebooted mine.

`Logger: homeassistant.components.sensor
Source: custom_components/amberelectric/sensor.py:100
Integration: Sensor (documentation, issues)
First occurred: 4:04:21 PM (1 occurrences)
Last logged: 4:04:21 PM

Error while setting up amberelectric platform for sensor
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 201, in _async_setup_platform
await asyncio.gather(*pending)
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 310, in async_add_entities
await asyncio.gather(*tasks)
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 481, in _async_add_entity
await entity.add_to_platform_finish()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 522, in add_to_platform_finish
self.async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 296, in async_write_ha_state
self._async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 320, in _async_write_ha_state
sstate = self.state
File “/config/custom_components/amberelectric/sensor.py”, line 100, in state
return abs(self.calc_amber_price(self.amber_data.data.static_prices.b1.totalfixed_kwh_price, self.amber_data.data.static_prices.b1.loss_factor, current_price[0].wholesale_kwh_price))
IndexError: list index out of range`

But that looks like it then generates the same original error.

When I compare files between the ambermodel file you provided as the set of 4 above, and the modded filed you earlier provided, I can see differences (I just chose a line (252) and compared to see they’re certainly different) Here’s the link you provided earlier:

is there a way to download that file and use it to replace the set of 4 you provide in the zip?

In other words, I dont think the zip file pack contains your fix from a few hours ago.
And I can’t work out a way to download the above in corect format.
Right click-save link as downloads it in the wrong form (when opening and viewing it), and copy and pasting the RAW data doesn’t seem to be fixing the problem…

I’ve merged those changed back into the main repository now. So they should be available when you download the zip. If you look at the AmberModel.py file it should say updated 1hr ago.

1 Like

Okay, I completely replaced the 4 files in the folder on my HA, did a full restart, and back to getting the original error message

Lewis, if you don’t mind me asking, did you make further changes to the ambermodel file after you posted the single modified file yesterday?

When I compare that one with the new set of 4 you last posted, I can see they’re different around line 15? (Trying both of them and both are still returning “list index out of range”)

Keeping track of which 4 files I need is proving to be extremely tough!

I can get the prices working again if I use the sensor.py from 4 months ago (the current one from 2 months ago doesn’t work - with the rest of the “new” 3 files).
I think the issue lies in the sensor file and not the ambermodel file?

So the two issues are:
In the old sensor file (that works), the line:
self.calc_amber_price(self.amber_data.data.static_prices.e1.totalfixed_kwh_price,self.amber_data.data.static_prices.e1.loss_factor,self.current_prices[0].wholesale_kwh_price)

is now replaced by
self.calc_amber_price(self.amber_data.data.static_prices.e1.totalfixed_kwh_price, self.amber_data.data.static_prices.e1.loss_factor, current_price[0].wholesale_kwh_price)

I have tried using the newest Sensor.py file, and replaced just this and the solar line below it, which then gives me a live price/entity showing in HA.
It’s not the exact live price, but its ballpark.

But the second issue is that regardless of which form I use of the above, having network_name: 'Jemena' in my config file is causing invalidation when checked? Not sure how this is related.
Once I hashed this out, it lets it successfully validation check and works (but now I’m back to CitiPower). Is there anywhere I can edit in Jemena into any of the .py files?