Amber Electric (Australia) Custom Component

Congrats onthe bub! Just joined Amber and was excited to see your project for sensor data.

I too am getting failures, look forward to your update!

2020-07-21 13:56:10 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 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/amberelectric/sensor.py", line 45, in setup_platform
    AmberPricingSensor(amber_data, postcode, CONST_SOLARFIT, "Amber solar feed in tariff", "mdi:solar-power"),
  File "/config/custom_components/amberelectric/sensor.py", line 62, in __init__
    self.update()
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 239, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/amberelectric/sensor.py", line 157, in update
    self.amber_data = AmberData.from_dict(json.loads(response.text))
  File "/config/custom_components/amberelectric/ambermodel.py", line 433, in from_dict
    data = Data.from_dict(obj.get("data"))
  File "/config/custom_components/amberelectric/ambermodel.py", line 396, in from_dict
    VariablePricesAndRenewable.from_dict, obj.get("variablePricesAndRenewables")
  File "/config/custom_components/amberelectric/ambermodel.py", line 51, in from_list
    return [f(y) for y in x]
  File "/config/custom_components/amberelectric/ambermodel.py", line 51, in <listcomp>
    return [f(y) for y in x]
  File "/config/custom_components/amberelectric/ambermodel.py", line 315, in from_dict
    created_at = from_datetime(obj.get("createdAt"))
  File "/config/custom_components/amberelectric/ambermodel.py", line 41, in from_datetime
    return dateutil.parser.parse(x)
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 1374, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 646, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 725, in _parse
    l = _timelex.split(timestr)         # Splits the timestr into tokens
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 207, in split
    return list(cls(s))
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 76, in __init__
    '{itype}'.format(itype=instream.__class__.__name__))
TypeError: Parser must be a string or character stream, not NoneType

My pull request should resolve that issue mate: https://github.com/lewisbenge/hass-amber-electric/pull/9
Be great if you could test and confirm :slight_smile:

Congratulations on the bub Lewis.
:smiley:

Yep it did! Awesome, thanks. Will add it in and have a play shortly.

1 Like

All seems to be working fine although I have noticed I am pulling a different wholesale price comapred to my phone app - suspect because postcode is defaulting to CitiPower rather than Jemena in my area.

EDIT: as already meantioned by @boc

Hi Guys,

Iā€™m back in front of my PC this week. Iā€™ve approved the PR from @boc to fix the serialisation issues causing the crashes. Iā€™ve also see a bunch of issues raised in Github, so Iā€™ll work through them.

Note I donā€™t actually work for Amber, so Iā€™m working with the limitations of the API they have supplied. Unfortunately until they supply a personalized feed we may continue to see issues specific to the use cases.

Iā€™ll post again once Iā€™ve had a chance to get the tweaks in-place.

Thanks,
Lewis

2 Likes

Just had this up and running for a few days to check it out, awesome work. I have noticed that the integration appears to be running off UTC+1 (or -9 hours from current AEST). I.e current time is 18:54 but the sensor is showing last update as 09:53 (which is also the earliest lookback in the the actuals)

When looking at the actual and forecast price feed, it looks like the historical actuals go back 9 hours - when checking the historic actuals against the amber app you can easily align them (which is great) however they are out by one, i.e. the cost in the amber app for 18:00 is 27c, 17:30 is 28c, 17:00 is 24c. In the historic actuals they show as 18:30 is 27c, 18:00 is 28c, 17:30 is 24c. etc

I see there are a few comments that may be related and an open issue, so all good if this is a known issue and working on it, let me know if I can provide anything else to help?

Cheers,
Mike

Ok, so just realised I hadnā€™t localised my raspberry piā€¦ that sorted out some of the issues I was seeing. Iā€™m still seeing a offset issue with the forecast being off by 30 mins, i.e. app is saying now (19:30) 24c, 20:00 is 25c, 20:30 is 24c etc and HA sensor has forecast which matches at 20:00 is 24c, 20:30 at 25c, 21:00 at 24c etc - clearly offset by 1 period incorrectly, unless the sensor is showing ā€œup to that timeā€ whereas the app is showing ā€œfrom that timeā€? In which case they align perfectly. Am I just reading it wrong?

Hi, Iā€™ve completed the first steps of adding the components to my folder, and adding my postcode in config yaml, but Iā€™m hoping you could be kinda enough to help me achieve my main goal (or secondary goal if not)

All I want to initially do is be able to ask my google home (series of minis around my house, along with my phone) ā€œhey google, whatā€™s the price?ā€
And Iā€™m hoping it can just respond with ā€œthe current price is 23cā€ or something.

That way my family can quickly check if itā€™s time to turn on high power usage appliances like dishwashers, rather than having to open the app and find out (sounds like a pretty basic task but one that gets ignored!)

My secondary goal, whether than can be achieved or not, would be to have a toggle or something (IFTTT widget) on my Android phones maiN screen that lets me click to see the live price?

Going forwards, either an automated, or when prompted ā€œthe price is forecast to spike at $XX today at XXYYpmā€ would be a really cool goal for later down the track.

If all this is too tricky, would a simpler task of setting a price trigger to turn on a wifi power switch work? That way if the price goes above a pre-determined price, it could trigger a switch to turn on which would turn on a red led light in my living room to alert that power is expensive and dirty.

If I can contribute any way, Iā€™d love to help - the one thing I can possibly bring to the table is a direct contact with one of the founders of Amber :slight_smile:
Cheers

(should add, since this post, Iā€™ve been able to successfully link Google home to HA the dreaded manual way)

1 Like

Just to update: I have successfully integrated this component (the current price sensor) with Google Home, allowing me to ask any of my home minis ā€œhey google, power priceā€, and she responds ā€œthe current price is 17.25 centsā€.

Very happy this result, and will do perfectly until Amber get around to adding google home support. Bonus of having this component is that you can also add a widget on Android that shows the live price (with tap to update). Again, does what I need until Amber get around to adding widgets.

Anyone know how to switch the sensor to 5 minute rather than 30 minute intervals?

I think the actual data is only in 30min intervals, and the sensor by default checks every 15mins.
But the issue Iā€™m finding is that it will be 7:10pm, and itā€™s still showing the 6:30pm price.
This seems to be because there is 2 ā€œactualā€ prices? The Amber app price is always between 15-30mins ā€œaheadā€ of the price shown in the sensorā€¦

Amber does 5 minute updates from what I can see in their app so assume their feeds would provide the same. ambermodel.py references this also:

class PeriodSource(Enum):
    THE_30_MIN = "30MIN"
    THE_5_MIN = "5MIN"

This issue you are seeing is because I have put a throttle on the amount of calls to the Amber API. As this is not an official project for them, I didnā€™t want to have a default of a bunch of additional servers hitting their APIā€™s too frequently and causing downstream issues.

As such the the API refresh rate is controlled by a constant in the script:

SCAN_INTERVAL = timedelta(minutes=15)

You can reduce the number to make the API refresh more frequently, or remove the throttle on line 152 and it will poll at the standard intervals set by HA.

1 Like

Thanks Lewis.
Lots of price spikes last few days, and only realised yesterday that Amber set their app pushes to $3/kWh which is well above what I want alerts for. Using HA to alert via push notifications seems to be my best bet to control usage at the moment (will eventually send to Google Home for voice alerts) - although CitiPower and Jemena donā€™t align, it is at least close enough for some awareness.

Wouldnā€™t you either be Jemena or Citi? Either way, why not set your actual provider? Once I did this, the apps price has always been within 1c of HAs shown price (apologies if this isnā€™t what youā€™re talking about).

On another idea, Iā€™ve tested a changing colour light bulb, which I have in a corner of my main living area in a lamp (default green). When the price goes above 24.99c, it turns yellow, and over 50c it turns red. Iā€™m finding it very helpful in knowing when a spike happens - in combination of a HA price widget on my Android, and the good old ā€œhey google, (whatā€™s the) power priceā€

@Tuttle Yep, I am Jemena - but the only config option I am aware of is postcode which then defaults to CitiPower as the provider. Not sure if I missed something in docsā€¦

Like the bulb colour idea!! Might steal that.

I copied and pasted the latest community edit (by Madpilot) of the files, which includes the option to pick your provider, and also aligns the price correctly (before I updated these files, it was always showing me the price that was half an hour old compared with amber app)

Edit, Iā€™m new to all this, but using these edited files (#12), I copied and pasted the raw data over my data in the 2 files (didnā€™t bother with readme)

I think I also added network to my config.yaml

sensor:

  • platform: amberelectric
    postcode: ā€˜2000ā€™
    network: jemena
1 Like

Nice - this has worked for me too! Thanks.

1 Like

I have merged these PRā€™s into the main repository too. Apologies Iā€™m a little slack at the moment, still trying to figure the balance between work vs. a new baby vs. having time to spend on finishing my HA investments.

2 Likes