Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106537

Extracting multiple sensors using RESTful Sensor

$
0
0

G’day!

This is my post here and I really hope it doesn’t repeat a question already asked.

I am trying to setup multiple sensors using RESTful Sensor, after reading here that

Tip: If you want to create multiple sensors using the same endpoint, use the RESTful configuration instructions.

The structure of the data that I have incoming is a list of sensors:

{
    "status": "success",
    "time": 0.04,
    "flags": {},
    "data": [
        {
            "id": 100809,
            "label": "play area",
            "device_id": 13489,
            "temperature": 21.0
        },
        {
            "id": 100819,
            "label": "dining area",
            "device_id": 13589,
            "temperature": 22.5
        },
        {
            "id": 100821,
            "label": "guests room",
            "device_id": 13591,
            "temperature": 20.5
        }
     ]
}

I can easily setup all these sensors individually, but then I will need to manually walk them one at a time, generating more than 20 queries (for all the 20 sensors I’ve got) which will be very inefficient and quickly drain my daily quota of 500 API calls per day.

I am a bit confused if the RESTful sensor is the way to go here and if so - can someone help with the syntax as I am a little bit confused on how to make this work.

Here is what I have tried so far for only one of the sensors, but it doesn’t seem to be working


rest:
  resource: 'https://mihome4u.co.uk/api/v1/subdevices/list'
  method: GET
  authentication: basic
  username: !secret ACCOUNT
  password: !secret PASS

  headers:
    Content-Type: application/json
  scan_interval: 67

  sensor:
    - name: "Guest Room"
      unique_id: 100821
      device_class: temperature

      #unit_of_measurement: '°C'
      json_attributes_path: ".data[] |  select(.id == 100821)"
      # json_attributes_path: "json_attributes_path: "$..[?(@.id=='100821')]""
      value_template: "{{ value_json[0].temperature }}"
      json_attributes:
        - id
        - label
        - device_id
        - power_state
        - startup_mode
        - device_type
        - remote_id
        - target_temperature
        - voltage
        - voltage_reported_at
        - updated_at
        - last_temperature

I hope this makes sense and thanks in advance

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 106537

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>