Value template from a response variable

I expect this is probably really simple but i’m not very good at templating and would appreciate it if anyone can help me? I have a REST API command that works and returns a bunch of info (example of the returned data is below). My automation runs the rest command with the ‘response_variable’ option enabled (called ‘backup_status’). I need an if / then in the automation to continue if a value template matches the rest data’s ‘total’ value to ‘1’ or fail if the value is not ‘1’ or no value is returned. As a check i’ve tested with a notification with the following line in and it displays ‘1’ correctly so I know the rest command’s response variable is working in the automation:

Backups active: {{ backup_status.content.total }}

What should the line in my value template be to work correctly? Thanks for any help!

Example REST command data returned:
:::::::::
content:
data:
- pid: 557858
upid: “long_boring_upid_removed”
user: my_backup_user
saved: “0”
status: RUNNING
node: my_server
id: “301”
type: vzdump
starttime: 1762292069
pstart: 98470477
total: 1
status: 200
headers:
Cache-Control: max-age=0
Connection: Keep-Alive
Date: Tue, 04 Nov 2025 21:34:32
Pragma: no-cache
Server: pve-api-daemon/3.0
Content-Length: “245”
Content-Type: application/json;charset=UTF-8
Expires: Tue, 04 Nov 2025 21:34:32

If {{ backup_status.content.total }} returns the expected value, then you just need to do a equality comparison:

{{ backup_status.content.total == 1 }}

Thanks that’s one I tried but with the 1 in single or double quotes. Didn’t try it without quotes. I’ll check tmrw :+1:

If you are using it in a automation you most likely need to surround the template in quotes.

If you need further help, please post the actual automation configuration, properly formatted, so we can see what the cause might be.

The YAML will look something like:

- if: "{{ backup_status.content.total == 1 }}"
  then:
    # Do stuff here

You put the whole {{ }} expression in quotes, not the 1.

1 Like

Thanks, the value template is working now with no quotes:

{{ backup_status.content.total >= 1 }}

Previously I kept trying to run it like:

{{ 'backup_status.content.total' >= '1' }}
{{ backup_status.content.total >= '1' }}

One more question. Obviously i’m able to use the ‘total’ value ok, but when I try to use one of the data: sub-values it doesn’t work. E.g. this doesn’t work:

{{ backup_status.content.data.status == RUNNING }}

How might I get and use the status value? Here is the API response data again, formatted better for you:

content:
  data:
    - upid: "<long_boring_ID>"
      pstart: 104757581
      id: "301"
      user: "<my_user>"
      status: RUNNING
      type: vzdump
      starttime: 1762354940
      pid: 892012
      saved: "0"
      node: pve1
  total: 1

That hyphen denotes that the stuff under data is an item in a list. So, you need to select the list item by its index first and use quotes appropriately so you are comparing to a string value…

{{ backup_status.content.data[0].status == 'RUNNING' }}

:+1: Thanks again