Template cover value_template - TypeError: not all arguments converted during string formatting!

Even after much reading, I’m afraid I still don’t have a proper grasp of how platform templates work, so that’s probably why I’m struggling to get one working for my garage door automation I’m attempting. This is my relevant bit of config:

  - platform: template
        friendly_name: "Garage Door - HASS"
        value_template: "{{is_state('binary_sensor.garage_door', 'on')}}"
          service: homeassistant.turn_on
          entity_id: switch.garage_door_switch
          service: homeassistant.turn_on
          entity_id: switch.garage_door_switch
          service: homeassistant.turn_on
          entity_id: switch.garage_door_switch

“Check Config” works OK, but I’m seeing this error in the log:

Error while setting up platform template
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/src/homeassistant/homeassistant/components/template/cover.py", line 94, in async_setup_platform
  File "/usr/local/lib/python3.7/logging/__init__.py", line 1407, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/local/lib/python3.7/logging/__init__.py", line 1514, in _log
  File "/usr/local/lib/python3.7/logging/__init__.py", line 1524, in handle
  File "/usr/local/lib/python3.7/logging/__init__.py", line 1586, in callHandlers
  File "/usr/local/lib/python3.7/logging/__init__.py", line 894, in handle
  File "/usr/src/homeassistant/homeassistant/components/system_log/__init__.py", line 167, in emit
    _figure_out_source(record, stack, self.hass))
  File "/usr/src/homeassistant/homeassistant/components/system_log/__init__.py", line 92, in __init__
    self.message = record.getMessage()
  File "/usr/local/lib/python3.7/logging/__init__.py", line 369, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting

I assume the issue is with the value_template. I’ve tried loads of variations of this, but I can’t get any to work.

Can anyone help me decipher what that error message is telling me please?

Your value_template should work if you have the configured binary_sensor.
Just copy and paste the template into Dev Tools/Templates and you can check it.

How should your cover work with the same actions for open/close/stop?

Are you sure the problwm is this cover?
Comment it out and see if everything else works.

1 Like

Thank you. You suspicions were correct - this bit of code didn’t appear to be the issue!

I commented it out, and I’m still getting the same error after restart. The only other template cover I had was in an ESPHome config. I’ve commented that out and even removed an old cover reference in the entity registry and I’m still getting that error. Very strange.

My garage door opener only has one control. It does an up/stop(if moving)/down in rotation. I wasn’t sure if I’d be able to get the logic to handle that so I just set them all the same for now.

Thanks again. I’m turning in now and will return to this after work tomorrow.

I noticed I was a few patch levels behind the latest release (I was on 0.96.2). Just updated to 0.96.5, and no error! Uncommented what I thought was the offending section, still no errors, and now it’s available to use!

So, looks like I fell foul of a bug, now squashed :smile: