YAML evaluated from developer tools but not from UI call

if I call a script from developer tools->services


service: script.alexa_generic
data:
  alexa_message: set Living Room Radiator temperature to {{ states('counter.tmp_trv') }}
  alexa_content_type: custom
  alexa_echo: media_player.living_room_echo_dot

then traces of the script shows me

 media_content_id: set Living Room Radiator temperature to 6

but the identical call from a button show

 media_content_id: set Living Room Radiator temperature to {{ states('counter.tmp_trv') }}

Most cards do not accept templates (especially in the actions), you will need to move the templating to a script or restructure your existing script.

1 Like

Is there any way around this or is there something to do with the architecture of home assistant that doesn’t allow it?
Seems like a fundamental bug/feature that would be great to have especially in this case where I can call alexa routines or custom calls dynamically

Had to create a new (less generic) script for the alexa call but that did the trick thanks:

 media_content_id: "set {{radiator}} temperature to {{states('counter.tmp_trv')}}"

I don’t know for sure, but since even highly templatable cards like Mushroom and Custom Button don’t accept templates in actions either, I’d assume it’s more than a trivial thing.

I wouldn’t go so far as to call it a bug since templating isn’t allowed elsewhere in most cards. There’s a lot of flexibility available by moving the templating to a script or automation. If you share your alexa_generic script we can probably help you restructure it.

Personally, I opted for a card with text input.

Looks similar to your code on the link you gave, but I add here for completeness.
It’s very generic so I could probably have a more specific version for other cases.

# call with content type 'custom' to emulate speaking to Alexa or 'routine' to run an Alexa routine
alias: Alexa - Generic
sequence:
  - service: media_player.play_media
    data:
      media_content_id: "{{alexa_message}}"
      media_content_type: "{{alexa_content_type}}"
    target:
      entity_id: "{{alexa_echo}}"
mode: single
icon: mdi:home-assistant