Monitoring Predbat Plan Generation Times in Home Assistant

Predbat from springfall2008 is a fantastic custom integration for Home Assistant that intelligently manages solar battery charging and discharging based on predicted solar generation and energy tariffs. It’s especially helpful for optimising when to charge from the grid or discharge to avoid peak tariffs, and it’s saved me a decent amount on my energy bill.

chart showing predbat on times

But like any planning tool, Predbat needs time to generate its plan. Most of the time it does this quickly – but occasionally it can take a little longer. I wanted a way to visualise and track how long Predbat was taking to generate its plan each time it ran.

Why track Predbat’s ON time?

The provided switch.predbat_active entity goes into the on state when Predbat is generating a new plan. Once complete, it switches back to off. By measuring how long it remains ON, I can catch cases where Predbat is taking longer than expected.

If it ever takes more than 5 minutes, I want to know – either through a notification or visually via my dashboard.

Step 1: Creating the Sensor

I used a trigger-based template sensor that calculates the duration in minutes that the switch.predbat_active was ON.

Here’s the YAML for the sensor:

- trigger:
    - platform: state
      entity_id: switch.predbat_active
      from: 'on'
      to: 'off'
  sensor:
    - name: Predbat Last ON Duration
      unique_id: predbat_last_on_duration
      state: >
        {{ (as_timestamp(now()) - as_timestamp(trigger.from_state.last_changed)) / 60 }}
      unit_of_measurement: "minutes"
      icon: mdi:timer

This sensor will only update when the switch turns OFF. It records how many minutes it was ON – which is effectively how long Predbat took to generate its plan.

Step 2: Visualising ON Durations in ApexCharts

To make this information more useful, I plotted it using the excellent ApexCharts card for Home Assistant.

Here’s the chart YAML I used:

type: custom:apexcharts-card
graph_span: 24h
header:
  show: true
  title: Predbat ON Durations
  show_states: true
  colorize_states: true
series:
  - entity: sensor.predbat_last_on_duration
    type: column
apex_config:
  yaxis:
    min: 0
    max: 6
  annotations:
    yaxis:
      - "y": 5
        borderColor: "#FF0000"
        strokeDashArray: 1

This renders a neat column chart of how long each plan generation took. The red annotation line at 5 minutes gives a clear visual cue if something is taking too long.

Notifications and Automations

Now that we have this entity, its a simple job to create a notification if the ON time is longer than my desired 5 minutes. Just use the new entity to trigger a notification to home assistant or your mobile device.