Unexpected error for call_service: coroutine raised StopIteration

Hi all,
I have HA on a raspberry Pi and a UDI Polisy box.
I created a script to transfer the status of my UPS between HA and my Polisy.
I also have another script that transfers the UPS Battery Charge value to the Polisy.
The scripts are called every 10 seconds via an automation.
Every time the scripts run, I get an “Unexpected error for call_service at pos 2: coroutine raised StopIteration”.
Here are the scripts:

alias: UPS Status
sequence:
  - if:
      - condition: template
        value_template: "{{ 'Online' in states('sensor.cp1350avr_status') }}"
    then:
      - service: isy994.set_variable
        data:
          name: sUPSOnline
          value: 1
    else:
      - service: isy994.set_variable
        data:
          name: sUPSOnline
          value: 0
  - if:
      - condition: template
        value_template: "{{ 'On Battery' in states('sensor.cp1350avr_status') }}"
    then:
      - service: isy994.set_variable
        data:
          name: sUPSOnBattery
          value: 1
    else:
      - service: isy994.set_variable
        data:
          name: sUPSOnBattery
          value: 0
  - if:
      - condition: template
        value_template: "{{ 'Low Battery' in states('sensor.cp1350avr_status') }}"
    then:
      - service: isy994.set_variable
        data:
          name: sUPSLowBattery
          value: 1
    else:
      - service: isy994.set_variable
        data:
          name: sUPSLowBattery
          value: 0
  - if:
      - condition: template
        value_template: "{{ 'Forced Shutdown' in states('sensor.cp1350avr_status') }}"
    then:
      - service: isy994.set_variable
        data:
          name: sUPSFSD
          value: 1
    else:
      - service: isy994.set_variable
        data:
          name: sUPSFSD
          value: 0
  - if:
      - condition: or
        conditions:
          - condition: template
            value_template: "{{ 'High Battery' in states('sensor.cp1350avr_status') }}"
          - condition: template
            value_template: >-
              {{ 'Battery Needs Replaced' in states('sensor.cp1350avr_status')
              }}
          - condition: template
            value_template: "{{ 'Bypass Active' in states('sensor.cp1350avr_status') }}"
          - condition: template
            value_template: "{{ 'Runtime Calibration' in states('sensor.cp1350avr_status') }}"
          - condition: template
            value_template: "{{ 'Offline' in states('sensor.cp1350avr_status') }}"
          - condition: template
            value_template: "{{ 'Overloaded' in states('sensor.cp1350avr_status') }}"
          - condition: template
            value_template: "{{ 'Trimming Voltage' in states('sensor.cp1350avr_status') }}"
          - condition: template
            value_template: "{{ 'Boosting Voltage' in states('sensor.cp1350avr_status') }}"
          - condition: template
            value_template: "{{ 'Alarm' in states('sensor.cp1350avr_status') }}"
    then:
      - service: isy994.set_variable
        data:
          name: sUPSProblem
          value: 1
    else:
      - service: isy994.set_variable
        data:
          name: sUPSProblem
          value: 0
mode: single
alias: UPS Battery Charge
sequence:
  - if:
      - condition: numeric_state
        entity_id: sensor.cp1350avr_battery_charge
        above: "99"
    then:
      - service: isy994.set_variable
        data:
          name: iUPSBatteryCharge
          value: 100
    else:
      - if:
          - condition: numeric_state
            entity_id: sensor.cp1350avr_battery_charge
            above: "89"
            below: "99"
        then:
          - service: isy994.set_variable
            data:
              name: iUPSBatteryCharge
              value: 90
        else:
          - if:
              - condition: numeric_state
                entity_id: sensor.cp1350avr_battery_charge
                above: "79"
                below: "89"
            then:
              - service: isy994.set_variable
                data:
                  name: iUPSBatteryCharge
                  value: 80
            else:
              - if:
                  - condition: numeric_state
                    entity_id: sensor.cp1350avr_battery_charge
                    above: "69"
                    below: "79"
                then:
                  - service: isy994.set_variable
                    data:
                      name: iUPSBatteryCharge
                      value: 70
                else:
                  - if:
                      - condition: numeric_state
                        entity_id: sensor.cp1350avr_battery_charge
                        above: "59"
                        below: "69"
                    then:
                      - service: isy994.set_variable
                        data:
                          name: iUPSBatteryCharge
                          value: 60
                    else:
                      - if:
                          - condition: numeric_state
                            entity_id: sensor.cp1350avr_battery_charge
                            above: "49"
                            below: "59"
                        then:
                          - service: isy994.set_variable
                            data:
                              name: iUPSBatteryCharge
                              value: 50
                        else:
                          - if:
                              - condition: numeric_state
                                entity_id: sensor.cp1350avr_battery_charge
                                above: "39"
                                below: "49"
                            then:
                              - service: isy994.set_variable
                                data:
                                  name: iUPSBatteryCharge
                                  value: 40
                            else:
                              - if:
                                  - condition: numeric_state
                                    entity_id: sensor.cp1350avr_battery_charge
                                    above: "29"
                                    below: "39"
                                then:
                                  - service: isy994.set_variable
                                    data:
                                      name: iUPSBatteryCharge
                                      value: 30
                                else:
                                  - if:
                                      - condition: numeric_state
                                        entity_id: sensor.cp1350avr_battery_charge
                                        above: "19"
                                        below: "29"
                                    then:
                                      - service: isy994.set_variable
                                        data:
                                          name: iUPSBatteryCharge
                                          value: 20
                                    else:
                                      - if:
                                          - condition: numeric_state
                                            entity_id: sensor.cp1350avr_battery_charge
                                            below: "19"
                                            above: "9"
                                        then:
                                          - service: isy994.set_variable
                                            data:
                                              name: iUPSBatteryCharge
                                              value: 10
                                        else:
                                          - service: isy994.set_variable
                                            data:
                                              name: iUPSBatteryCharge
                                              value: 0
mode: single

The automation is:

alias: UPS Status
description: ""
trigger:
  - platform: time_pattern
    seconds: /10
condition: []
action:
  - service: script.ups_status
    data: {}
  - service: script.ups_battery_charge
    data: {}
mode: single

I suspect the error is related to the fact that the same service is called many times in a row and may not have the time to complete before being called again. If that’s the case, I’m not really sure how to fix this. How much time should I wait before calling the service again? Since I have multiple variables to set, is it possible to write them all in one service call?

Please help. I need some pointers.