svenerbe / ecoflow_dynamic_power_adjustment

Service Description: EcoFlow Device API Integration for Power Stream Control
56 stars 6 forks source link

Feature request - Dynamically recharge Delta Pro battery #35

Open BeyondPixels opened 2 months ago

BeyondPixels commented 2 months ago

Hi there,

Sorry, it's a bit out of scope but I wanted to dynamically set the "AC Charging power" value of my Delta Pro based on another sensor (excess of solar, basically), a bit like you do with the PowerStream.

image

I've checked the doc and I can see this: image

...But I don't really know how I can use it the way you use "cmdCode": "WN511_SET_PERMANENT_WATTS_PACK" in your py script.

I thought it would be benefit others as well.

Thanks in advance!

EDIT: I've just realized the 2nd screenshot wasn't about setting charging rate but rather setting the max level of the battery.

For now, I use a HA automation which simply switches the smartplug on where the DP is when there is excess solar... And it stays charging at 1000W. I'm not sure how I can dynamically change this value effectively.

BeyondPixels commented 2 months ago

So to anyone interested, I figured out by configuring a few things in HA.

First of all, I created 2 automations that start charging the battery when my smart meter says I'm injecting. It's using a smart plug to do so. I've added conditions to avoid start the automation if the smart plug is already on or if the the battery is already above 75%

"alias: Ecoflow Delta Pro - Charges on electricity injection
description: Charges when injection is at least 400W for 2mn
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.dsmr_power_grid
    for:
      hours: 0
      minutes: 2
      seconds: 0
    below: -200
condition:
  - condition: device
    type: is_off
    device_id: f5981bb74ea46b6187ef9f25d4c9f055
    entity_id: 4f2e7591aa6759d4d3d1ab167cec76dc
    domain: switch
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - type: is_battery_level
    condition: device
    device_id: a7c0e93bdd4acb0bbdddf25f3890e58e
    entity_id: a6ffbebc9eab579ca2645a47447908be
    domain: sensor
    below: 75
action:
  - type: turn_on
    device_id: f5981bb74ea46b6187ef9f25d4c9f055
    entity_id: 4f2e7591aa6759d4d3d1ab167cec76dc
    domain: switch
mode: single
"

The other automation is to stop charging when there is no solar available for the battery. Here, I added a second trigger if the PowerStream is providing electricity to avoid charging and discharging at the same time.

"alias: Ecoflow Delta Pro - Discharges when no injection
description: Discharges when injection is less then 1W for 5mn
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.dsmr_power_grid
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: -1
  - type: power
    platform: device
    device_id: c17e17cb24472e2a1ff8411f71120984
    entity_id: 6ba9abd0c1f1a39e413166853b3e08c2
    domain: sensor
    above: 0
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition:
  - condition: device
    type: is_on
    device_id: f5981bb74ea46b6187ef9f25d4c9f055
    entity_id: 4f2e7591aa6759d4d3d1ab167cec76dc
    domain: switch
action:
  - type: turn_off
    device_id: f5981bb74ea46b6187ef9f25d4c9f055
    entity_id: 4f2e7591aa6759d4d3d1ab167cec76dc
    domain: switch
mode: single
"

Next, I created to 2 template sensors: The 1st one calculates the delta between the AC Charging power of the Delta Pro and the Power from the grid. The 2nd sensor is there to make it round (the step is by 100).

- platform: template
  sensors:
    ecoflow_delta_pro_ac_charging_power_dynamic:
      friendly_name: "Delta Pro - AC Charging power dynamic"
      unit_of_measurement: "W"
      value_template: "{{ (((states('number.delta_pro_ac_charging_power') | float) - (states('sensor.dsmr_power_grid') | float))) | round(0) }}"

    ecoflow_delta_pro_ac_charging_power_dynamic_hundred:
      friendly_name: "Delta Pro - AC Charging power dynamic hundred"
      unit_of_measurement: "W"
      value_template: "{{ ((states('sensor.ecoflow_delta_pro_ac_charging_power_dynamic') | float / 100) | round(0) * 100) }}"

The last thing I did is creating another automation that sets every minute the AC Charging power sensor to the right value. This one isn't pretty but it works.

alias: Ecoflow Delta Pro - Adjusts AC charge dynamically
description: ""
trigger:
  - platform: time_pattern
    minutes: /1
    enabled: true
condition: []
action:
    - if:
          - condition: device
            type: is_off
            device_id: f5981bb74ea46b6187ef9f25d4c9f055
            entity_id: 4f2e7591aa6759d4d3d1ab167cec76dc
            domain: switch
        then:
          - device_id: a7c0e93bdd4acb0bbdddf25f3890e58e
            domain: number
            entity_id: 387497207b9da1748656a36732fe9796
            type: set_value
            value: 200
        else:
          - if:
              - condition: numeric_state
                entity_id: sensor.ecoflow_delta_pro_ac_charging_power_dynamic_hundred
                below: 200
            then:
              - device_id: a7c0e93bdd4acb0bbdddf25f3890e58e
                domain: number
                entity_id: 387497207b9da1748656a36732fe9796
                type: set_value
                value: 200
          - if:
              - condition: numeric_state
                entity_id: sensor.ecoflow_delta_pro_ac_charging_power_dynamic_hundred
                below: 2901
                above: 199
            then:
              - target:
                  entity_id: number.delta_pro_ac_charging_power
                data:
                  value: >-
                    {{
                    states('sensor.ecoflow_delta_pro_ac_charging_power_dynamic_hundred')
                    | float }}
                action: number.set_value
          - if:
              - condition: numeric_state
                entity_id: sensor.ecoflow_delta_pro_ac_charging_power_dynamic_hundred
                above: 2900
            then:
              - device_id: a7c0e93bdd4acb0bbdddf25f3890e58e
                domain: number
                entity_id: 387497207b9da1748656a36732fe9796
                type: set_value
                value: 2900
mode: single