Core: Cover templates return an error when using a binary template for their value_template

Created on 8 Sep 2020  路  4Comments  路  Source: home-assistant/core

The problem

I have a cover template whose state portion looks like this:

cover:
  - platform: template
    covers:
      garage_door:
        friendly_name: "Garage Door"
        value_template: "{{ is_state('binary_sensor.garage_door_sensor', 'off') }}"

Prior to 0.115.0b0, this used to properly return open/closed based on the state of the binary_sensor, but I now get the following error message in the log, and the cover template always has a state of "open":

2020-09-07 16:06:11 ERROR (MainThread) [homeassistant.components.template.cover] Received invalid cover is_on state: False. Expected: open, closed, true, false

If I evaluate the template in the dev tools, it looks like it is returning True and False:

Screen Shot 2020-09-07 at 4 17 41 PM

I know there's some translation that goes into what gets displayed and it can be different from what's actually returned, but in this case it looks like it's the same.

This returns the correct value:

        icon_template: >-
          {% if is_state('binary_sensor.garage_door_sensor', 'off') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

So the template engine is properly interpreting True/False as boolean true/false, but maybe just the cover template no longer likes the value?

I've worked around it for now by changing the template to:

value_template: "{{ 'open' if is_state('binary_sensor.garage_door_sensor', 'off') else 'closed' }}"

Environment

  • Home Assistant Core release with the issue: 0.115.0b0
  • Last working Home Assistant Core release (if known): 0.114.4
  • Operating environment (OS/Container/Supervised/Core): OS in a VM
  • Integration causing this issue: Maybe just cover templates?
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/cover.template/

Problem-relevant configuration.yaml

cover:
  - platform: template
    covers:
      garage_door:
        friendly_name: "Garage Door"
        value_template: "{{ is_state('binary_sensor.garage_door_sensor', 'off') }}"

Traceback/Error logs

2020-09-07 16:04:50 ERROR (MainThread) [homeassistant.components.template.cover] Received invalid cover is_on state: False. Expected: open, closed, true, false

Additional information

template

Most helpful comment

It鈥檚 completely inconsistent as to which templates did lower and which didn鈥檛. I鈥檒l audit them tomorrow and adjust

All 4 comments

We might have previously automatically made these .lower()

Yup there was a .lower

state = self._template.async_render().lower()

Need to check light as well

It鈥檚 completely inconsistent as to which templates did lower and which didn鈥檛. I鈥檒l audit them tomorrow and adjust

Hey there @phracturedblue, @tetienne, mind taking a look at this issue as its been labeled with an integration (template) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

Was this page helpful?
0 / 5 - 0 ratings