Rest sensor help -NAS Plugin

Hi all,
I’m i trying to make a few sensors but I don’t think I’m getting the json path correct or not sure what I’m doing wrong, maybe someone can take a look and help me out.

Here is my sensor:

  - platform: rest
    name: truenas_plugin_sonarr
    resource: "http://192.168.**xxx.xxx**/api/v2.0/plugin/id/sonarr"
    headers:
      Authorization: Bearer 1-**XXXXXXXX**
      Content-type: application/json
      User-Agent: Home Assistant
    scan_interval: 1800
    json_attributes:
      - state

and here is the output of the nas when i run on a terminal:
curl -X GET -H “Authorization: Bearer 1-XXXXX” “http://192.168.xxx.xxx/api/v2.0/plugin”

[
 {
  "jid": 1,
  "name": "Plex",
  "boot": "on",
  "state": "up",
  "type": "pluginv2",
  "release": "12.1-RELEASE-p13",
  "ip4": "epair0b|192.168.XXX.XXX",
  "ip6": null,
  "template": null,
  "doc_url": null,
  "plugin": "plexmediaserver",
  "plugin_repository": "https://github.com/freenas/iocage-ix-plugins.git",
  "category": "entertainment",
  "maintainer": "iXsystems <[email protected]>",
  "id": "Plex",
  "plugin_info": null,
  "admin_portals": [
   "http://192.168.XXX:XXX:32400/web"
  ],
  "version": "1.22.3.4392",
  "revision": "0",
  "epoch": "0"
 },
 {
  "jid": 2,
  "name": "Resolop-SYNC",
  "boot": "on",
  "state": "up",
  "type": "pluginv2",
  "release": "12.1-RELEASE-p13",
  "ip4": "epair0b|192.168.XXX.XXX",
  "ip6": null,
  "template": null,
  "doc_url": null,
  "plugin": "rslsync",
  "plugin_repository": "https://github.com/ix-plugin-hub/iocage-plugin-index.git",
  "category": "content",
  "maintainer": null,
  "id": "Resolop-SYNC",
  "plugin_info": null,
  "admin_portals": [
   "http://192.168.XXX.XXX:8888/"
  ],
  "version": "N/A",
  "revision": "N/A",
  "epoch": "N/A"
 },
 {
  "jid": 3,
  "name": "Transmission",
  "boot": "on",
  "state": "up",
  "type": "pluginv2",
  "release": "12.1-RELEASE-p13",
  "ip4": "epair0b|192.168.XXX.XXX",
  "ip6": null,
  "template": null,
  "doc_url": null,
  "plugin": "transmission",
  "plugin_repository": "https://github.com/ix-plugin-hub/iocage-plugin-index.git",
  "category": "content",
  "maintainer": null,
  "id": "Transmission",
  "plugin_info": null,
  "admin_portals": [
   "http://192.168.XXX.XXX:9091"
  ],
  "version": "3.00",
  "revision": "3",
  "epoch": "0"
 },
 {
  "jid": 7,
  "name": "radarr",
  "boot": "on",
  "state": "up",
  "type": "pluginv2",
  "release": "12.2-RELEASE-p6",
  "ip4": "epair0b|192.168.XXX.XXX",
  "ip6": null,
  "template": null,
  "doc_url": null,
  "plugin": "radarr",
  "plugin_repository": "https://github.com/ix-plugin-hub/iocage-plugin-index.git",
  "category": "content",
  "maintainer": null,
  "id": "radarr",
  "plugin_info": null,
  "admin_portals": [
   "http://192.168.XXX.XXX:7878"
  ],
  "version": "3.0.2.4552",
  "revision": "0",
  "epoch": "0"
 },
 {
  "jid": 5,
  "name": "sonarr",
  "boot": "on",
  "state": "up",
  "type": "pluginv2",
  "release": "12.2-RELEASE-p6",
  "ip4": "vnet0|192.168.XXX.XXX/24",
  "ip6": null,
  "template": null,
  "doc_url": null,
  "plugin": "sonarr",
  "plugin_repository": "https://github.com/ix-plugin-hub/iocage-plugin-index.git",
  "category": "content",
  "maintainer": null,
  "id": "sonarr",
  "plugin_info": null,
  "admin_portals": [
   "http://192.168.XXX.XXX:8989"
  ],
  "version": "3.0.6.1196",
  "revision": "0",
  "epoch": "0"
 }

Thanks For the Help!!

There are multiple “states” and they are each in a different array. Does the below work for you?

  - platform: rest
    name: truenas_plugin_sonarr
    resource: "http://192.168.**xxx.xxx**/api/v2.0/plugin/id/sonarr"
    headers:
      Authorization: Bearer 1-**XXXXXXXX**
      Content-type: application/json
      User-Agent: Home Assistant
    scan_interval: 1800
    json_attributes_path: "$.[0]"
    json_attributes:
      - state

Basically, what Craig says, but you likely want, for “sonarr” specifically:

    json_attributes_path: "$.[?(@.name=='sonarr')]"
1 Like

Nice code there, ive not noticed that before.

Also, OP, if you do want all the sensors for radarr, Transmission etc, you may consider the rest sensor at RESTful - Home Assistant

It will allow you to create multiple sensors under your rest connection.

HI thanks for the help, after implementing the suggestion i got this errors on the logs
JSON result was not a dictionary or list with 0th element a dictionary

11:15:13 AM – (WARNING) RESTful

REST result could not be parsed as JSON

11:15:13 AM – (WARNING) RESTful

Could it be the 255 character limitation?

Yes that’s what I’m am doing, just one by one :grinning: , once I get this one going I can do the rest.

thanks

That’s part of the jsonpath specification: JSONPath Syntax | AlertSite Documentation

I just assume HA supports the full spec, here :wink:

1 Like

That will only work with http://192.168.xxx.xxx/api/v2.0/plugin, with the sample json you provided.

We don’t know what http://192.168.**xxx.xxx**/api/v2.0/plugin/id/sonarr provides, if anything

Hi ,
here are theresults for http://192.168.xxx.xxx/api/v2.0/plugin/id/sonarr

{
 "jid": 5,
 "name": "sonarr",
 "boot": "on",
 "state": "up",
 "type": "pluginv2",
 "release": "12.2-RELEASE-p6",
 "ip4": "vnet0|192.168.XXX.XXX/24",
 "ip6": null,
 "template": null,
 "doc_url": null,
 "plugin": "sonarr",
 "plugin_repository": "https://github.com/ix-plugin-hub/iocage-plugin-index.git",
 "category": "content",
 "maintainer": null,
 "id": "sonarr",
 "plugin_info": null,
 "admin_portals": [
  "http://192.168.XXX.XXX:8989"
 ],
 "version": "3.0.6.1196",
 "revision": "0",
 "epoch": "0"
}

Thanks

Then your initial code, without json_attributes_path, should work.
What error are you getting?

With my code i get nothing
Logs:
Logger: homeassistant.components.rest.sensor
Source: components/rest/sensor.py:177
Integration: RESTful (documentation, issues)
First occurred: 11:42:22 AM (1 occurrences)
Last logged: 11:42:22 AM

REST result could not be parsed as JSON

Strange. Maybe remove those so that the rest call is exactly the same as your curl.

nothing shows up :upside_down_face:

Ah yeah, values are limited to 255 char, and as you don’t specify value_template, the full json is considered as the value.

Try:

  - platform: rest
    name: truenas_plugin_sonarr
    resource: "http://192.168.**xxx.xxx**/api/v2.0/plugin/id/sonarr"
    headers:
      Authorization: Bearer 1-**XXXXXXXX**
      Content-type: application/json
      User-Agent: Home Assistant
    scan_interval: 1800
    value_template: "{{ value_json.state }}"
1 Like

now its showing up but says:
sensor.truenas_plugin_sonarr] unknown

so its getting there :slight_smile:

maybe:
value_template: “{{ value_json[0].state }}”

??

Where does it “show”?
Maybe the “]” is a typo?

yes it was a typo , sorry :grinning:

shows at: Developer Tools / states

Put a screenshot, please