Why does this template read false in the automation but true when tested separately?

I have a template which should read true when Home Assistant has been up for more than 30 seconds.

"{{ (as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) > 30 }}"

What’s curious is that I can test this using Developer/ Tools.Template/Template Editor and see that it evaluates to true but when the following automation runs, the trace shows that it evaluates to false.

alias: Power Disconnected
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.inverter_grid_connected_status
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 10
conditions:
  - condition: and
    conditions:
      - condition: time
        after: "06:00:00"
        before: "21:00:00"
      - condition: template
        value_template: >-
          "{{ (as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) > 30
          }}"
actions:
  - action: notify.pushover
    metadata: {}
    data:
      title: Grid Power Disconnected
      message: Grid Power Disconnected
      data:
        sound: no_power
        priority: 0
mode: single

here is the trace…

and here is the test of the template…

And here are the specifics on sensor.uptime

Surely I must be missing something very basic here… Any help is appreciated.

Your template likely isn’t correct. What is the state of sensor.uptime? It’s likely a single float value which as_timestamp wouldn’t be able to parse. Unless it’s a timestamp sensor. either way, show us the state of sensor.uptime.

If it is correct, your problem is the extra quotes.

image

1 Like

(I added the sensor.uptime information above).

You are indeed correct that the problem was the extra quotation marks. I’ve been programming since the 1970’s but yaml is still eluding me in many ways.

THANK YOU VERY MUCH!