Don't Run Automation if sensor has specific text

I have a sensor that outputs the last time something was updated

I’m wanting to trigger an automation, but only if, the sensor doesn’t include the words “days” or “weeks”
So it only runs if it contains “Hours” or "seconds.

states('sensor.update2

“Updated 2 days ago”

Use a template trigger:


{%- set x = states('sensor.update2') %}
{{ 'hours' in x or 'seconds' in x }}

1 Like

Use a templated condition:

For example:

condition:
  alias: "not days"
  condition: template
  value_template: "{{ (not 'days' in 'updated 2 days ago') and (not 'weeks' in 'updated 2 days ago') }}"

The value_template: will evaluate as false and the condition will fail, thus the triggered automation won’t run.

Replace the text ‘updated 2 days ago’ with your sensor state.

1 Like

Thanks but run into another issue now, maybe this isn’t the way to do it?
It keeps triggering as the state is now “Updated 11 minutes ago” - so each minute, it triggers.

Would be easier to just say if “Updated 1 minute ago”

So the automation should trigger only twice in fact? Once when the sensor’s state contains ‘seconds’ and once when it contains ‘hours’?

Go to Developer Tools > States and check if the sensor has a device_class attribute whose value is timestamp. Let us know if it does (or doesn’t).

No timestamp.
Only want the automation to run off the trigger value contains the word “minute”

Solved.
Easy enough

{{ 'ABC' in trigger.to_state.state }}