Export Trigger Automation

Post Reply
RyanMorgan
Posts: 16
Joined: Fri Oct 14, 2022 8:16 am

This is an automation I put together to monitor the current export price and if above a certain value (and a few other conditions), it trigger the inverter to export excess to the grid.
I am on the Agile Outgoing so whenever the prices is above 15p, I want to inverter to start exporting as a priority.
In the future, Fox are planning to enable the inverter to "force discharge" so I will be utilising this under this automation when that time comes.
This can also be adapted to monitor the import price and then perhaps force charge or enter backup mode when the price goes low (or even negative).

The basic steps are summarised as:
1) Ensure that the Octopus Energy integration is installed and working - specifically, ensure that you can see the "current rate" for either the export or import meter.
2) Ensure that the "FoxEss - Modbus" integration is installed and working - we will be using the work mode service to change the work mode.
3) Create a helper - this will be a simple drop down list named "Export Trigger Indicator" that shows either "Yes" or "No" (see image below) - this will be used to track whether the export sequence has been activated or not.
4) Create a new automation and copy and paste the code at the bottom of the page into the YAML section.
5) Tidy up the code to personalise it to your own sensors/helper/purpose.

Just to explain each stage of the automation...

Trigger

trigger:
- platform: state
entity_id:
- >-
sensor.octopus_energy_electricity_21j0016214_2100041763431_export_current_rate

This is a simple trigger that reacts every time the price changes. When the price changes, the automation then follows one of two paths.
Make sure you replace the entity_id here for your own.

---------------------------------

Condition

condition:
- condition: state
entity_id: select.energy_grid
state: peak

This is an optional part of this automation. I have simply added this to make sure this automation doesn't trigger overnight when I am charging my batteries with off-peak power.

--------------------------------

Action (If)

Each possible action basically checks two/three things...
1) Is the current rate above or below 15p?
2) Is the export trigger indicator on or off?
3) Is the battery SoC above 60% (only when the price rises above 15p)?


action:
- if:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.battery_soc
above: 60
- condition: numeric_state
entity_id: >-
sensor.octopus_energy_electricity_21j0016214_2100041763431_export_current_rate
above: 0.1499
- condition: state
entity_id: input_select.export_trigger_indicator
state: "Off"


For example, if the price changes and it climbes above 15p it will:
1) check to see whether the export trigger indicator is off - if it's on, then it's already in export mode and doesn't need to do anything.
2) checks to see if there is sufficient battery in reserve - I keep 60% minimum.
If the above checks out, then it triggers the action.

------------------------------------

Action

then:
- service: select.select_option
data:
option: Feed-in First
target:
entity_id: select.work_mode
- device_id: 0ba7653d0b53210fff0700994de25fa0
domain: mobile_app
type: notify
title: FoxESS
message: Export - Feed In Triggered
- service: input_select.select_option
data:
option: "On"
target:
entity_id: input_select.export_trigger_indicator

If the conditions are met above, then the automation sets out it's actions. Following the example above (price rises above 15p, there is plenty of batter and the export indicator is off)...
1) The first action is to switch the inverter to "Feed in" mode - the opposite will be to switch back to "Self Use" if the price drops below 15p.
2) The second is to notify my phone via the Home Assistant app that it's switched into Export Mode (and vice versa) - Make sure you replace the device_id here for your own.
3) Finally, the "Export Trigger Indicator" is switched to "On" - This will ensure that while the price is above 15p, the automation won't be triggered again.

----------------------------------

I hope this all makes sense .
While this is for export, you can easily adapt it for import by triggering on "import rate" and then using the call_service to set the MinSoC to 100% or set a charge window whenever the import price falls below a desired level, etc.
Remember to make sure the unique bits to you are updated like the "current rate" sensor and "device" for receiving notifications, etc.
The world's your oyster!

Code: Select all

alias: Export Trigger
description: ""
trigger:
  - platform: state
    entity_id:
      - >-
        sensor.octopus_energy_electricity_21j0016214_2100041763431_export_current_rate
condition:
  - condition: state
    entity_id: select.energy_grid
    state: peak
action:
  - if:
      - condition: and
        conditions:
          - condition: numeric_state
            entity_id: sensor.battery_soc
            above: 60
          - condition: numeric_state
            entity_id: >-
              sensor.octopus_energy_electricity_21j0016214_2100041763431_export_current_rate
            above: 0.1499
          - condition: state
            entity_id: input_select.export_trigger_indicator
            state: "Off"
    then:
      - service: select.select_option
        data:
          option: Feed-in First
        target:
          entity_id: select.work_mode
      - device_id: 0ba7653d0b53210fff0700994de25fa0
        domain: mobile_app
        type: notify
        title: FoxESS
        message: Export - Feed In Triggered
      - service: input_select.select_option
        data:
          option: "On"
        target:
          entity_id: input_select.export_trigger_indicator
  - if:
      - condition: and
        conditions:
          - condition: numeric_state
            entity_id: >-
              sensor.octopus_energy_electricity_21j0016214_2100041763431_export_current_rate
            below: 0.15
          - condition: state
            entity_id: input_select.export_trigger_indicator
            state: "On"
    then:
      - service: select.select_option
        data:
          option: Self Use
        target:
          entity_id: select.work_mode
      - device_id: 0ba7653d0b53210fff0700994de25fa0
        domain: mobile_app
        type: notify
        title: FoxESS
        message: Export - Self Use Restored
      - service: input_select.select_option
        data:
          option: "Off"
        target:
          entity_id: input_select.export_trigger_indicator
      - event: ""
        event_data: {}
mode: single

Image
Attachments
Export Indicator.png
Post Reply