Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103312

This template works in Developer Tools, but not in a script. Why?

$
0
0

I have the following template in a script. When I test the template in Developer Tools, it works like I expect. But when I call it, I get an error. Is there a way to accomplish what I’m trying to do here?

The script:

service_template: |
  {% if is_state('device_tracker.frank_iphone', 'work') %}
     notify.email_frank
  {% else %}
     notify.mobile_app_frank_iphone
  {% endif %}
data: |
  {% if title is defined %}
    title: "{{ title }}"
  {% endif %}
  {% if message is defined %}
    message: "{{ message }}"
  {% endif %}
  {% if image is defined or url is defined %}
    data:
      {% if image is defined %}
        image: "{{ image }}"
      {% endif %}
      {% if url is defined %}
        url: "{{ url }}"
      {% endif %}
  {% endif %}

Example of calling it:

service: script.notify_frank_with_data
data:
  title: foo
  message: bar

The error when calling it:

2022-05-07 07:14:19 ERROR (MainThread) [homeassistant.components.script.notify_frank_with_data] notify_frank_with_data: Error executing script. Error for call_service at pos 1: Error rendering data template: Result is not a Dictionary
2022-05-07 07:14:19 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Error for call_service at pos 1: Error rendering data template: Result is not a Dictionary
2022-05-07 07:14:19 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139955239246912] Error handling message: Error rendering data template: Result is not a Dictionary (unknown_error)

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 103312

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>