Notifies and Switches On After X Time without Motion & Gate/Door Open

Tags: #<Tag:0x00007fc41bc20628> #<Tag:0x00007fc41bc20560> #<Tag:0x00007fc41bc20420>

The idea is to check the garage gate if it’s open for X minutes without any motion detected inside. So, I have motion sensor, a door sensor and a switch that operates the garage door.

Unfortunately I’m getting this error that is getting me really crazy: ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'str object' has no attribute 'last_changed'

Here’s the Blueprint:

blueprint:
  name: Notifies and Switches ON After X Time 
  description: Notifies and Switches ON After X Time 
  domain: automation
  input: 
    contact_sensor: 
      name: Contact Sensor
      description: The garage gate sensor that triggers the automation
      selector: 
        entity:
          domain: binary_sensor
    motion_entity:
      name: Motion Sensor
      description: Motion Sensor
      selector:
        entity:
          domain: binary_sensor 
    motion_timer:
      name: 'Timer'
      description: Notification and switch timer (in minutes)
      default: 5
      selector: 
        number:
          min: 1
          step: 1
          max: 60
          unit_of_measurement: minutes
          mode: slider
    target_entity:
      name: Target entity
      description: The switch that will become ON when the automation is triggered
      selector:
        target:
          entity:             
            domain: switch
    device_identifier:
      name: Device to notify
      description: The device that will receive the notification
      selector: 
        device:
          integration: mobile_app

mode: parallel

variables:
  motion_timer: !input 'motion_timer'
  motion_entity: !input 'motion_entity'

# We will have two triggers, but actions will be ignored if the garage is already closed or any motion detected during the last X minutes. 
trigger:
- platform: state
  entity_id: !input contact_sensor
  to: 'on'
  for:
    hours: 0
    minutes: !input motion_timer
    seconds: 0
- platform: state
  entity_id: !input motion_entity
  to: 'on'
  for:
    hours: 0
    minutes: !input motion_timer
    seconds: 0

# Check garage if is still open
# No motion during timer defined
condition:
- condition: and
  conditions:
  - condition: state
    entity_id: !input contact_sensor
    state: 'on'
  - condition: template
    value_template: '{{ ( motion_entity == none ) or ( as_timestamp(now()) >= as_timestamp(motion_entity.last_changed) + (motion_timer | float ) * 60 ) }}'

# Send a notification and closes the garage gate
action:
- device_id: !input device_identifier
  domain: mobile_app
  type: notify
  message: 'Closing Garage...'
  title: 'Garage still open!'
- service: homeassistant.turn_on
  target: !input 'target_entity'