Closed dgoodlad closed 5 months ago
I think I've worked it out: the extreme_now
calculation assumes that the list of prices includes the current price, which is not the case for the data from Amber.
Is it worth making this configurable?
I got it working by creating a template sensor which includes both the current and forecast values:
- name: Energy Prices
unique_id: energy_prices_template
state: "{{ states('sensor.home_electricity_general_price') }}"
attributes:
forecasts: >
{%- set forecasts_sensor = 'sensor.home_electricity_general_forecast' -%}
{%- set price_sensor = 'sensor.home_electricity_general_price' -%}
{%- set current = {"start_time": state_attr(price_sensor, 'start_time'), "per_kwh": state_attr(price_sensor, 'per_kwh')} -%}
{{ [current] + state_attr(forecasts_sensor, 'forecasts') }}
@TheFes I think the lowest-effort "fix" here would be to document that the current price must be in the sensor data. I'm going to leave this issue open while the underlying problem remains, even though I've fixed it for myself 😄
I think the problem is that you were using extreme_now
but the selected time period was not including the current time.
Let met look into this a bit further.
No, that doesn't seem to be the problem. Wait, now I understand your comment, I will fix this :)
Could you confirm it's fixed now?
Confirmed! I flipped my template's sensor
value back to the native forecast sensor from the Amber integration and it worked without crashing. Thank-you!
With this fixed, I've opened a PR to document the configuration for Amber in https://github.com/TheFes/cheapest-energy-hours/pull/143
I'm trying to use the data from the Amber Electric integration, but the macro throws an error that I can't seem to trace:
UndefinedError: No first item, sequence was empty.
.I'm calling it in the developer template editor like this:
The forecasts attribute of the sensor has data structured like this (sourced by printing
state_attr(sensor, 'forecasts')
):I've had a quick read of the macro, and it looks like it should be able to parse that correctly. I tested it using the code from https://github.com/TheFes/cheapest-energy-hours/blob/main/cheapest_energy_hours.jinja#L287-L295
and get
This is about the limit of my ability to debug Jinja templating, so would love some help or suggestions as to where to 👀 next.
Thanks!