Control Wallbox Max Current using home power absorbtion

Hello all,

I’m trying to compensate the Wallbox power consumption using a current control from Wallbox integration.
Originally I work on regulation based on Home Power Consumption to reduce using progressice if/then conditions nested (25-20-15 progressive reduction if above 6 Kw) then I was thinking to calculate it.
Since is the first time I try to set numbers based on formulas and I find several topics I try the following code:

alias: CARICA EV - Limita la corrente di carica in base consumo casa - Calcolo
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.casa_potenza_di_carico
    above: 6
condition:
  - condition: state
    entity_id: sensor.wallbox_pulsar_max_sn_604257_descrizione_dello_stato
    state: Charging
action:
  - service: number.set_value
    metadata: {}
    data:
      value:
        {{ ((6 - states(‘sensor.casa_potenza_di_carico’) | float / 230) | float + states(‘number.wallbox_pulsar_max_sn_604257_corrente_di_carica_massima’) | float }}
    target:
      entity_id: number.wallbox_pulsar_max_sn_604257_corrente_di_carica_massima
mode: single

This do not work since when I save it, the formula disappears.

  • sensor.casa_potenza_di_carico is the home power load measured from Tesla integration
  • wallbox_pulsar_max_sn_604257_corrente_di_carica_massima is the current max allowed for Wallbox and this can be set usign this parameter

Any idea where I make mistakes?

If you put it in the template editor you get an error at pos 16. Those are the quotes, which appear to be “smart” quotes. They look pretty, but are not the quotes they should be. This is always the first thing I turn off in the keyboard settings of IOS devices. You should also provide a default for the float filter. And then there is a mismatch in the number of braces.

Assuming dividing the 6 by 230 too is unlikely, it should be:

{{ (6 - states('sensor.casa_potenza_di_carico') | float(0) / 230) | float(0) + states('number.wallbox_pulsar_max_sn_604257_corrente_di_carica_massima') | float(0) }}

Thanks for the answer!
I try with your suggested changes (copy/paste the line on the formula), save the automation but if I open again it is changed with this (only second line was changed):

  value:
    "[object Object]": null

I’m pretty sure I did a mistakes but due to my limited skills on this matter I do not arrive to understand why… :neutral_face:

Maybe use the yaml mode and change the value template there?