I am trying to create a unified notification script (based on a blueprint from the forum) that i can re-use for all notifications. the script builds the notification payload in several building blocks. when i call the script, i am getting this error Error: expected dict for dictionary value @ data['data']
. the section of the script where the error occurs is this:
alias: Send notification
service: '{{ notify_service }}'
data:
title: '{{ title }}'
message: '{{ message }}'
data: '{{ notification_data }}'
the notification_data
variable is what was built by the previous building blocks. in the trace is see the data makes it in there correctly, but for some reason it appears that a yaml strip operator
(>-
) is inserted in the data variable:
Executed: April 12, 2024 at 2:08:35 PM
Error: expected dict for dictionary value @ data['data']
Result:
params:
domain: notify
service: mobile_app_sebs_devices
service_data:
title: ''
message: THE MESSAGE
data: >-
{'subtitle': Undefined, 'push':
{'interruption-level': Undefined}, 'actions': [{'enabled': True, 'action':
'', 'title': 'TEST', 'icon': 'sfsymbols:field_opt_1_icon', 'destructive':
'field_opt_1_destructive', 'authenticationRequired':
'field_opt_1_authentication_required', 'uri': 'field_opt_1_uri'},
{'enabled': True, 'action': '', 'title': 'TEST2', 'icon':
'sfsymbols:field_opt_2_icon', 'destructive': 'field_opt_2_destructive',
'authenticationRequired': 'field_opt_2_authentication_required', 'uri':
'field_opt_2_uri'}], 'tag': Undefined}
target: {}
running_script: false
the previous step where the notification_data is built also adds the strip operator to the variable. Here is the yaml for that section:
variables:
options: |-
{{ [option_one, option_two, option_three] | selectattr('enabled') | list }}
expect_response: |-
{{ enable_timeout or option_one_enabled or option_two_enabled or
option_three_enabled }}
notification_data: |-
{% set payload = namespace(data={ 'apple_device': true }) %}
{% set push = namespace(d={}) %}
{% set payload.data = dict( payload.data, **{ 'subtitle': subtitle }) %}
{% set push.d = dict(push.d, **{ 'interruption-level': interruption_level })%}
{% if notification_link | length %}
{% endif %}
{% if attachment_type == 'camera_entity' %}
{% set payload.data = dict(payload.data, **{ 'entity_id': attachment_camera_entity }) %}
{% endif %}
{% set payload.data = dict(payload.data, **{ 'push': push.d }) %}
{% set payload.data = dict(payload.data, **{'actions': options }) %}
{% set payload.data = dict(payload.data, **{'tag':tag }) %}
{% if group|length %}
{% set payload.data = dict(payload.data, **{'group': group }) %}
{% endif %}
{{ payload.data }}
alias: Setup Mobile Payload
I’ve tested the service call with the contents of the data variable and it works as expected, just not sure how to remove the strip operator >-
. Anyone have any hints?
EDIT: edited the title for clarity…