Constant errors in log with Wallbox car charging automation

Hello there!

After months banging my head against a wall (got to start somewhere) I have finally managed to write what I think is a good automation for my setup. Unfortunately it is spewing out errors I do not quite understand. I am hoping they are related to my shoddy work and not a less solvable problem (IE the fact I’m trying to control a cloud based service with less than perfect reception).

Here is my yaml file.

alias: Car Charging via Wallbox
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.power_surplus_for_car
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - variables:
      grid_usage: "{{ states('sensor.power_surplus_for_car') | float }}"
      max_charging_amps: 25
      min_charging_amps: 6
      grid_voltage: 240
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: template
                value_template: "{{ grid_usage > 0 }}"
              - condition: numeric_state
                entity_id: sensor.battery_soc
                above: 94
        sequence:
          - service: number.set_value
            target:
              entity_id: number.wallbox_portal_max_charging_current
            data:
              value: >
                {% set charger_power_draw =
                (states('number.wallbox_portal_max_charging_current') | int) *
                grid_voltage %}  {% set charging_amps = ((grid_usage +
                charger_power_draw) / grid_voltage) | round(0, 'floor') | int %}
                {{ [max_charging_amps, charging_amps] | min }}
          - type: turn_on
            device_id: dd9d56ea186f6428125c912832e9ad9c
            entity_id: 047f7ff3b13da53c4f688733685ea22c
            domain: switch
      - conditions:
          - condition: and
            conditions:
              - condition: template
                value_template: "{{ grid_usage <= 0 }}"
              - condition: numeric_state
                entity_id: sensor.battery_soc
                above: 94
        sequence:
          - service: number.set_value
            target:
              entity_id: number.wallbox_portal_max_charging_current
            data:
              value: >
                {% set deficit_watts = -1 * grid_usage %} {% set
                current_charging_amps =
                states('number.wallbox_portal_max_charging_current') | int %} {%
                set required_charging_amps = ((deficit_watts / grid_voltage) |
                round(0, 'ceil')) | int %} {% set updated_charging_amps =
                current_charging_amps - required_charging_amps %} {% if
                updated_charging_amps < min_charging_amps %} 5 {% else %} {{
                [max_charging_amps, updated_charging_amps] | min }} {% endif %}
          - if:
              - condition: numeric_state
                entity_id: number.wallbox_portal_max_charging_current
                below: 6
            then:
              - type: turn_off
                device_id: dd9d56ea186f6428125c912832e9ad9c
                entity_id: 047f7ff3b13da53c4f688733685ea22c
                domain: switch
      - conditions:
          - condition: numeric_state
            entity_id: sensor.battery_soc
            below: 95
        sequence:
          - type: turn_off
            device_id: dd9d56ea186f6428125c912832e9ad9c
            entity_id: 047f7ff3b13da53c4f688733685ea22c
            domain: switch
mode: single

The sensor sensor.power_surplus_for_car is definitely working as intended. The sensor sensor.battery_soc is the SoC of my off-grid home.

I swear it is working as intended half the time, but I am also getting a constant spew of the following two errors the rest of the time.

Logger: homeassistant.components.automation.new_automation_2
Source: components/automation/__init__.py:676
Integration: Automation (documentation, issues)
First occurred: 10:56:49 (14 occurrences)
Last logged: 11:05:51

Error while executing automation automation.new_automation_2:
Logger: homeassistant.components.automation.new_automation_2
Source: helpers/script.py:1783
Integration: Automation (documentation, issues)
First occurred: 10:56:49 (28 occurrences)
Last logged: 11:05:51

Car Charging via Wallbox: Choose at step 2: choice 3: Error executing script. Error for device at pos 1:
Car Charging via Wallbox: Error executing script. Error for choose at pos 2:
Car Charging via Wallbox: Choose at step 2: choice 1: Error executing script. Error for device at pos 2:

Interestingly the second error occurs exactly twice as much as the first…

After my brain falling apart working on this automation (while having no idea what I am doing) I have run out of capacity attempting to troubleshoot this so would love any suggestions.

Apologies for wasting anyone’s time!

Kindest regards.