Hi,
I did a super bad job of explaining my conundrum. Apologies. Your reply was educational though. Thank you.
Let me simplify with a different example.
I have included yaml file in my yaml dashboard for a climate-card that is fed by variables.
The !include, looks like this:
- !include
- ../components/mini-climate.yaml
- entity: {{govee_entity}}
name: "Porch Space Heater"
buttons: ["heat", "auto", "swing", "presets"]
hvac_show_buttons: ["auto", "heat", "fan", "swing_mode", "custom_1"]
hvac_mode: {{govee_hvac_modes}}
indicators: {{govee_indicators}}
secondary_info: {"type": "fan-mode-dropdown"}
{# override defaults #}
hvac_auto: {"icon": "mdi:sun-snowflake-variant", "is_active": "auto",
"hvac_mode": "auto", "activeColor": "var(--state-climate-auto-color) !important"}
hvac_custom_1: {"type": "dropdown", "icon": "mdi:lightbulb",
"active": "(value !== '' && entity.attributes.nightlight == 'on')",
"state": {"attribute": "selected_scene"}, "activeColor": "var(--state-light-active-color) !important",
"source": {"off":"Light Off", "Coffee": "Coffee", "Sleep":"Sleep", "Warm": "Warm"},
"action": {"domain": "mqtt", "service": "publish",
"options": "{ topic: 'gv2mqtt/DB2A6074F445163C/set-mode-scene', payload: selected }"
}
}
Inside the included yaml file, we use the hvac_custom_1.source
variable like this:
source:
<<:
{{item.source}}
It works.
The rendered output (with the dropdown fed by hvac_custom_1.source
) is:
Now, instead of hard-coding that hvac_cutom_1.source
variable, I want to create the options, from an attribute of an entity:
I have an entity: climate.porch_spaceheater
. It has an attribute that looks like this (abbreviated):
nightlight_scenes:
- name: Reading
value: 1
- name: Movie
value: 2
- name: Work
value: 3
- name: Night Light
value: 4
- name: Party
value: 5
- name: Sports
value: 6
- name: Music
value: 7
- name: Warm
value: 8
To test my jinja to get the data from that attribute, I have created a āDebug Markdown Cardā in the dashboard yaml that looks like this:
- type: markdown
title: "Debug Markdown Zone"
content: |
{% raw %}
{% set scenes = state_attr('climate.porch_spaceheater', 'nightlight_scenes') | map(attribute='name')|list %}
{% set source = '[' ~ (scenes | map('regex_replace', '^(.*)$', '{ "\\1": "\\1" }') | join(", ")) ~ ']' %}
{{ source }}
{% endraw %}
It works. And outputs this (I know thatās a hairy xform, but it works!):
So, my question is how the heck do I get that {%raw%}ā¦{%endraw%} block to feed the source prop in hvac_custom_1.source
?
- !include:
- ../..etc...
- entity: ....
hvac_custom_1: {
...
"source": //STUFF FROM %RAW% %ENDRAW% GOES HERE!
}
I have tried everything. doing it inline, creating a source
variable at the top of the file, creating a macro, but all to avail. I hope I explained this well enough, and hoping someone can teach me the way. If you need more info, please shout!
TIA.