This might be a bit niche, but I know other people use Home Assistant, Predbat to automate their batteries, and are lucky enough to be in one of the Octopus Power-up postcodes.
The solution can easily be adapted for other energy providers that have special rate offers at certain times, but at the moment its written for the Octopus Power Up that gives zero pence import electricity for a period of time when supply is plentiful. e.g. we've got one tomorrow, 13/2, 8-10pm.
The problem is that Octopus don't provide an API to make the power up date and times available, they send you an email, you have to click a link and opt into the event, and then you have to program Predbat with the zero rate period - which is a pain needing a file editor to edit the predbat config apps.yaml file. I have an additional step to do as I have Home Assistant automations that swap the energy tariff in use so it doesn't count as charged electricity in my Energy dashboard, and I also turn on some electric heaters in outside workshops as the electricity is free for the period.
My solution combines the last two together, based on entering the date, start time and end time into Home Assistant entities, it then automatically writes the correct price rate override to Predbat's apps.yaml file.
Here's the bits of the solution:
Three helper date time entities in Home Assistant, octopus_power_up_date, octopus_power_up_start_time and octopus_power_up_end_time
A dashboard for the helper entities so you can see and change the power up date & times, and provide an 'add to predbat button' that invokes the unix shell command to add the times to predbat
- title: Powerup
path: powerup
icon: mdi:arrow-collapse-up
badges: []
cards:
- type: entities
entities:
- entity: input_datetime.octopus_power_up_date
- entity: input_datetime.octopus_power_up_start_time
- entity: input_datetime.octopus_power_up_end_time
- show_name: true
show_icon: false
type: button
tap_action:
action: call-service
service: shell_command.predbat_add_power_up_event
target: {}
name: Save Power Up event to Predbat
- A shell command adding to Home Assistant's configuration.yaml, this will pass the 3 entity values to a shell script when invoked by pressing the dashboard button:
# Shell command to update Predbat with Power up event
shell_command:
predbat_add_power_up_event: /bin/bash -c "/config/predbat_add_powerup_event.sh '{{ states("input_datetime.octopus_power_up_date")}}' '{{states("input_datetime.octopus_power_up_start_time")}}' '{{states("input_datetime.octopus_power_up_end_time")}}' >>/config/appdaemon/apps/batpred/config/apps.yaml"
(restart HA after adding this to configuration.yaml)
- A unix shell script called predbat_add_powerup_event.sh which is stored in the /config directory of Home Assistant:
echo " - date: '$1'"
echo " start: '$2'"
echo " end: '$3'"
echo " rate: 0"
echo " load_scaling: 3.0"
- You will have to make the above script executable, so open a ssh window and type the following commands:
cd /config
chmod +x predbat_add_powerup_event.sh
- Finally, the script works by appending the power up date and rates to the end of Predbat's apps.yaml file so you need to move the 'import_rates_override' section in apps.yaml to the end of the file so when the script runs it can simply append the new rate details onto the end of apps.yaml, Predbat will see the change and will automatically reload itself with the new rates detail.
e.g. end of my apps.yaml file containing a previous import_rates_override:
# Import rates can be overridden with rates_import_override
# Export rates can be overridden with rates_export_override
# Use the same format as above, but a date can be included if it just applies for a set day (e.g. Octopus power ups)
# This will override even the Octopus plugin rates if enabled
rates_import_override:
- date: '2024-02-09'
start: '12:00:00'
end: '15:00:00'
rate: 0
load_scaling: 3.0
And that's it. It looks complex but is fairly simple in what each job does in turn.
I'd call this the mark 1 script. Ideally I didn't want to have to have a bespoke unix shell script, but HA didn't like me writing yaml direct from a shell_command in configuration.yaml so it was a way to get it to work.
I'd also want to remove the restriction on having to have the import_rates_override at the end of apps.yaml and be able to insert the rate into the file regardless of how apps.yaml is sequenced. This needs use of sed or awk to insert part way through the file, something I haven't looked into yet.
Enjoy, hope it is useful to others














