Testing Home Assistant Automation - Octopus Free Energy Sessions

Today I had another free energy session I and thought I should be able to automated this with home assistant, now after some effort I got this automation “ALMOST” working - which is where I need your help…

I created the below automation and it is supposed to monitor an “EVENT” - but I think there is an issue within home assistant and the EVENT name is too long, I can’t even manually send an event - but if I create a fake one using a shorter name it works !!! - can someone have a look and see if it works for you.

alias: Octopus Free Electricity Session Automation
description: Automation to handle free electricity sessions from Octopus
triggers:
  - event_type: octopus_energy_a_**<your ID>**_octoplus_free_electricity_session_events
    trigger: event
conditions:
  - condition: template
    value_template: >-
      {{ trigger.event.data.events is defined and trigger.event.data.events |
      length > 0 }}
actions:
  - variables:
      last_event: "{{ trigger.event.data.events[-1] }}"
      last_event_code: "{{ last_event['code'] }}"
      last_event_start: "{{ last_event['start'] }}"
      last_event_end: "{{ last_event['end'] }}"
      last_duration: "{{ last_event['duration_in_minutes']|int }}"
  - action: notify.mobile_app_sm_m336b
    data:
      message: >
        Event code: {{ last_event_code }} Start: {{
        as_datetime(last_event_start) }} End: {{ last_event_end }} Full event:
        {{ last_event }} Wait-start: {{ last_event['start'] }} now: {{ now() |
        as_timestamp | timestamp_custom('%D:%Y:%H:%M') }} NewStart: {{
        last_event_start |  as_timestamp | timestamp_custom('%D:%Y:%H:%M') }}
        NewEnd: {{ last_event_end |  as_timestamp |
        timestamp_custom('%D:%Y:%H:%M') }}
      title: Test
  - wait_template: >-
      {{ now() | as_timestamp | timestamp_custom('%D:%Y:%H:%M') ==
      last_event_start | as_timestamp | timestamp_custom('%D:%Y:%H:%M') }}
    enabled: true
    timeout: "10:00:00"
  - device_id: f976c25a26ea549946a75649e24c6800
    domain: number
    entity_id: f47817041a56dc6309282f613f7c5cc5
    type: set_value
    value: 60
  - device_id: f976c25a26ea549946a75649e24c6800
    domain: button
    entity_id: ac26478a381fd8332914fc6917526b1a
    type: press
    enabled: true
  - wait_template: >-
      {{ now() | as_timestamp | timestamp_custom('%D:%Y:%H:%M') ==
      last_event_end | as_timestamp | timestamp_custom('%D:%Y:%H:%M') }}
    timeout: "10:00:00"
    continue_on_timeout: false
  - device_id: f976c25a26ea549946a75649e24c6800
    domain: button
    entity_id: 5f12a833bf12ee3c20cba58c78c7ceb4
    type: press
mode: single

1 Like

I can’t really help you with the automation as I’ve never tried using event triggers like this.

In my HA I see the Octopus events trigger on a very regular basis, for the free electricity, its every hour:

Am guessing that they trigger every time the integration polls Octopus because other events such as import rates trigger more frequently.

I use predbat which handles decoding the Octopus free electricity events, but before Predbat did this I used a REST service to get these details into HA, and its easy to trigger on when the times change:

See Free Electricity Sessions

PS: Don’t use device id’s in your automations, it makes them unreadable and not portable. Just select the entity id instead, you’ll get a readable name and not a string of numbers

1 Like

Am I going crazy then ? - I use predbat for all my solar stuff etc…

Is there an existing predbat entity I can use to just trigger my automation ? - does it just have an indicator saying “Free Electricity” ?

I have looked but can’t find anything ( intelligent charging slots ? ) - so any help would be great.

1 Like

Have a look at Energy rates - Predbat Documentation

You just configure a line in apps.yaml to point to your Octopus free electricity sensor and Predbat will automatically plan battery charging/discharging for the free electricity event. You can adjust the predicted load for the free sessions as well so if you plan to put the washing on etc

1 Like

I followed the instructions for the link you provided, and its a bit more complex to setup - but its all working now - so just wait for the next session now.

My automation just turns on my iBoost for now - and then i’m going to add in all my other things like Tumble dryer and Air conditioners etc..

I just want to use as much free power as I can handle ( I don’t have an EV yet - but that will 100% be the big hitter for free power )

I would be cool if you could get this integrated into predbat to make is simpler to use in further automations, but I am happy and predbat is am awesome bit of software,

1 Like

I started off with the whizzy.org REST API to create the free electricity sensor, and I then had my own scripts to push that into predbat.

Predbat will now auto detect the free electricity session if you set it up in apps.yaml, but at the moment doesn’t have a ‘free electricity session ongoing’ flag or similar. Could mimic the effect with an automation triggered with current import rate being zero, or use the whizzy API.

For me the free electricity sessions are generally of limited use when they occur during the day as I’m often generating so much solar that I am exporting not importing.

2 Likes

go here there are many more user whose collective brains you should be able to find a solution

1 Like

Here is an alternative way of detecting and controlling Free Electricity sessions.

1 Like

I have a python module that does somewhat more complicated analysis, if you are a code level sort of person.

1 Like

Free session tomorrow - lets see what happens.

1 Like

Predbat has picked the free session up automatically for me tomorrow, and although its planning to charge, in reality I expect I will be exporting not importing as I can only charge 2.4kW into the batteries each half hour and the solar forecast is for more than that.

I had a 2 hour powerup event today with similar results, looks like I imported nothing as PV generation was good

Geoff,

it’s great that there are so many ways to do the same thing :slight_smile: - I have an iBoost+ that has a “Feature” that even though when you select “Manual Boost” if is detects over 1kw return of solar it switches back to automatic, I just changed my automation to look at the costs per kWH and use that to control the iBoost ( and send some notifications ).

I also took to heart your suggestion to use the Entity_id :slight_smile:

Here is my really simple automation now that has a delay and loop so that my iboost+ works as I want, and now if does work I am also going to add additional tasks when Power-ups happen so that my AirCon comes on and will either heat or cool my house for free ( as why not just use the power when it’s free )

alias: Test Octopus Free Energy Sessions
description: ""
triggers:
  - trigger: numeric_state
    entity_id: predbat.rates
    below: 1
conditions: []
actions:
  - action: notify.mobile_app_sm_m336b
    data:
      message: |
        Low Rates Started: {{ states('predbat.rates') | float }}
      title: How much
  - target:
      entity_id: number.iboost_manual_boost_time
    data:
      value: 120
    action: number.set_value
  - target:
      entity_id: button.iboost_manual_boost_start
    action: button.press
  - target:
      entity_id: number.iboost_manual_boost_time
    data:
      value: 120
    action: number.set_value
  - repeat:
      until:
        - condition: template
          value_template: |
            {{ is_state('sensor.iboost_mode', 'Water Tank HOT')
               or (states('predbat.rates') | float > 1) }}
      sequence:
        - target:
            entity_id: button.iboost_manual_boost_start
          action: button.press
          data: {}
        - delay: "00:00:10"
  - wait_template: |
      {{ is_state('sensor.iboost_mode', 'Water Tank HOT')
         or (states('predbat.rates') | float > 1) }}
  - action: notify.mobile_app_sm_m336b
    data:
      message: |
        Low rate ending: {{ states('predbat.rates') | float }}
      title: Low Rates Stopped
  - target:
      entity_id: button.iboost_manual_boost_cancel
    action: button.press
mode: single

I am leaving the charging of the batteries etc… to predbat - this is just for all the stuff.