Adding Greener Days sensors to Home Assistant

Using Intelligent Octopus from Octopus Energy tends to charge your Electic Vehicle at times when it’s “greenest” for the grid, which as well as saving you money is excellent for balancing the usage of energy across high demand appliances like your EV.

The problem is that currently there’s no real ability for Intelligent Octopus users to tell Octopus to only charge their car if it’s best for the grid on that night. Say you’re only using your EV for running errands for the next few days, you know you need to top up the battery at some point but you’re not fussed if that’s tonight, tomorrow or even the day after. Sure you can tell IO to only put a small amount of charge into your car each night, but if it’s going to be windy tomorrow instead of tonight and that wind power is going spare, then it’s best for cars to hold over a charge to the next day.

Octopus app Devices tab

Enter Greener Days

Greener Days is an initiative from Octopus which analyses the amount of green energy likely to be available each night and forecasts how “green” the UK grid will be through the night and into the next day.

Greener Days on the Octopus Energy website

Each day is ranked by its “greeness index” and appears as a colour, from red meaning bad to green meaning best and days with an excess of green energy are crowned to highlight them as the best days to charge or consume more electricity ( such as charging home batteries ). Using this data to decide which night to charge is not only better for the grid, but also may earn you more Octopoints if you’re subscribed.

Note, each day refers to that night. This might seem a little strange but is essentially telling you which evening it’s best to plug in to charge overnight. This means that if “Thursday” is highlighted then it’s actually early Friday morning which is going to be the greenest.

Home Assistant

Home Assistant has support for sensors based on Greener Days data thanks to the amazing Octopus Energy integration by Dave Kendall. Using these sensors it’s possible to automate certain activities such as setting the charge level of your home batteries to a higher state of charge, or setting the EV to charge to a higher level / at all. The raw sensors are extremely useful as they are.

The two sensors available are:

Greenness Forecast Current Index, which provides a value from 0 to 100 based on how “green” the grid is currently.

Greeness Forecast Highlighted, which is a binary sensor showing that the current period would have been shown on the website as a crown, and is the greenest day to charge ( and may earn you Octopoints ).

Octopus Energy Greeness Index attributes

What’s also useful is that the “current index” sensor also contains a bunch of attributes, one of which is the future forecast, and using this data we can present a forecast inside a Home Assistant dashboard:

Showing Octopus Greeness Index on a dashboard

I’ve built two sensors, one which provides an easy to read analysis of the best day to plug in, which can show if today or tomorrow is going to be greenest, or if not which day in the next three days is going to have the highest greeness index. If it’s not desperate to take on a charge then I can use this sensor to work out the best night to plug in.

The second sensor provides a forecast of the next 5 days, showing a day by day state of the greeness index, as Low, Medium, High or Greenest shown as L, M, H or G. The first letter is tonight, the next letter is tomorrow, and so on.

While there’s more optimal code, I’ve written these so they can work as regular Template Sensors within the UI, so no YAML! To create them, head to Settings > Devices > Helpers and then choose Create Helper from the bottom of the screen then Template then Template a sensor.

Creating a template sensor

There you can give the template a name, and in State Template, pase one of the following.

Important: Each sensor contains your account number, so the code below has my account number replaced with xxxyyy, so it’s best to copy this code into a text editor then replace xxxyyywith your account number.

Best day to charge

{% if state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[0].is_highlighted %}
Today is greenest
{% elif state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[1].is_highlighted %}
Tomorrow is greener
{% elif state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[0].greenness_index == 'HIGH' %}
Today is high
{% elif state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[1].greenness_index == 'HIGH' %}
Tomorrow is high
{% elif state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[2].greenness_index == 'HIGH' %}
Day after tomorrow is high
{% else %}
{{ "Today is " + state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[0].greenness_index.lower() + ", tomorrow is " + state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[1].greenness_index.lower() }}
{% endif %}

Greeness Forecast

{% if state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[0].is_highlighted %}
G
{% else %}
{{state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[0].greenness_index[:1]}}
{% endif %}
{{" "}}
{% if state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[1].is_highlighted %}
G
{% else %}
{{state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[1].greenness_index[:1]}}
{% endif %}
{{" "}}
{% if state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[2].is_highlighted %}
G
{% else %}
{{state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[2].greenness_index[:1]}}
{% endif %}
{{" "}}
{% if state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[3].is_highlighted %}
G
{% else %}
{{state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[3].greenness_index[:1]}}
{% endif %}
{{" "}}
{% if state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[4].is_highlighted %}
G
{% else %}
{{state_attr('sensor.octopus_energy_a_xxxyyy_greenness_forecast_current_index', 'forecast')[4].greenness_index[:1]}}
{% endif %}

Then, once you can created these sensors you can add them as entities to any dashboard.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *