Amber Electric (Australia) Custom Component

How did you get this one setup for Google to tell you the current price?
I have google assistant hooked up manually, not through nabu.
But you can’t expose sensors to google assistant ?

Posting here because I’ve had a few people ask me to share my config.yaml to help them get this working. Hopefully thats OK :slight_smile:

sensor:
 - platform: amberelectric
   postcode: '3031'
   network_name: 'Jemena'

google_assistant:
  project_id: MYTESTAPPID
  service_account: !include /config/NAMEOFSAVEDFILE.json
  report_state: true
  expose_by_default: true
  exposed_domains:
    - switch
    - light
    - script
  entity_config:
    script.speak_power_rates:
      name: speak_power_rates
      room: kitchen
      expose: true
      aliases:
        - Power Rates
        - Power Price
script:
   speak_power_rates:
     alias: 'Speak power rates'
     sequence:
     - delay:
         seconds: 2
     - service: tts.google_say
       entity_id:
         - media_player.living_room_speaker
         - media_player.bedroom_speaker
         - media_player.bathroom_speaker
         - media_player.office_speaker 
       data_template:
         message: >-
           The power currently costs {{states('sensor.amber_general_usage_price')}} cents

# Text to speech
tts:
  - platform: google_translate
    service_name: google_say

# Example configuration.yaml entry
ifttt:
  key: MYIFTTKEY
1 Like

@lewisbenge any chance you could add this to HACS?

1 Like

Another issue, the prices are always positive.
currently amber are charging for export and grid power is close to free. (rare but definitely a thing)
The app reads -5cents for solar
The amber integration reads +5cents.


Unti5tled

1 Like

Hi, is yours or anyone else’s sensors/entities offline today? Noticed price hadn’t changed all morning, so restarted server, but now both sensors are showing as “Error entity not found”.
Haven’t touched config or any other yamls, and they have been working great since day 1…?

Yes, mine is also offline for ~9 hours.

1 Like

@boc I know it’s been ages - but I’m trying to build a library, and because I’m still waiting for a smart meter - can only partially see the data.
You pasted the output from UsageHub/GetUsageForHub but it’s been truncated.
If you still have the whole payload somewhere - are you able to put it in a pastebin or somewhere so I can see what a whole response looks like?
Thanks in advance - appreciate if you are too busy

Hey @troykelly, not sure I did paste something like that?

If you’re interested in the python script I used in the quoted post, it is:

:~$ cat test_amberelectric_api.py
import requests
import json

URL = "https://api.amberelectric.com.au/prices/listprices"

response = requests.post(URL, '{"postcode":"3012"}')

#print(response.content)

response = requests.post(URL, '{"postcode":"3012","networkProvider":"Jemena"}')

print(response.content)

Thanks @boc Ive got most of the protocol handling done already - I just have no idea what comes back for that request because we are still waiting to get connected.

I will wait until I get connected then get back to it (unless Amber sends me an example payload) :slight_smile:

@Jon_ctrl - do you mind sharing your config for Amber cards, like the style and detail!

Hi Tockers
The history graph is the mini graph card from HACS.
change out my sensors with yours.

config -

    entity: sensor.amber_general_usage_price
    name: Grid Price
  - color: '#fbc774'
    entity: sensor.amber_solar_feed_in_tariff
    name: Feed In
    show_state: true
  - aggregate_func: min
    color: gray
    entity: binary_sensor.night
    name: Night
    show fill: true
    show legend: false
    show_line: false
    show_points: false
    show_state: true
    smoothing: false
    y_axis: secondary
hours_to_show: 72
name: Power Price History
points_per_hour: 4
show:
  extrema: true
  labels: false
  labels_secondary: false
  smoothing: false
state_map:
  - label: Day
    value: 'off'
  - label: Night
    value: 'on'
type: 'custom:mini-graph-card'

You will need to create a night / day binary sensor in config.yaml with the following -

# Night Day Sensor
  - platform: tod
    name: Night
    after: sunset
    before: sunrise

the dual gauge card (also from HACS) config is -

colors:
  - color: var(--label-badge-green)
    value: 0
  - color: var(--label-badge-yellow)
    value: 20
  - color: var(--label-badge-red)
    value: 25
inner:
  colors:
    - color: var(--label-badge-green)
      value: 6
    - color: var(--label-badge-yellow)
      value: 2
    - color: var(--label-badge-red)
      value: 1.9
  entity: sensor.amber_solar_feed_in_tariff
  label: Export
  max: 20
  min: -20
  unit: c
outer:
  entity: sensor.amber_general_usage_price
  label: Grid
  max: 50
  min: 0
  unit: c
title: Price
type: 'custom:dual-gauge-card'

Have fun :slight_smile:
If you change anything post it up, lots of examples make everyones UI nicer to look at :slight_smile:

1 Like

So the API is still pulling live data for everyone else on here? So strange, can’t see why mine would fall over, unless it’s post code related (but the actual app is still showing correct data for my postcode?)

mine will often go out for hours or sometimes days then come back and be stable for ages.
it’s luck of the draw im afraid.
this is a fledgling project and is amazing, if not quite 100% yet.
damn close tho thanks to the amazing contributors :slight_smile:

Mine seems to have failed when yours did Tom. I’ve done an update and a few restarts with no change.

2020-10-05 08:35:18 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
1 Like

So after some experimenting, both line 100 (the solar one) AND line 97 (CONST_GENERALUSE) are throwing up “index out of range”.

If I delete the solar line (100) it then throws up the same error about line 97.

Line 97 looks like this:
return 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)

So what I can’t work out is what is causing an index out of range error.

I tried changing network provider, post code, removing each input element of that line, all of which had no effect after a server restart.

What did have effect was deleting BOTH lines 97 & 100.
This brought the sensor back on line.
But it provided an “unknown” current price. When clicked on, it did however still show accurate future prices in their 30min increments.

Can anyone work out what’s going on here, or even check their own line 97 and 100 and see if theres any differences? (not sure how that would be possible, as I refreshed to the latest updated files to ensure it wasnt a corrupted file at my end)

Thanks for any help!

It looks like the payload may have changed on Amber’s side. The code tries to deserialise the JSON file into an object to make it easier to pull out the parameters required. This seems to have caused non-stop issues since I published this plug-in, so I may need to re-write the code to traverse the JSON manually.

This however won’t fix things if Amber changes the API on their end.

I’ll try and take a look to see if I can resolve the issue in the current code-base, and then aim to re-write as soon as possible.

1 Like

Thanks for raising this. It is a casting error forcing value to be rounded to a positive. I’ll investigate it when I’m fixing the other more critical error.

2 Likes

Thanks for looking into this Lewis - what’s confusing me is why it appears to be affecting some of us, but others are certain their data is still arriving and is correct?
(On the whirlpool forum, it seems the majority don’t have this issue)
Hopefully a soon,urti on can be found, and if it is a change on Ambers side to the API, happy to raise it with them (the more information I can give them, the better)
Cheers again!

The payload returns differently based on energy supplier. We discovered this when I first published the component and it worked for me, but those in Victoria had issues. It’s likely we are now seeing similar issues. Unfortunately Amber haven’t supplied documentation for the API, so I’m coding against what I can see, and having to test in production with others.

2 Likes

That might be it - I’m with Jemena in Melbourne (3031). That’s why I tried defaulting back to CitiPower in the config, but that, and a post code change both didn’t help.

If all else fails, in the meantime it would be better to use the future half hour price. But obviously the actual live price would be ideal.