Rollo
(Rollo)
February 28, 2020, 11:22pm
1
Hello, I get an error message and do not know what to do and need help pls:
Message malformed: expected a dictionary for dictionary value @ data[‘action’][0][‘data_template’]
data_template: >-
{% if is_state('binary_sensor.khlschrank', 'off') %}
message: 'Kühlschrank geschlossen'
title: 'ENTWARNUNG!'
{% else %}
message: 'Kühlschrank offen'
title: 'WARNUNG!'
{% endif %}
service: notify.notify
Vlad
(Vladislav)
February 29, 2020, 12:07am
2
I think you using wrong template for this code, try value_template.
And instead “>-” use “>”
AhmadK
(akasma74)
February 29, 2020, 12:16am
3
Vlad:
try value_template.
he has an automation/action here, not template sensor
Vlad:
And instead “>-” use “>”
what’s the difference?
Actually, it would be great to see the whole automation.
Anyway, how about this:
service: notify.notify
data_template: >-
{% if is_state('binary_sensor.khlschrank', 'off') %}
message: 'Kühlschrank geschlossen'
title: 'ENTWARNUNG!'
{% else %}
message: 'Kühlschrank offen'
title: 'WARNUNG!'
{% endif %}
or even better, this one
service: notify.notify
data_template:
title: >
{{ 'ENTWARNUNG!' if is_state('binary_sensor.khlschrank', 'off') else 'WARNUNG!' }}
message: >
{{ 'Kühlschrank geschlossen' if is_state('binary_sensor.khlschrank', 'off') else 'Kühlschrank geschlossen' }}
Mutt
(Muttley)
February 29, 2020, 12:31am
4
Vlad:
“>-” use “>”
The dash “-” removes spaces helps compact output, especially in the format output in the template editor.
AhmadK
(akasma74)
February 29, 2020, 12:33am
5
ok. does it make any difference here?
Mutt
(Muttley)
February 29, 2020, 12:35am
6
No, but that’s not the question ‘you’ asked
AhmadK
(akasma74)
February 29, 2020, 12:38am
7
well, the full initial question could’ve been “will that thingie make any difference here?”
sorry for shortcuting
You can’t use templates to conditionally include key/value pairs (i.e., parameters and their values.) A template must be contained entirely within a value.
data_template:
message: >
{% if is_state('binary_sensor.khlschrank', 'off') %}
Kühlschrank geschlossen
{% else %}
Kühlschrank offen
{% endif %}
title: >
{% if is_state('binary_sensor.khlschrank', 'off') %}
ENTWARNUNG!
{% else %}
WARNUNG!
{% endif %}
service: notify.notify
2 Likes
Rollo
(Rollo)
February 29, 2020, 8:47am
9
Thanks!
The solution works for me so far and is comprehensible.
I’m quite new in the business. Is there a good source with examples and explanations available?
AhmadK
(akasma74)
February 29, 2020, 8:50am
10
There is, right here and here to start with