Hi all,
Iām facing a bit of a weird one here .
Iām trying to pass an OrderedDict as a value for a template.
The dict is name room and is structured as follow : OrderedDict([(āfriendly_nameā, āSalle de bainā), (āhumidityā, True), (āidā, ābathroomā), (ālightā, False), (ātemperatureā, True), (āvacuumā, False)]) .
If I use this with a template :
- !include
- ../../templates/room.yaml
- room: {{ room }}
Iām able to access the room variable inside thetemplate file as so :
- type: markdown
content: |
{{ room }}
Which gives me a nice result :
However I have trouble accessing each individual key/value inside the dict. So far, Iāve tried :
- {{ room.id }}
- {{ room[id] }}
- {{ room[āidā] }}
- {{ room|id }}
-> Result is always blank.
The thing that intirgues me is that {{ room|length }} gives me something like 130, which to me seems to indicate that the dictionnary is converted to a string when passed as a value.
So fa my solution has been to pass each value as a separate variable :
- !include
- ../../templates/room.yaml
- gridcol: {{ loop.index }} / {{ loop.index + 1 }}
gridrow: {{ rowIndex + rowloop.index0 }} / {{ rowIndex + rowloop.index0 + 1 }}
room: {{ room }}
room_id: {{ room.id }}
room_humidity: {{ room.humidity }}
room_light: {{ room.light }}
room_motion: {{ room.motion }}
room_name: {{ room.friendly_name }}
room_temperature: {{ room.temperature }}
room_vacuum: {{ room.vacuum }}
But tbh I donāt like the method & the look of it.
-> Have you guys been able to pass dict as variables in a jinja template ? Do you see something wrong in my code ?