Cheapest Energy Hours - Jinja macro for dynamic energy prices

I’ve never seen a sensor reporting the values like this, so that’s why the macro doesn’t support it.

But why not use the core EnergyZero integration, and retrieve the prices using the template sensor blueprint?

Yes, I known there is an EnergyZero Core integration written by @klaasnicolaas, but I think he will run into the same ‘issue’ as I have now.
EnergyZero is also switched from hourprices to quarterprices at Jan 1st, 2026.
As far as I know the EnergyZero Core needs to be updated to show the quarterprices too and need to use the new API.

This is being worked on, the python package has already been adjusted, but the integration still needs to be updated.

Hi Klaas,
My REST API is working (electricity and gas), and I get the same results as you have in e.g. Comparing v4.0.1...v5.0.0 · klaasnicolaas/python-energyzero · GitHub

I also noticed that you have nested values?
Will this say that the macro written by TheFes can’t be used in the future?

The action provided by the integration doesn’t return the values like that. Maybe it’s reformatted before the response for the action is returned.

You could still use the template sensor, what is the entity_id of your current sensor which returns the attribute value like you posted above? And which attribute is it?

Wait, I already see it in the code you posted for the macro

template: 
  - sensor: 
      - unique_id: energy_zero_reformatted
        name: Energy Zero Prices 
        state: "{{ states('sensor.electricity_market_price_hour_price') }}"
        attributes: 
          prices: >
            {% set ns = namespace(prices=[]) %}
            {% for i in state_attr('sensor.electricity_market_price_hour_price', 'base') | default([], true) %}
              {% set ns.prices = ns.prices + [dict(start=i.start, price=i.price.value | float)] %}
            {% endfor %}
            {{ ns.prices }}

That should give you a sensor.energy_zero_prices which can be used with the macro

1 Like

It looks like it’s working the way I’d like it to.
I couldn’t have imagined how you designed that sensor attribute. Lack of knowledge.
I did have to add {{ ns.prices }} to the attribute, otherwise it wouldn’t work.
I’m very happy with this solution.
Thank you very much.

Yeah, forgot to output it :slight_smile:
Good catch

Thanks to your help and support, I’ve now fully switched from the old EnergyZero API to the new API to retrieve energy rates.

Thanks again for all your help, and now it’s time for a nice cup of coffee. :slight_smile:

1 Like