snarky-snark / home-assistant-variables

A custom Home Assistant component for declaring and setting generic variable entities dynamically.
Apache License 2.0
278 stars 16 forks source link

Trying to use variable in Lovelace template, as service_data, not standalone entity #55

Closed iscofield closed 3 years ago

iscofield commented 3 years ago

I have a lovelace button that calls a service and I am trying to utilize a variable that's been set and can't get it to actually populate the button. I've tried every combination I can think of but nothing works.

This works in my configuration.yaml:

service: rest_command.turn_fan_light_on
data: 
  device: "{{ states('var.ian_fan') }}"

Populating the same in Lovelace does not. I've tried all of the following combinations:

device: var.ian_fan
device: states.var.ian_fan
device: states.var.ian_fan.state
device: states('var.ian_fan')
device: "{{ states('var.ian_fan') }}"
device: "{{ states.var.ian_fan }}"
device: "{{ states.var.ian_fan.state }}"

If I put in the actual string that the variable represents, it works fine, so I know the surrounding context works, it would just appear that I can't use the variable in this manner?

snarky-snark commented 3 years ago

Have you tried using data_template instead of data?