Automation for wallbox charge control

Hello all,

I am trying to implement a charge control automation for my wallbox.
I have scripts that will turn the wallbox on and off as well as switch the charge current to 6A, 8A, 10A, 12A and 16A (2.7kw up to 7.2kw)
I can also read my current power consumption (or production as I have solar panels installed) as a sum value ("-" would be net surplus power, β€œ+” would be net additional consumption).
In order to automate the charge control, I have created several automations to adjust the charge current depending on the current surplus power in order to optimize utilization of the surplus produced by my solar panels.

Here is one example (created by the wizard) that automatically increases the charge to 8A if the total consumption is less than β€œ-780” Watts for 10 seconds (which is the delta between 6A and 8A). Wallbox Status code 11 means β€œCharging”.

alias: Auto_Wallbox_8A_up
description: Wallbox up 8A
trigger:
  - platform: numeric_state
    entity_id: sensor.consumption_total
    for:
      hours: 0
      minutes: 0
      seconds: 10
    below: -780
condition:
  - condition: state
    entity_id: sensor.wallbox_status_code
    state: "11"
  - condition: numeric_state
    entity_id: sensor.wallbox_current_l1
    above: 5
    below: 7
action:
  - service: script.alfen_wallbox_limit_8a
    data: {}
mode: single

Here an example that decreases the charge to 6A if the total consumption is more than 0 for 10 seconds and the wallbox is set to 8 (more precisely 7A and 9A):

alias: Auto_Wallbox_6A_down
description: Wallbox down to 6A
trigger:
  - platform: numeric_state
    entity_id: sensor.consumption_total
    for:
      hours: 0
      minutes: 0
      seconds: 10
    above: 0
condition:
  - condition: state
    entity_id: sensor.wallbox_status_code
    state: "11"
  - condition: numeric_state
    entity_id: sensor.wallbox_current_l1
    above: 7
    below: 9
action:
  - service: script.alfen_wallbox_limit_6a
    data: {}
mode: single

So basically I envision this to scale the charge up and down in steps if there is enough surplus or too much total consumption. (on 6A β†’ 8A β†’ 10A β†’ 12A β†’ 16A and 16A β†’ 12A β†’ 10A β†’ 8A β†’ 6A β†’ off)

The problem with all of them is that the triggers sometimes do not work - I suspect that is because as soon as the sun goes away and e.g. the current charge is set to e.g. 10A and my total consumption value jumps to e.g. 2000, then it will trigger the next step to 8A after 10 seconds, reducing the total consumption to about 1200 which is >0 (so the next step should trigger), but since it never crosses the 0 threshold defined in the next step to 6A, it will never trigger.

Does anyone have an idea for a solution for this?

Ok I have made the next step - I changed the trigger to activate every time there is an update to the total consumption sensor - in the below example - in essence it triggers with every update (2 sec.). The condition now includes the total consumption to be -780 and 6A as current.

alias: Auto_Wallbox_8A_up
description: Wallbox up to 8A
trigger:
  - platform: state
    entity_id:
      - sensor.consumption_total
condition:
  - condition: state
    entity_id: sensor.wallbox_status_code
    state: "11"
  - condition: numeric_state
    entity_id: sensor.wallbox_current_l1
    above: 5
    below: 7
  - condition: numeric_state
    entity_id: sensor.consumption_total
    below: -780
action:
  - service: script.alfen_wallbox_limit_8a
    data: {}
mode: single

That seems to work, however I guess there is no way I can say β€œbelow -780 total consumption for more than 10 seconds” in the conditions?

Ok seems there is not much anyone could contribute, but with further research I was able to tie the update criteria to the last update of the sensor.wallbox_current_l1 sensor with:

  - condition: template
    value_template: >-
      {{

      (as_timestamp(now())-as_timestamp(states.sensor.wallbox_erik_current_l1.last_changed))

      < 5 }}

In essence, I can make sure that the last update of the sensor is less than 5 seconds ago - which makes sure that the condition is based on a recent sensor value - without it, the scripts use old values that are potentially more than 1 minute old - since the consumption values are updated every 5 seconds, the conditions only fire if the related conditions are just as recent.
Seems to work well :+1:

1 Like