Concatenate variable 1 with variable 2 (extracted from array)

I have now changed my variables to the following:

variables:
  media_player_id: " {{ trigger.device_id }} "
  media_player: " {{ device_entities(media_player_id) |select('search','^media_player.')|first }} "
  friendly_name: " {{ states[media_player]['attributes']['friendly_name'] }} "
  prepend: media_player.
  voice_assistant_device: " {{ prepend ~ (friendly_name) | slugify}} "

This what I was trying to do at first but was unsure of syntax. But good for comparison to put both methods in this topic. Thank you.

Update 21/02/25: changedselect('search','^media_player.*player') to
select('search','^media_player.') due to issue after an update of ESPHome to 2025.2.0 the player part at the end of the name in it’s friendly name has been removed. Change works either way (all conations beginning with media_player. will work).

1 Like