I’m trying to build a json that is going to be a attribute of a sensor but I get the error
Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data[‘sensors’][‘matsedel_backaskolan_screen’][‘attribute_templates’].
A bit confusing but the loop at the bottom generates the json on the right, if I then feed this to a variable then I can use it just fine.
So when I try and use the same loop in a sensor:
sensor:
- platform: template
sensors:
matsedel_backaskolan_screen:
friendly_name: "Matsedel Backaskolan skärmanpassad"
value_template: "{{state_attr('sensor.matsedel_backaskolan', 'weeks')[0]['days'][ (now().timestamp() | timestamp_custom('%w')) | int-1]['items'] }}"
attribute_templates: >-
{
{% for weeks in state_attr('sensor.matsedel_backaskolan', 'weeks') -%}
{% if loop.first %}0{% else %}1{% endif %}:{
'week': 'Vecka {{ weeks.number }}',
{% for days in weeks.days -%}
'{{ days["date"] |timestamp_custom("%a") | replace("Mon", "Mån") | replace("Tue", "Tis") | replace("Wed", "Ons") | replace("Thu", "Tors") | replace("Fri", "Fre") }}dag': {{ days["items"] }} ,
{{" " }}
{%- endfor %} },
{%- endfor %} }
I get the error message that it expected a dictionary value.
Is it even possible to do this?