Amber Electric - Best Price Block

Amber is an Australian electricity retailer that provides access to wholesale electricity prices.

This script will tell you the best time to use your appliances. You can ask for either the cheapest or most expensive block of time, and it will tell you in how many hours that block will, and what the average price would be.

One fun application is with voice commands:

The YAML for the “Next cheapest power block” automation:

alias: "Sentence: Next cheapest power block"
description: Ask when the next cheapest block of time is.
trigger:
  - platform: conversation
    command:
      - "[What is |When is ]the [next] cheapest {hour} hour block"
condition: []
action:
  - service: script.best_power_price
    data:
      min_max: min
      entity_id: sensor.amber_general_forecast
      block_size: "{{ trigger.slots.hour }}"
    response_variable: response
  - set_conversation_response: |-
      {% if response.starts_in_hours == 0 -%}
        The cheapest {{ response.block_size }} hour block is now, with an average price of {{ response.cents_per_kwh }} cents per kilowatt hour.
      {% elif response.starts_in_hours == 0.5 %}
        The cheapest {{ response.block_size }} hour block starts in 30 minutes, with an average price of {{ response.cents_per_kwh }} cents per kilowatt hour.
      {% else %}
        The cheapest {{ response.block_size }} hour block starts in {{response.starts_in_hours}} hours, with an average price of {{ response.cents_per_kwh }} cents per kilowatt hour.
      {% endif %}
mode: single

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

You can install the integration here:

Open your Home Assistant instance and start setting up a new integration.

You will need to be an Amber customer to access the API required by the integration.

Not a customer? You can sign up here: https://join.amber.com.au/signup

2 Likes

Hey Myles,

Love the script, I have taken it and modified it so that it shows in a text box at the top of my dashboard so that i can see when the next best block is(not gone down the assist path yet) and by default i just leave it as 2 hours as that covers most appliances.

I defined a few helpers to hold the value of the output variables.


alias: test - best price
description: ""
trigger:
  - platform: time_pattern
    seconds: "00"
condition: []
action:
  - service: script.best_power_price
    metadata: {}
    data:
      block_size: 2
      min_max: min
      entity_id: sensor.general_forecast
    response_variable: response
    enabled: true
  - service: input_number.set_value
    target:
      entity_id: input_number.amber_low_cost
    data:
      value: "{{ response.cents_per_kwh }}"
  - service: input_datetime.set_datetime
    data:
      time: >-
        {% set t = as_timestamp(now()) + (response.starts_in_hours*3600) %} {{ t
        | as_datetime |as_timestamp | timestamp_custom('%H:%M') }}
    target:
      entity_id: input_datetime.amber_low_time
mode: single

Then my card looks like this


type: custom:mushroom-template-card
primary: 'Power Details '
secondary: ' The lowest power price will be at {{ states(''input_datetime.amber_low_time'') }} and cost {{ states(''input_number.amber_low_cost'')}}c'
icon: mdi:home

One update I am trying to get going but seems beyond my skills is could you define the best power price with in the next time window, say tell me the best price in the next 8 hours, or even tell me the best price before sunset or sunrise, this would be great if you need to time box something like if you want to run the washing overnight and want it done for when you wake up in the morning.

Cheers

Lachlan

1 Like

This looks like a very useful blueprint, but I’m getting “unknown error” when trying to import the blueprint.
Updated to latest OS and core. Still doesn’t work.
Tried importing another blueprint which worked fine, but still no success with this one.
Can you tell me what is wrong?

This is the log

Logger: homeassistant.components.websocket_api.http.connection
Source: components/blueprint/importer.py:168
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 19:28:46 (2 occurrences)
Last logged: 19:35:03

  • [547157884224] Error handling message: Unknown error (unknown_error) Ivan from fe80::83e7:219c:23cb:1ad9 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36)
  • [547267858624] Error handling message: Unknown error (unknown_error) Ivan from fe80::83e7:219c:23cb:1ad9 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36)

Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py”, line 27, in _handle_async_response await func(hass, connection, msg) File “/usr/src/homeassistant/homeassistant/components/blueprint/websocket_api.py”, line 77, in ws_import_blueprint imported_blueprint = await importer.fetch_blueprint_from_url(hass, msg[“url”]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/components/blueprint/importer.py”, line 257, in fetch_blueprint_from_url imported_bp = await func(hass, url) ^^^^^^^^^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/components/blueprint/importer.py”, line 168, in fetch_blueprint_from_github_url resp = await session.get(import_url, raise_for_status=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/local/lib/python3.12/site-packages/aiohttp/client.py”, line 696, in _request resp.raise_for_status() File “/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py”, line 1070, in raise_for_status raise ClientResponseError( aiohttp.client_exceptions.ClientResponseError: 404, message=‘Not Found’, url=URL(‘https://raw.githubusercontent.com/amberelectric/public-api/main/home-assistant/blueprints/cheapest_block.yaml’)

Whoops - I had the file name wrong.

Try https://raw.githubusercontent.com/amberelectric/public-api/main/home-assistant/blueprints/best_price.yaml

(I’ve updated the link above)

You know the response variable that is returned in the script is that the amount of “blocks” before the time that window is in, because mine keeps spitting out 13 hours away, which doesnt match up in app?

What other parameters are you passing in?

Sorry my apologies, looks like the forecast entity goes out further than the app shows you.

I’m going to try work in a way for it to exclude certain hours of the day eg 00:00-4:00 and 22:00-24:00

Also thanks for creating this I was trying to do something similar to schedule out my deferrable loads based on this :smiley:

@matt2468 Ah, yes it does.

Jinja2 templates are kind of terrible for this, but a cheat way of doing it would be to set the intervals you want to avoid to either 17 if you want to find the cheapest or -2 if you want to find the most expensive (those two numbers are guaranteed to be higher/lower than the max/min prices that can be returned).

Yeah they really are :sweat_smile: I was trying to get chatgpt to help create the template but it kept adding more and more and getting confused hahha, its just moreso I dont want certain appliances running say overnight or whatnot. If I get something working ill post in this thread in case anyone else need something similar

MadPilot - Thanks for this (and all your other work with Amber stuff).
I can call the script through the developer tools and get results. However, I’d like to set up an automation to run, at say midnight, and determine when to run the hot water heater for two hours.
Whilst I’ve setup quite a few automations, I’m not sure how to capture the results from the call and turn that into an automation.
Any pointers on getting started?

I’ve got the service working now using two automations to run our heat pump hotwater system for circa two hours a day at the projected best time. My approach is below. More than happy to take suggestions for improvements.
Step 1 - create a date/time helper to store the time to start the hot water heater. (time only) Mine is called ‘HotWaterPlannedHeatBlockStart’ - only has to be done once.

Step 2 - An daily automation that uses the service to get best 2 hr block and stores the planned start time in the helper variable. (the set_datetime has be be done in YAML)

Step 3 - An automation that starts and stops the heater (the heater is a ‘dumb’ unit so it is just powered down and only started once a day. It generally finishes in 2 hrs or less but I give it some buffer)

Nice one! Looks good to me.

I’d be interested to see how it performs!