Created
September 23, 2023 02:50
-
-
Save Didgeridrew/8c734fbb77ee9e1ce464dc7e42304759 to your computer and use it in GitHub Desktop.
HA - Modifying Dictionaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {%- 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