Problem with Automation data_template :/

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

I think you using wrong template for this code, try value_template.
And instead “>-” use “>”

he has an automation/action here, not template sensor :wink:

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' }}

The dash “-” removes spaces helps compact output, especially in the format output in the template editor.

ok. does it make any difference here? :wink:

No, but that’s not the question ‘you’ asked

well, the full initial question could’ve been “will that thingie make any difference here?” :wink:
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

Thanks! :slight_smile:
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?

There is, right here and here to start with :wink: