Help with condition template using sensor attribute

Hi fellow automators :smiley:

Entity Page:

Entity:
  binary_sensor.motion_sensor_158d0001e52dee
State:
  on
Attributes:
  No motion since: 1800
  battery_level: 41
  friendly_name: Motion Hallway
  device_class: motion

Automation.yaml

- alias: 'no motion test'
  trigger:
  condtion:
    - condition: template
      value_template: "{{ states.binary_sensor.motion_sensor_158d0001e52dee.attributes['No motion since'] > 300 }}"
   action:
     - service: persistent_notification.create
       data:
         message: "No motion for > 300 has returned true"
         title: "Test" 

value_template: "{{ states.binary_sensor.motion_sensor_158d0001e52dee.attributes['No motion since'] > 300 }}"

The syntax for the value template condition is incorrect, and I can’t figure out why.
I want to return a condition = true if ‘no motion since’ > ‘300’.

Thanks for any help

What does the Templates Tool show if you paste
{{ states.binary_sensor.motion_sensor_158d0001e52dee.attributes['No motion since'] }} in?
Maybe convert to int?
{{ states.binary_sensor.motion_sensor_158d0001e52dee.attributes['No motion since'] | int > 300 }}

1 Like

i have never used the template tool, but that definitely sounds like something i should use. I will try and report back! thank you.

{{ states.binary_sensor.motion_sensor_158d0001e52dee.attributes['No motion since'] }}

in the template tool. comes back with

300

so that part works!

{{ states.binary_sensor.motion_sensor_158d0001e52dee.attributes['No motion since'] | int > 300 }}

gives me

True

Yeah, I’ve been working on this one line for almost 1 hour :frowning:

1 Like

try adding an “int” filter to the attribute read:

value_template: "{{ states.binary_sensor.motion_sensor_158d0001e52dee.attributes['No motion since'] | int > 300 }}"

In the example you gave, there is a spelling mistake, condtion: