Preventing excessive grid draw blowing grid supplier pole fuse

Here in Western Australia, it is winter and I am pulling peak power from the grid with little solar generation, so there’s a high risk of exceeding our grid draw limit (63A at 240v, or just above 15kW), particularly when the house battery (16kWh Sigenergy) is force charging in the midday low tariff period.

So I’ve just written an emergency automation which watches for excessive grid draw and progressively turn off EV charger (3.6kW dumb charger on BYD Dolphin using jkaberg’s integration), Aircon (2-4kW, Advantage Air integration) and HWS booster (2kW, Shelly 1EM integration), continuing turning off consumers until the total grid draw goes under 15kW.

I know it’s simple but might save someone some time. So here it is:

Preformatted text

alias: Grid draw alert on excessive grid power consumption
description: ''
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.grid_draw
    above: 15000
conditions: []
actions:
  - action: notify.mobile_app_iphone_14
    metadata: {}
    data:
      message: >-
        Grid power exceeding 15kW! Reducing load now! Turning off EV charging, AC and
        HWS booster for starters.
    enabled: true
  - if:
      - condition: numeric_state
        entity_id: sensor.grid_draw
        above: 15000
      - condition: numeric_state
        entity_id: sensor.dolphin_battery_power
        above: 1000
    then:
      - action: time.set_value
        metadata: {}
        target:
          entity_id: time.dolphin_end_time
        data:
          time: '09:01:00'
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - if:
      - condition: numeric_state
        entity_id: sensor.grid_draw
        above: 15000
      - condition: climate.is_hvac_mode
        target:
          entity_id: climate.ac
        options:
          for:
            hours: 0
            minutes: 0
            seconds: 10
          hvac_mode:
            - heat
            - cool
            - dry
    then:
      - action: climate.set_hvac_mode
        metadata: {}
        target:
          entity_id: climate.ac
        data:
          hvac_mode: fan_only
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - if:
      - condition: numeric_state
        entity_id: sensor.grid_draw
        above: 15000
      - condition: numeric_state
        entity_id: sensor.shellyem_485519d733db_channel_1_power
        above: 1000
    then:
      - action: switch.turn_off
        metadata: {}
        target:
          entity_id: switch.pv_power_in_hws_booster_switch
        data: {}
mode: single