How to prevent ugly log error for turning off Kodi by method System Shutdown?

I get this ugly error in my log when I attempt to turn off the Kodi media_player while it is already turned off:

TransportError trying to run API method media_player.kodi.System.Shutdown({})

How can I prevent this error? Any ideas?

This is my configuration:

  - platform: kodi
    host: x.x.x.x
      - service: wake_on_lan.send_magic_packet
          mac: xx:xx:xx:xx:xx:xx
          broadcast_address: xx.xx.xx.255
    turn_off_action: #service template was an attempt but threw other ugly errors
      # - service_template: >
      #     {% if is_state('media_player.kodi','off') %}
      #     script.dummy
      #     {% else %}
      #     kodi.call_method
      #     {% endif %}
      - service: kodi.call_method
          entity_id: media_player.kodi
          method: System.Shutdown

I’d prefer to solve it in the turn_off action if at all possible. An alternative would be to add checks in all automations before running the turn_off service. But that would mean a lot of code duplication.