Failing to read correct state from RESTful sensor

Sorry if the title is too vague.

I want to read the status of my alarm system using the provider API. I am getting a response but am not able to isolate the specific value of “areas” they are returning.

“areas” can have a value of ‘armed’, ‘stay’, ‘sleep’, ‘notready’, etc.

I’ve set up a RESTful sensor in my config as below

sensor:
  - platform: rest
    name: getolarmstatus
    json_attributes_path: "$.data.[0].deviceState"
    json_attributes:
      - "areas"
    value_template: "{{ value_json.areas }}"
    resource: https://apiv4.olarm.co/api/v4/devices
    method: GET
    headers:
      Authorization: xxxx
    scan_interval: 300

Below is excerpt from what I am getting back

{
   "page":1,
   "data":[
      {
         "deviceState":{
            "timestamp":1668776375391,
            "cmdRecv":0,
            "type":"",
            "areas":[
               "stay"
            ],
            "areasDetail":[
               ""
            ]
         }
      }

In the example above I want to isolate just the value “stay”.

Going to Developer Tools

{{ states.sensor.getolarmstatus }}

shows

<template TemplateState(<state sensor.getolarmstatus=; areas=['stay'], friendly_name=getolarmstatus @ 2022-11-18T15:06:37.142418+02:00>)>

I’ve tried drilling down further but suspect I’m not fully understanding how it works

{{ states.sensor.getolarmstatus.areas }}
{{ states.sensor.getolarmstatus.areas[0] }}

does nothing

I’m running Home Assistant 2022.11.2, Supervisor 2022.10.2

Try:

sensor:
  - platform: rest
    name: getolarmstatus
    value_template: "{{ value_json.data[0].deviceState.areas[0] }}"
    resource: https://apiv4.olarm.co/api/v4/devices
    method: GET
    headers:
      Authorization: xxxx
    scan_interval: 300
2 Likes

I’ve spent more hours on this than I would like to admit, but never considered removing the json_attributes and _path.

Thank you @Briggy

1 Like