Charging Tesla with excess power from solar panels

After some head scratching and a lot of trial and error, I now have a working automation that starts the charge, increases amps as solar excess is available, reduces charge amps when power dips into import, and then stops the charge when there are no available amps.

Feel free to use, edit and critique the following automation:

alias: "*Tesla Solar Charging Automation"
description: ""
trigger:
  - platform: time_pattern
    seconds: /30
condition:
  - condition: and
    conditions:
      - condition: sun
        before: sunset
      - condition: sun
        after: sunrise
  - condition: state
    entity_id: device_tracker.nikita_location_tracker
    state: home
  - condition: state
    entity_id: binary_sensor.nikita_charger
    state: "on"
  - condition: template
    value_template: >
      {{ (states('number.nikita_charge_limit') | int -
      states('sensor.nikita_battery') | int) > 0.1 }}
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.solaredge_m1_ac_power
            above: 250
        sequence:
          - choose:
              - conditions:
                  - condition: state
                    entity_id: switch.nikita_charger
                    state: "off"
                sequence:
                  - target:
                      entity_id: switch.nikita_charger
                    action: switch.turn_on
                    data: {}
          - data:
              entity_id: number.nikita_charging_amps
              value: >
                {% set current_amps = states('number.nikita_charging_amps') |
                float %} {% set add_amps =
                (states('sensor.solaredge_m1_ac_power') | float / 236) |
                round(0, 'floor') %} {% set new_amps = current_amps + add_amps
                %} {{ [new_amps, 8] | min | float }}
            action: number.set_value
      - conditions:
          - condition: numeric_state
            entity_id: sensor.solaredge_m1_ac_power
            below: 0
        sequence:
          - choose:
              - conditions:
                  - condition: numeric_state
                    entity_id: number.nikita_charging_amps
                    above: 1
                sequence:
                  - data:
                      entity_id: number.nikita_charging_amps
                      value: >
                        {% set current_amps =
                        states('number.nikita_charging_amps') | float %} {% set
                        sub_amps = ((states('sensor.solaredge_m1_ac_power') |
                        float * -1) / 236) | round(0, 'floor') %} {% set
                        new_amps = current_amps - sub_amps %} {{ [new_amps, 1] |
                        max | float }}
                    action: number.set_value
              - conditions:
                  - condition: numeric_state
                    entity_id: number.nikita_charging_amps
                    below: 1.1
                sequence:
                  - target:
                      entity_id: switch.nikita_charger
                    action: switch.turn_off
                    data: {}
mode: single


So far it seems pretty quick to react to changes in solar output (clouds, other loads in the house etc), reliable, and robust.
Enjoy!