Home assistant automation to discharge battery to grid

13 comments started 2023-10-26 last 2023-10-29
Home AutomationHome Assistant
M
#1 michaelmcgoldrick

Hi folks,

Id like to have an automation in home assistant that would run at 130am for 25 minutes and discharge the batter to the grid, but only if it's over a certain percentage.

Should be possible? I have home assistant and givetcp running.

Cheers
Mick

A
#2 anglefire

michaelmcgoldrick Yep, very possible. Just use an automation to trigger at a time and then have percentage limit otherwise it doesn't kick in. Then you have to tell the inverter to discharge, which is the action.
The, at the end of the time, you have another automation to put the inverter back to normal.

I haven't done it, and this may be too simplistic, but the principle is there.
The other way is to use something like predbat https://github.com/springfall2008/batpred/blob/main/README.md#predbat-install which will probably do it alot more elegantly by predicting your usage.

M
#3 michaelmcgoldrick

is it possible to set up a nightly discharge time - like say 1.30 to 1.59 (right before my night tariff kicks in) Then toggle that on/off with an automation that tuns at say 1.25 every night? also when doing a discharge will it also cover the house load? i.e. i don't want grid import at the same time.. the tariff i have between 2am and 5am is about 5p.. and i get paid about 24p for export (ireland).. i use about 1kw during the day hours (electric shower etc) where the inverter doesnt cover the load.. if i could export even 1.5kw that would pretty much cover the cost of my 1kw import.. the day tarrif is about 35p.. i also dont want to deplete my battery below 20% as ive 13.6 storage and can only 'get' 10.8 into the battery in the 3 hour tariff window.. days where i have any solar thats not a huge issue.. but if ive a dark day and only generate minor amounts i dont want the battery to deplete before 2am..

M
#4 michaelmcgoldrick

the other thing is i don't want the myenergy eddi using the power as i discharge it - can i set the eddi to 'stop' mode and will it still boost on its schedule?

M
#5 michaelmcgoldrick

question - whats the difference between the timed discharge and timed export settings on the givenergy portal?

G
#6 geoffreycoan

michaelmcgoldrick when doing a discharge will it also cover the house load? i.e. i don't want grid import at the same time

The inverter and battery can only import or export at one time, it can’t do both.

If you are discharging the battery at say 2.6kW, any house load will use that electricity and anything left over will be exported. If your house demand is higher than the inverter and battery can supply, say 4kW then the inverter will supply what it can and the balance will be imported.

You can schedule and automate precisely what you want in home assistant. I have similar scripts for my battery. We have Octopus power up events in our region, a few hours of free electricity when grid supply is higher than demand . My scripts stop the battery charging so any solar gets exported but the batteries will still discharge to meet house load, then just before the period starts they export anything remaining and force charge at 0p in the free period

T
#7 TheGasMan

geoffreycoan Hi - Do you know if there is any "idiot's guide" already available to help with setting up Home Assistant either on this forum or elsewhere? I would assume it's a commonly asked question.... (newbie here)

T
#8 TX200

TheGasMan best bet is look at you tube - speak to the geek

T
#9 TheGasMan

TX200 Thanks - I'll have a look

#10 Wonder Watt

Definitely doable with HA. You can also set both a charge and export schedule with our free service.

Mainly for people who like a fairly hands-off approach and don't want to mess with a Raspberry Pi and HA, as much fun as that can be. 😃

M
#11 michaelmcgoldrick

geoffreycoan would you be able to share some of your scripts?

G
#12 geoffreycoan

michaelmcgoldrick sure no problem

Here is a script that I call from an automation to force a discharge. It’s in a script just so I can run it any time I want or trigger it from an automation:

alias: G395 Inv2 Force Discharge
sequence:
  - service: select.select_option
    data:
      option: "00:00:00"
    target:
      entity_id: select.h_sd2237g395_discharge_start_time_slot_1
  - service: select.select_option
    target:
      entity_id:
        - select.h_sd2237g395_discharge_end_time_slot_1
    data:
      option: "23:59:00"
  - service: number.set_value
    data:
      value: "2600"
    target:
      entity_id: number.h_sd2237g395_battery_discharge_rate
  - service: number.set_value
    data:
      value: "4"
    target:
      entity_id: number.h_sd2237g395_battery_power_reserve
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: select.select_option
    target:
      entity_id:
        - select.h_sd2237g395_mode
    data:
      option: Timed Export
mode: single
icon: mdi:battery-minus-outline

I don’t have an automation that precisely matches what you want, but here’s one I use for Octopus power up events, it holds the battery from charging up in the morning (you won’t need that bit), at 1pm it checks if the battery has a charge and if it has it runs the above script to discharge it, and then at 2pm it starts a force charge, and finally 4pm it stops the charge and puts the inverter back to Eco mode
Should be enough to reuse

alias: G395 Inv2 Octopus Power Up
description: Don't let the battery charge in the morning, then force charge 2-4pm
trigger:
  - platform: time
    at:
      - "06:00"
      - "08:00"
      - "10:00"
      - "12:00"
    id: 2-hourly-stop-charging
  - platform: time
    at: "13:15:00"
    id: 1pm-check-if-discharge-required
    enabled: true
  - platform: time
    at:
      - "14:00"
      - "14:06"
    id: power-up-start
  - platform: time
    at: input_datetime.octopus_power_up_end_time
    id: power-up-end
condition:
  - condition: template
    value_template: >-
      {{ (now().date()) | string ==
      states('input_datetime.octopus_power_up_date') }}
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - 2-hourly-stop-charging
        sequence:
          - service: number.set_value
            data:
              value: "0"
            target:
              entity_id: number.h_sd2237g395_battery_charge_rate
      - conditions:
          - condition: trigger
            id:
              - 1pm-check-if-discharge-required
        sequence:
          - if:
              - condition: numeric_state
                entity_id: sensor.h_sd2237g395_soc
                above: 5
            then:
              - service: script.g395_inv2_force_discharge
                data: {}
      - conditions:
          - condition: trigger
            id:
              - power-up-start
        sequence:
          - service: select.select_option
            data:
              option: Normal
            target:
              entity_id:
                - select.h_sd2237g395_temp_pause_charge
          - service: select.select_option
            data:
              option: Eco
            target:
              entity_id: select.h_sd2237g395_mode
          - delay:
              hours: 0
              minutes: 0
              seconds: 30
              milliseconds: 0
          - service: number.set_value
            data:
              value: "2600"
            target:
              entity_id: number.h_sd2237g395_battery_charge_rate
          - service: select.select_option
            data:
              option: "120"
            target:
              entity_id:
                - select.h_sd2237g395_force_charge
          - service: homeassistant.turn_off
            data: {}
            target:
              entity_id:
                - switch.h_sd2237g395_enable_discharge
      - conditions:
          - condition: trigger
            id:
              - power-up-end
        sequence:
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
          - service: select.select_option
            data:
              option: Normal
            target:
              entity_id:
                - select.h_sd2237g395_force_charge
          - delay:
              hours: 0
              minutes: 0
              seconds: 30
              milliseconds: 0
          - service: select.select_option
            data:
              option: Eco
            target:
              entity_id: select.h_sd2237g395_mode
          - service: select.select_option
            data:
              option: "00:00:00"
            target:
              entity_id:
                - select.h_sd2237g395_charge_end_time_slot_1
                - select.h_sd2237g395_charge_start_time_slot_1
                - select.h_sd2237g395_discharge_start_time_slot_1
                - select.h_sd2237g395_discharge_end_time_slot_1
          - service: number.set_value
            data:
              value: "2000"
            target:
              entity_id: number.h_sd2237g395_battery_charge_rate
          - service: homeassistant.turn_on
            data: {}
            target:
              entity_id:
                - switch.h_sd2237g395_enable_discharge
mode: single
X
#13 XAPBob

I have set up a "Helper" device with the following template:

{{ (today_at("23:30") - now()).seconds / 3600 * 3.15 + 0.6 }}

That gives me a value of "how much energy would it take to discharge between now and 11:30 this evening, assuming I want 0.6kWh to remain...

Then I have an automation which triggers every 5 minutes

It confirms that the OI slot is off (i.e. I'm not currently in a cheap period)
It confirms that the battery is currently in "normal" mode
It then checks that the battery energy stored is greater than my helper:

condition: numeric_state
entity_id: sensor.givtcp_ce####g###_soc_kwh
above: sensor.energy_needed_for_full_discharge

And kicks off the force discharge.

I have another automation that resets the battery state at 11:30...