Seeking help monitoring kWh from smart plug and trigger other plug when reach certain limit

I have two Bluetti power stations which unfortunately do not integrate with HA. The power stations normally function as UPS, but I occasionally want to drain their batteries down. To do this, I was hoping to manually trigger an automation that turns off a first smart plug that stops charging the power station. A second plug on the output side of the power station then monitors the amount of kWh used by the load of the power station, and upon reaching a specific energy threshold (say 1.5 kWh), the first plug is triggered to turn back on and allow the power station to charge up again.

The smart plug does provide kWh monitoring, but it simply reports the total kWh that has passed through the plug since it was first plugged in.

I’m struggling in creating an automation that:
(1) is manually triggered;
(2) that then triggers a second event when a predetermined amount of energy has passed through the plug on the power station load side since the automation was triggered (e.g., upon start of the automation there has already been 3 kWh passed through the plug, and I want the automation to trigger another event after another 1.5 kWh has passed through the plug).

I presume such an automation would involve a utility meter helper. I created such a helper but it simply reports the total kWh since the helper went online.

Can someone point me in the right direction on how to do this?

Thanks,

You may want to take a look at the MeasureIt custom integration. That would allow you to set up a sensor that uses your utility meter as its source, but can be reset in your automation’s actions. It also allows you to set up a template condition within the sensor config.

With those things in mind I would do it as follows:

  1. Create an Input Boolean/Toggle Helper to act as your on/off switch for the draining sequence.
  2. Set up the MeasureIt sensor based on your utility meter with a template that checks that the Input boolean is on and the first plug is off, and reset set to “manual”.
  3. Create the automation:
triggers:
  - id: start
    trigger: state
    entity_id: input_boolean.battery_drain
    to: 'on'
    from: 'off'
  - id: finished
    trigger: numeric_state
    entity_id: sensor.measureit_battery_plug_2
    above: 1.5
  - id: finished
    trigger: state
    entity_id: input_boolean.battery_drain
    to: 'off'
    from: 'on'
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: start
        sequence:
          - action: switch.turn_off
            target:
              entity_id: switch.battery_plug_1
          - action: measureit.reset
            data: {}
            target:
              entity_id: sensor.measureit_battery_plug_2
      - conditions:
          - condition: trigger
            id: finished
        sequence:
          - action: switch.turn_on
            target:
              entity_id: switch.battery_plug_1
          - action: input_boolean.turn_off
            target:
              entity_id: input_boolean.battery_drain

For the manual trigger part, you can simply set the automation to trigger when the state of your first smart plug goes from on to off.

Add the smart plug to your dashboard, then you can simply click on it to toggle the power if you want manual control.