I have a template sensor that has an attribute that is a dict which renders great on a dashboard, but it seems like after the last HA update [2024.4.2] I cannot use a dict in the message
for a notify service.
I’ve hard-coded the message here to make it clear I’m returning a dict:
binary_sensor:
- name: House Locked
device_class: lock
state: |
{{ locked | count != ent_list | count }}
attributes:
message: |
{{
{
"Front Door": "Unlocked",
"Side Window": "Open"
}
}}
This renders nicely in the UI on a dashboard:
also in the developer view:
I was rendering this in a service call (in an automation), too, but now it’s giving an error:
service: notify.mobile_app_iphone
data:
title: House is unlocked!
message: |
{{ state_attr('binary_sensor.house_locked', 'message') }}
Which now results in:
Error running action
template value should be a string for dictionary value @ data[‘message’]. Got None
I’m curious how the Entity Card is rending the dictionary correctly, and if that rendering used to also apply in templates in a previous HA versions.
Is there something in Jinja to render a dictionary? Or do I need to do something like this?
[Edited]
{% set dict = state_attr('binary_sensor.house_locked', 'message') %}
{{ dict }}
-------------------
{{ dict|items|map('join', ': ')|list|join("\n") }}
Which results in:
{'Front Door': 'Unlocked', 'Side Window': 'Open'}
-------------------
Front Door: Unlocked
Side Window: Open
Thanks.