Help Requested: Error on Automation Template Trigger

The Home Assistant System Log keeps on throwing this error;

Logger: homeassistant.components.template.trigger
Source: components/template/trigger.py:68
Integration: Template (documentation, issues)
First occurred: 11:28:03 (1 occurrences)
Last logged: 11:28:03

Error evaluating ‘template’ trigger for ‘Beta: Picnic’: ValueError: Template error: as_timestamp got invalid input ‘unknown’ when rendering template ‘platform: template value_template: >- {% if states(‘sensor.picnic_selected_slot_max_order_time’) not in [‘unknown’,‘unavailable’,‘none’] %} {{ 7200 > (as_timestamp(states(‘sensor.picnic_selected_slot_max_order_time’)) - as_timestamp(now(), 0)) > 0}} {% endif %} variables: message: >- Your Picnic order hasn’t been sent! It won’t be possible after {{ as_timestamp(states(“sensor.picnic_selected_slot_max_order_time”)) | timestamp_custom(“%H:%M”) }}.’ but no default was specified

Whereas I think I actually have created defaults for this Automation Template Trigger:

alias: "Beta: Picnic"
description: ""
trigger:
  - platform: template
    value_template: >-
      {% if states('sensor.picnic_next_delivery_eta_start') not in
      ['unknown','unavailable','none'] %}
        {{ 901 > (as_timestamp(states('sensor.picnic_next_delivery_eta_start'), 0) - as_timestamp(now(), 0)) > 840}}
      {% endif %}
    id: delivery_soon
  - platform: template
    value_template: |
      platform: time_pattern
      minutes: /2
    id: update_eta
  - platform: template
    value_template: |-
      platform: template
      value_template: >-
        {% if states('sensor.picnic_selected_slot_max_order_time') not in
        ['unknown','unavailable','none'] %}
          {{ 7200 > (as_timestamp(states('sensor.picnic_selected_slot_max_order_time')) - as_timestamp(now(), 0)) > 0}}
        {% endif %}
      variables:
        message: >-
          Your Picnic order hasn't been sent! It won't be possible after {{
          as_timestamp(states("sensor.picnic_selected_slot_max_order_time")) |
          timestamp_custom("%H:%M") }}.
    variables:
      message: >-
        Your Picnic order hasn't been sent! It won't be possible after {{
        as_timestamp(states("sensor.picnic_selected_slot_max_order_time")) |
        timestamp_custom("%H:%M") }}.
    id: order_window_closing
  - platform: template
    value_template: |-
      platform: template
      value_template: >-
        {% if states('sensor.picnic_last_order_max_order_time') not in
        ['unknown','unavailable','none'] %}
          {{ 7200 > (as_timestamp(states('sensor.picnic_last_order_max_order_time')) - as_timestamp(now(), 0)) > 0}}
        {% endif %}
      variables:
        message: >-
          Would you like to add something to the current Picnic order? It won't be
          possible after {{
          as_timestamp(states("sensor.picnic_last_order_max_order_time")) |
          timestamp_custom("%H:%M") }}.
    variables:
      message: >-
        Your Picnic order hasn't been sent! It won't be possible after {{
        as_timestamp(states("sensor.picnic_selected_slot_max_order_time")) |
        timestamp_custom("%H:%M") }}.
    id: order_window_closing
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: delivery_soon
        sequence:
          - if:
              - condition: numeric_state
                entity_id: zone.home
                below: 1
            then:
              - service: notify.notification_devices_household_all
                data:
                  title: Picnic on-route for delivery!
                  message: >
                    Your Picnic order will be delivered between {{
                    states('sensor.picnic_next_delivery_eta_start_time') }} and
                    {{ states('sensor.picnic_next_delivery_eta_end_time') }}!
                  data:
                    clickAction: app://com.picnic.android
                    icon_url: >-
                      https://picnic.app/nl/wp-content/uploads/sites/18/2020/11/logo.png
                    notification_icon: mdi:cart
                    tag: picnic_alert
                    timeout: 1800
                    color: "#eb4034"
                    ttl: 0
                    priority: high
            else:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: input_boolean.house_in_dnd_mode
                    state: "off"
                  - condition: and
                    conditions:
                      - condition: state
                        entity_id: input_boolean.house_in_night_mode
                        state: "off"
                      - condition: state
                        entity_id: input_boolean.morning_ritual_executed
                        state: "on"
                  - condition: or
                    conditions:
                      - condition: state
                        entity_id: input_select.matthijs_status_dropdown
                        state: Home
                      - condition: state
                        entity_id: input_select.matthijs_status_dropdown
                        state: Just Arrived
              - if:
                  - condition: state
                    entity_id: input_boolean.use_alexa
                    state: "on"
                then:
                  - if:
                      - condition: or
                        conditions:
                          - condition: not
                            conditions:
                              - type: is_open
                                condition: device
                                device_id: caf18366a43b1720796a9f8849e504ba
                                entity_id: >-
                                  binary_sensor.back_garden_shed_door_sensor_contact
                                domain: binary_sensor
                          - condition: not
                            conditions:
                              - type: is_open
                                condition: device
                                device_id: 7f04c801e994ca5334fd039373f68439
                                entity_id: >-
                                  binary_sensor.kitchen_door_motion_temperature_sensor_contact
                                domain: binary_sensor
                    then:
                      - service: notify.alexa_media_everywhere
                        data:
                          message: >-
                            Your Picnic order will be delivered between {{
                            states('sensor.picnic_next_delivery_eta_start_time')
                            }} and {{
                            states('sensor.picnic_next_delivery_eta_end_time')
                            }}!
                          data:
                            type: announce
                            method: all
                    else:
                      - service: script.turn_on
                        target:
                          entity_id: script.google_home_resume
                        data:
                          variables:
                            action:
                              - service: media_player.play_media
                                target:
                                  entity_id: media_player.all_google_speakers
                                data:
                                  media_content_id: >-
                                    media-source://tts/cloud?message=Matthijs%2C+your+Picnic+order+will+be+delivered+soon&language=en-GB&gender=female
                                  media_content_type: provider
                                extra:
                                  volume: 0.5
                                metadata:
                                  title: >-
                                    Matthijs, your Picnic order will be
                                    delivered soon.
                                  thumbnail: >-
                                    https://brands.home-assistant.io/_/cloud/logo.png
                                  media_class: app
                                  children_media_class: null
                                  navigateIds:
                                    - {}
                                    - media_content_type: app
                                      media_content_id: media-source://tts
                                    - media_content_type: provider
                                      media_content_id: >-
                                        media-source://tts/cloud?message=Matthijs%2C+your+Picnic+order+will+be+delivered+soon&language=en-GB&gender=female
                else:
                  - service: script.turn_on
                    target:
                      entity_id: script.google_home_resume
                    data:
                      variables:
                        action:
                          - service: media_player.play_media
                            target:
                              entity_id: media_player.all_google_speakers
                            data:
                              media_content_id: >-
                                media-source://tts/cloud?message=Matthijs%2C+your+Picnic+order+will+be+delivered+soon&language=en-GB&gender=female
                              media_content_type: provider
                            extra:
                              volume: 0.5
                            metadata:
                              title: >-
                                Matthijs, your Picnic order will be delivered
                                soon.
                              thumbnail: >-
                                https://brands.home-assistant.io/_/cloud/logo.png
                              media_class: app
                              children_media_class: null
                              navigateIds:
                                - {}
                                - media_content_type: app
                                  media_content_id: media-source://tts
                                - media_content_type: provider
                                  media_content_id: >-
                                    media-source://tts/cloud?message=Matthijs%2C+your+Picnic+order+will+be+delivered+soon&language=en-GB&gender=female
              - service: cast.show_lovelace_view
                data:
                  entity_id: media_player.bedroom_display
                  dashboard_path: lovelace-cast
                  view_path: picnic-eta
                enabled: false
              - delay:
                  hours: 0
                  minutes: 30
                  seconds: 0
                  milliseconds: 0
                enabled: false
              - service: media_player.turn_off
                data: {}
                target:
                  entity_id: media_player.bedroom_display
                enabled: false
      - conditions:
          - condition: trigger
            id: update_eta
        sequence:
          - service: homeassistant.update_entity
            entity_id: sensor.picnic_next_delivery_eta_start
      - conditions:
          - condition: trigger
            id: order_window_closing
        sequence:
          - if:
              - condition: numeric_state
                entity_id: zone.home
                above: 0
            then:
              - service: notify.notification_devices_household_all
                data:
                  title: Picnic order is closing!
                  message: "{{ message }}"
                  data:
                    clickAction: app://com.picnic.android
                    icon_url: >-
                      https://picnic.app/nl/wp-content/uploads/sites/18/2020/11/logo.png
                    notification_icon: mdi:cart
                    tag: picnic_alert
                    timeout: 1800
                    color: "#eb4034"
                    ttl: 0
                    priority: high
            else:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: input_boolean.house_in_dnd_mode
                    state: "off"
                  - condition: and
                    conditions:
                      - condition: state
                        entity_id: input_boolean.house_in_night_mode
                        state: "off"
                      - condition: state
                        entity_id: input_boolean.morning_ritual_executed
                        state: "on"
                  - condition: or
                    conditions:
                      - condition: state
                        entity_id: input_select.matthijs_status_dropdown
                        state: Home
                      - condition: state
                        entity_id: input_select.matthijs_status_dropdown
                        state: Just Arrived
              - if:
                  - condition: state
                    entity_id: input_boolean.use_alexa
                    state: "on"
                then:
                  - if:
                      - condition: or
                        conditions:
                          - condition: not
                            conditions:
                              - type: is_open
                                condition: device
                                device_id: caf18366a43b1720796a9f8849e504ba
                                entity_id: >-
                                  binary_sensor.back_garden_shed_door_sensor_contact
                                domain: binary_sensor
                          - condition: not
                            conditions:
                              - type: is_open
                                condition: device
                                device_id: 7f04c801e994ca5334fd039373f68439
                                entity_id: >-
                                  binary_sensor.kitchen_door_motion_temperature_sensor_contact
                                domain: binary_sensor
                    then:
                      - service: notify.alexa_media_everywhere
                        data:
                          message: >-
                            Matthijs, your Picnic order is closing! "{{ message
                            }}"
                          data:
                            type: announce
                            method: all
                    else:
                      - service: script.turn_on
                        target:
                          entity_id: script.google_home_resume
                        data:
                          variables:
                            action:
                              - service: media_player.play_media
                                target:
                                  entity_id: media_player.all_google_speakers
                                data:
                                  media_content_id: >-
                                    media-source://tts/cloud?message=Matthijs%2C+your+Picnic+order+is+closing&language=en-GB&gender=female
                                  media_content_type: provider
                                extra:
                                  volume: 0.5
                                metadata:
                                  title: Matthijs, your Picnic order is closing.
                                  thumbnail: >-
                                    https://brands.home-assistant.io/_/cloud/logo.png
                                  media_class: app
                                  children_media_class: null
                                  navigateIds:
                                    - {}
                                    - media_content_type: app
                                      media_content_id: media-source://tts
                                    - media_content_type: provider
                                      media_content_id: >-
                                        media-source://tts/cloud?message=Matthijs%2C+your+Picnic+order+is+closing&language=en-GB&gender=female
                else:
                  - service: script.turn_on
                    target:
                      entity_id: script.google_home_resume
                    data:
                      variables:
                        action:
                          - service: media_player.play_media
                            target:
                              entity_id: media_player.all_google_speakers
                            data:
                              media_content_id: >-
                                media-source://tts/cloud?message=Matthijs%2C+your+Picnic+order+is+closing&language=en-GB&gender=female
                              media_content_type: provider
                            extra:
                              volume: 0.5
                            metadata:
                              title: Matthijs, your Picnic order is closing.
                              thumbnail: >-
                                https://brands.home-assistant.io/_/cloud/logo.png
                              media_class: app
                              children_media_class: null
                              navigateIds:
                                - {}
                                - media_content_type: app
                                  media_content_id: media-source://tts
                                - media_content_type: provider
                                  media_content_id: >-
                                    media-source://tts/cloud?message=Matthijs%2C+your+Picnic+order+is+closing&language=en-GB&gender=female
              - service: notify.notification_devices_household_all
                data:
                  title: Picnic order is closing soon!
                  message: "{{ message }}"
                  data:
                    clickAction: app://com.picnic.android
                    icon_url: >-
                      https://picnic.app/nl/wp-content/uploads/sites/18/2020/11/logo.png
                    notification_icon: mdi:cart
                    tag: picnic_alert
                    timeout: 1800
                    color: "#eb4034"
                    ttl: 0
                    priority: high
mode: parallel
max: 10

I really don’t understand what I did do wrong. Can someone please help me out?

You have created some defaults… Every instance of as_timestamp() needs a default.

There are 2 missing in your 3rd trigger and 2 missing in the 4th trigger. Both also have an extraneous variables keys and values.

FWIW, now().timestamp() is equivalent to as_timestamp(now(), 0)

Thank you, changed the triggers as follows based on your guidance:

trigger:
  - platform: template
    value_template: >-
      {% if states('sensor.picnic_next_delivery_eta_start') not in
      ['unknown','unavailable','none'] %}
        {{ 901 > (as_timestamp(states('sensor.picnic_next_delivery_eta_start'), 0) - as_timestamp(now(), 0)) > 840}}
      {% endif %}
    id: delivery_soon
  - platform: template
    value_template: |
      platform: time_pattern
      minutes: /2
    id: update_eta
  - platform: template
    value_template: |-
      platform: template
      value_template: >-
        {% if states('sensor.picnic_selected_slot_max_order_time') not in
        ['unknown','unavailable','none'] %}
          {{ 7200 > (as_timestamp(states('sensor.picnic_selected_slot_max_order_time'), 0) - as_timestamp(now(), 0)) > 0}}
        {% endif %}
      variables:
        message: >-
          Your Picnic order hasn't been sent! It won't be possible after {{
          as_timestamp(states("sensor.picnic_selected_slot_max_order_time"), 0) |
          timestamp_custom("%H:%M"), 0 }}.
    variables:
      message: >-
        Your Picnic order hasn't been sent! It won't be possible after {{
        as_timestamp(states("sensor.picnic_selected_slot_max_order_time")) |
        timestamp_custom("%H:%M") }}.
    id: order_window_closing
  - platform: template
    value_template: |-
      platform: template
      value_template: >-
        {% if states('sensor.picnic_last_order_max_order_time') not in
        ['unknown','unavailable','none'] %}
          {{ 7200 > (as_timestamp(states('sensor.picnic_last_order_max_order_time'), 0) - as_timestamp(now(), 0)) > 0}}
        {% endif %}
      variables:
        message: >-
          Would you like to add something to the current Picnic order? It won't be
          possible after {{
          as_timestamp(states("sensor.picnic_last_order_max_order_time"), 0) |
          timestamp_custom("%H:%M"), 0 }}.
    variables:
      message: >-
        Your Picnic order hasn't been sent! It won't be possible after {{
        as_timestamp(states("sensor.picnic_selected_slot_max_order_time")) |
        timestamp_custom("%H:%M") }}.
    id: order_window_closing

What you posted as your correction is not a valid trigger configuration. As stated in my previous post, you should have defaults for all of your as_timestamp() functions. Also, it looks like you have copy/pasted a trigger inside another trigger…

Try the following:

  - platform: template
    value_template: >-
      {% if states('sensor.picnic_selected_slot_max_order_time') not in ['unknown','unavailable','none'] %}
        {% set delta = as_timestamp(states('sensor.picnic_selected_slot_max_order_time'), 0) 
        - now().timestamp() %}
        {{ 7200 > delta > 0}}
      {% endif %}
    variables:
      message: >-
        Your Picnic order hasn't been sent! It won't be possible after {{
        as_timestamp(states("sensor.picnic_selected_slot_max_order_time"), 0) |
        timestamp_custom("%H:%M") }}.
    id: order_window_closing

Hmmm, tx for pointing this out. The weird thing is, this is what happens using the Visual editor, I’ll try to replicate it and open a Github issue for it