Nuki - json - scanResults - multiple - problem

Hello,

I have a problem, I try to download data using:

  - platform: rest
    scan_interval: 25 
    resource: !secret nuki_info
    name: "NUKI status"
    value_template: "{{ value_json['scanResults'][0]['paired'] }}"
    json_attributes_path: "$.scanResults[0]"
    json_attributes:
      - rssi

from the link it looks like this:

{"bridgeType": 1, "ids": {"hardwareId": xxxxxxx, "serverId": xxxxxxxx}, "versions": {"firmwareVersion": "1.21.0", "wifiFirmwareVersion": "1.2.0"}, "uptime": 428, "currentTime": "2022-05-14T08:55:11+00:00", "serverConnected": true, "scanResults": [{"deviceType": 0, "nukiId": xxxxxxxxx, "name": "Nuki_xxxxxxxx", "rssi": -78, "paired": true}, {"deviceType": 0, "nukiId": xxxxxxxx, "name": "Nuki_xxxxxxxx", "rssi": -77, "paired": true}]}

i would like to get the second rssi value. How to do it?

Value change from

value_template: "{{ value_json['scanResults'][0]['paired'] }}"

on

value_template: "{{ value_json['scanResults'][1]['paired'] }}"

it gives nothing because there is one scanResults value but there are two paired.

How to do it

That’s not valid json.

I downloaded from here:
https://community.home-assistant.io/t/nuki-smart-lock-2-0-support-all-available-api-actions-i-e-add-lock-unlock/93079/79

It works and downloads, but only the first rssi, I can’t get it to download the second.

It works because we have the second value “lastKnownState”

  - platform: rest
    scan_interval: 13 # for constant polling to avoid draining the batteries too fast.(?)
    resource: http://xx.xx.xx.XXX:XXXX/list?token=XXXXXXXX # cache in bridge
    name: "NUKI Porta Estado"
    value_template: "{{ value_json[0]['lastKnownState']['stateName'] }}"
    json_attributes_path: "$[0].lastKnownState"
    json_attributes:
      - batteryCritical
      - batteryChargeState
      - timestamp
      

If you paste the formatted valid json from the resource I can help.

But how? after entering the website:
http://192.168.10.30:8080/list?token=xxxxxx(token)

I only have what I wrote.

I see why. You changed it. You replaced a bunch of numbers with xxxxxxx which aren’t numbers. That’s why it was not valid.

So after fixing that I can use this https://jsonpathfinder.com/ to find the paths to the data you want. Using the rest integration, instead of the rest sensor platform, you can have as many sensors as you want from the one call to the resource. No template sensors or messy attributes required.

rest:
  - resource: !secret nuki_info
    scan_interval: 25
    sensor:
      - name: "RSSI 1"
        value_template: "{{ value_json.scanResults[0].rssi }}"
        device_class: signal_strength
      - name: "RSSI 2"
        value_template: "{{ value_json.scanResults[1].rssi }}"
        device_class: signal_strength

You can add as many sensors as you want to this and they will all update after one call to the resource. Probably important considering your scan interval.

Keep in mind that this goes in your configuration.yaml file. Not your sensors.yaml file. It’s a new integration.

You can put it in another file (e.g. restful_sensors.yaml) by using an include in your configuration.yaml file like this:

rest: !include restful_sensors.yaml

You are genius!
It works.
Thank you for your help.

1 Like