Other ways to write 'on' / 'off'

Hi! I’m a pretty new user therefore I’m sorry if what I’m asking may be pretty obvious.

I’m writing code to automate lovelace’s dashboards by modifying yaml files with App Daemon’s add-on.
It’s pretty frustrating to write characters as single and double quotes by using YAML libraries, and sadly I want to write:

state: 
  - value: 'on'

which is harder than it seems to be.
I’m able to write:

state: 
  - value: on

but that’s no good.
So I was wondering if there is some way around this problem by writing equivalent ways of value: ‘on’.
I tried to create a variable (the custom component):

var: 
  onvalue:
    friendly_name: 'onvalue'
    initial_value: 'on'

and then write:

- value_template: "{{ states('var.onvalue') }}"

But it doesn’t work. Any help?

Btw: yes the libraries allow to write single quotes but than automatically add double quotes at the start and at the end, in fact I can write:

state: 
  - value: "'on'"

which, useless to say, doesn’t work as ‘on’.

This is trying to find the state of the literal string ‘var.onvalue’, even if you did not have the quotes around your variable it would evaluate to “{{ states(‘on’) }}” which is not how you use states()

- value_template: "{{ states('var.onvalue') }}"

Remove the quotes and you could use it like this:

- value_template: "{{ is_state('domain.some_entity', var.onvalue) }}"

Is it usable for the code of a card?

type: custom:button-card
entity: sensor.cam_ping1
tap_action: more-info
icon: mdi:router-wireless
color: auto
name: 192.168.2.2
state:
  - value_template: '{{ is_state('sensor.cam_ping1', var.offvalue) }}'
    color: rgb(200,0,0)
  - value_template: 'on'
    color: rgb(0,200,0)
  - value: unknown
    color: rgb(200,0,0)
  - value: unavailable
    color: rgb(200,0,0)
size: 30%

No, Lovelace does not support templates.

You can use this custom card to add Javascript templates (not jinja).

Also a word of warning about your use of quotes, you need to put double quotes outside your templates, otherwise this happens:

value_template: '{{ is_state('

I’ll try that, thanks!