Need help with RESTful sensor and HTTP

Requesting recommendations and assistance using the RESTful sensor. I’ve reviewed the RESTful docs and am struggling with understanding and how to use this. I’m not a developer or programmer but am familiar with HA used with an RPi 3 & 4.

I have an optical sensor that counts people. It is capable to count adults and children entering and exiting. The typical application is mounting the sensor overhead above a doorway and count people entering and exiting. The sensor has an API that I generate and online developer documentation available if you have account log in credentials.

Attached are three screenshots from the online documentation related to the url needed but I’m not understanding how to craft the yaml language in HA. For now I’m mainly interested in the counting and once I can understand how to get this working I will monitor other attributes.



Here’s two different versions of my code attempting to get the counting data. I’m not getting any errors but it doesn’t seem to be working.

  - platform: rest
    resource: http://customerapis.sensorio.com/key=my_api
    method: GET
    name: "LZR-SIGMA_8"
    value_template: '{{ (value_json["items"][0].measurements | int) }}'
    scan_interval: 900

Another version of code

  - platform: rest
    name: "LZR-SIGMA_9"
    resource: http://customerapis.sensorio.com/
    method: GET
    headers:
      x-access-token: my_api
    scan_interval: 900
    json_attributes_path: "$.measurements"
    json_attributes:
      - Adults_A
      - Adults_B
      - countA
      - countB
      - countAchild
      - countBchild
    value_template: "{{ value_json.measurements.countA }}"

I’d appreciate any help or recommendations.
Thank you,
JD

Try it using the new rest integration. You can create many sensors from the one call to the resource with this. Unlike the restful platform that requires a call for each of the sensors you create. This will cut down the chance of any API limit being exceeded or reduce your need to create template sensors if you grab all the measurements at once as attributes.

You need to add the device id in the resource and put your key in the headers:

rest:
  - resource: http://customerapis.sensorio.com/api/v1/devices/YOUR_DEVICE_ID_HERE/data
    headers: 
      x-API-Key: YOUR_KEY_HERE
      Content-Type: application/json # May not be required
    sensor:
      - name: "LZR-SIGMA_8 Count A"
        value_template: "{{ value_json.measurements[0].countA }}"
      - name: "LZR-SIGMA_8 Count B"
        value_template: "{{ value_json.measurements[0].countB }}"
      - name: "LZR-SIGMA_8 Count Child A"
        value_template: "{{ value_json.measurements[0].countAChild }}"
      - name: "LZR-SIGMA_8 Count Child B"
        value_template: "{{ value_json.measurements[0].countBChild }}"

I may not have the path to the values correct in the value_templates. You can use this tool to check:

https://jsonpathfinder.com/

Paste your example data in the left hand column and drill down to the measurement you want in the right hand column. The path is at the top of the right hand column (replace “x” with “value_json”).

Thank you for the recommendation…

I don’t believe the one call to the source is viable since there are already many DEVICE_ID’s created that are used in other aspects. Therefore, the DEVICE_ID and KEY would be required for each optical sensor which has it’s own ability to count adults entering and exiting.

The device (optical sensor in this case) already has these four attributes of counting adults and children and I believe it’s needed to call for a count at a given interval (scan_interval) in order to update the count as needed.

Each DEVICE_ID has it’s own API_KEY with these four attributes and more but for now the only interest is the counting aspect.

It’s my understanding if I can get one DEVICE_ID with its API_KEY working then I should be able to get the four counting attributes and then display these counts.

Thanks again for your time to look at this!

This is the first time you have mentioned multiple devices. It helps if you include all the relevant information in your question.

All that means is now you will be making one resource call to each device to get the multiple sensors from each (A, B Child A, Child B) in one go.

So what I wrote is still relevant.

Like this:

rest:
  - resource: http://customerapis.sensorio.com/api/v1/devices/YOUR_DEVICE_ID_HERE/data
    headers: 
      x-API-Key: YOUR_KEY_HERE
      Content-Type: application/json # May not be required
    sensor:
      - name: "LZR-SIGMA_8 Count A"
        value_template: "{{ value_json.measurements[0].countA }}"
      - name: "LZR-SIGMA_8 Count B"
        value_template: "{{ value_json.measurements[0].countB }}"
      - name: "LZR-SIGMA_8 Count Child A"
        value_template: "{{ value_json.measurements[0].countAChild }}"
      - name: "LZR-SIGMA_8 Count Child B"
        value_template: "{{ value_json.measurements[0].countBChild }}"
 - resource: http://customerapis.sensorio.com/api/v1/devices/YOUR_2ND_DEVICE_ID_HERE/data
    headers: 
      x-API-Key: YOUR_2ND_KEY_HERE
      Content-Type: application/json # May not be required
    sensor:
      - name: "LZR-SIGMA_8 Count A2"
        value_template: "{{ value_json.measurements[0].countA }}"
      - name: "LZR-SIGMA_8 Count B2"
        value_template: "{{ value_json.measurements[0].countB }}"
      - name: "LZR-SIGMA_8 Count Child A2"
        value_template: "{{ value_json.measurements[0].countAChild }}"
      - name: "LZR-SIGMA_8 Count Child B2"
        value_template: "{{ value_json.measurements[0].countBChild }}"
 - resource: http://customerapis.sensorio.com/api/v1/devices/YOUR_3RD_DEVICE_ID_HERE/data
    headers: etc...