Binary Sensor issue

Hi,

I have a ESPHome flashed Sonoff SV that is controlling the garage door (defined as a cover). There is a group of binary_sensors for all the doors/windows in the house and I want to add the state of garage to that group for home alarm. So I defined a binary sensor as below

template:
  - binary_sensor:
      - name: Garage Door Status2
        state: >-
          {% if states('cover.garagedoor') == 'closed' %}
            'off'
          {% else %}
            'on'
          {% endif %}

But it always seem “off”, this screen shot was taken when the garage door was open.
garage-2

And even more baffling when I copy and paste the if-else block in the template editor, it shows the correct state. This screen shot is taken at the same time as the one above.

Seems like there is nothing wrong with my code so why is HA not updating the state when garage door opens?

Ahh.hhhh, had to find ways to kick myself :grinning:

The quotes around on/off were the problem and this worked like a charm!

template:
  - binary_sensor:
      - name: Garage Door Status2
        state: >-
          {% if states('cover.garagedoor') == 'closed' %}
            off
          {% else %}
            on
          {% endif %}