Template not firing within "value_template"

I’m pretty new to HASSIO so I may be missing something simple but I have been confused and unable to get jinja to parse and output the value of a light entity’s brightness attribute. I am using a template to accomplish this, and per the docs I am using the state_attr function rather than polling directly from the sates object which could be uninitialized on startup.

Something I am unsure of is the difference between value and value_template. I have seen both used. I thought jinja parsed everything and replaced all portions of yaml within the special brackets? If not does it only parse within the _template fields?

Also, is there an issue with how I have formatted the yaml below to grab the brightness into a variable? (Using the variables integration through HACS)

Thank you so much for helping me understand this more fully!

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: variable.update_sensor
  target:
    entity_id: sensor.var
  data:
    value_template: "{{ state_attr('light.upstairs_hallway_spot_lights', 'brightness') }}"
entity: light.living_room_entries_floodlight

Here is the result of that execution, just the string I typed unparsed:

image

Darn.

Is there a way to reference the value of an attribute as an input for a service call in a card?

I am trying to create a button that records the current brightness of a light as a preset on a hold click, and sets the light to the brightness preset on a normal click.

I’ll use a script if needed but it seems overkill for so simple a need. Do you know why templates are unsupported in cards?

I think I read an explanation once, but I don’t remember the specifics… it’s probably a combination of load order, dashboard stability, and efficiency.

While it’s not exactly the same, you may be able to get what you want by using the scene.create service to create a scene on the fly for your light then scene.turn_on to recall the state.

show_name: true
show_icon: true
type: button
hold_action:
  action: call-service  
  service: scene.create
  data:
    scene_id: temp_hallway_spot_lights
    snapshot_entities:
      - light.upstairs_hallway_spot_lights
tap_action:
  action: call-service
  service: scene.turn_on
  target:
    entity_id: scene.temp_hallway_spot_lights

That works perfect! The only functionality that I can’t replicate is I was hoping to display the preset target brightness on the button as well, but that would require a template in the name field or a script to retroactively update the button name with the target percent. I might do it with a script later, unless you know a simpler way for that too!