Skip to content

Instantly share code, notes, and snippets.

@Didgeridrew
Created September 23, 2023 02:50
Show Gist options
  • Select an option

  • Save Didgeridrew/8c734fbb77ee9e1ce464dc7e42304759 to your computer and use it in GitHub Desktop.

Select an option

Save Didgeridrew/8c734fbb77ee9e1ce464dc7e42304759 to your computer and use it in GitHub Desktop.
HA - Modifying Dictionaries
{%- set target = ['media_player.amanda_s_bedroom_dot','media_player.basement_dot',
'media_player.amanda_s_living_room_dot']%}
======================================
{% set ns = namespace( x = {}) %}
{%- for t in expand(target) %}
{%- set ns.x = dict(ns.x, **{t.entity_id: t.name}) %}
{%- endfor %}
{{ ns.x }}
---------------------------------------
{%- set ns = namespace( y = []) %}
{%- for t in expand(target) %}
{%- set ns.y = ns.y + [(t.entity_id, t.name)] %}
{%- endfor %}
List of tuples: {{ ns.y }}
Dictionary: {{ dict.from_keys(ns.y) }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment