michel72
(Michel - espthings.io)
November 1, 2020, 9:35am
1
Hi,
I’m stying to get multiple sensors from 1 rest call as the API of my device does not seem to like multiple calls to it’s API
Right now I have configured this:
The rest call http://192.168.207.98/getParameters replies with:
{"type":"parameters","list":[{"vehicleState":2,"evseState":false,"maxCurrent":20,"actualCurrent":18,"actualPower":0,"duration":0,"alwaysActive":false,"lastActionUser":"","lastActionUID":"","energy":0,"mileage":0,"meterReading":0,"currentP1":0,"currentP2":0,"currentP3":0}]}
sensor:
- platform: rest
name: EVSE Vehicle state
resource: http://192.168.207.98/getParameters
value_template: "{{ value_json.list[0].vehicleState }}"
method: GET
timeout: 30
force_update: true
- platform: rest
name: EVSE state
resource: http://192.168.207.98/getParameters
value_template: "{{ value_json.list[0].evseState }}"
method: GET
timeout: 30
force_update: true
- platform: rest
name: EVSE Actual current
resource: http://192.168.207.98/getParameters
value_template: "{{ value_json.list[0].actualCurrent }}"
unit_of_measurement: "A"
method: GET
timeout: 30
force_update: true
How could I combine those 3 (or preferably all parameters) into one call?
You can use json_attributes to add other values to attributes in one sensor and then use template sensors for them.
1 Like
michel72
(Michel - espthings.io)
November 1, 2020, 10:19am
3
Thanks, I found this in another topic, and tried to get it to work for my specific use case, but sofar no luck. Do you have an example for my sensors maybe?
sensor:
- platform: rest
name: csensor
resource: http://10.161.0.130:2001/sensors
json_attributes:
- temperature
- humidity
- battery
- timestamp
- platform: template
sensors:
temperature:
value_template: '{{state.sensor.csensor.bedroom1.attributes["temperature"]}}'
tom_l
November 1, 2020, 10:32am
4
Specify a json attributes path.
sensor:
- platform: rest
name: csensor
resource: http://10.161.0.130:2001/sensors
json_attributes_path: $.list[0]
json_attributes:
- currentP1
- currentP2
- currentP3
- etc...
michel72
(Michel - espthings.io)
November 1, 2020, 10:43am
5
Thank you. That was it:
sensor:
- platform: rest
resource: http://192.168.207.98/getParameters
name: evse
value_template: 'OK'
json_attributes_path: $.list[0]
json_attributes:
- vehicleState
- evseState
- maxCurrent
- actualCurrent
- actualPower
- duration
- alwaysActive
- lastActionUser
- lastActionUID
- energy
- mileage
- meterReading
- currentP1
- currentP2
- currentP3
- platform: template
sensors:
evse_vehiclestate:
value_template: "{{ state_attr('sensor.evse', 'vehicleState') }}"
stanekl
(Lukas Stanek)
May 3, 2022, 5:51pm
6
Hello,
I am trying to read multiple sensors for 1 rest call. It works when I do one rest call to get one sensor via value_json.list[28]. How could I make more sensors it they only differ by number in [ ]?
Thank you for your help
tom_l
May 3, 2022, 10:59pm
7
Use the new rest integration.
rest:
- authentication: basic
username: "admin"
password: "password"
scan_interval: 60
resource: http://192.168.1.12/status.xml
sensor:
- name: "Sensor 1"
value_template: "{{ value_json.list[28] }}"
- name: "Sensor 2"
value_template: "{{ value_json.list[29] }}"
- name: "Sensor 3"
value_template: "{{ value_json.list[30] }}"
etc...
1 Like
For anyone looking here’s my setup for the following json response:
{
"bedroom_shades": {
"state": 0,
"position": 0,
"tilt_position": 0
},
"kitchen_door_blinds": {
"state": 0,
"position": 100,
"tilt_position": 0.0
},
"bedroom_blinds": {
"state": 0,
"position": 0,
"tilt_position": 100.0
},
"living_room_door_blinds": {
"state": 0,
"position": 0,
"tilt_position": 64.44444
}
}
The sensor configuration is as follows:
rest:
- resource: http://192.168.0.123/getState
scan_interval: 30
method: GET
verify_ssl: false
headers:
accept: "application/json"
content-type: "application/json"
payload: '{ "type": "get" }'
sensor:
- name: "bedroom_blinds"
value_template: "OK"
json_attributes_path: "$.['bedroom_blinds']"
json_attributes:
- position
- state
- tilt_position
- name: "bedroom_shades"
value_template: "OK"
json_attributes_path: "$.['bedroom_shades']"
json_attributes:
- position
- state
- tilt_position
- name: "kitchen_door_blinds"
value_template: "OK"
json_attributes_path: "$.['kitchen_door_blinds']"
json_attributes:
- position
- state
- tilt_position
- name: "living_room_door_blinds"
value_template: "OK"
json_attributes_path: "$.['living_room_door_blinds']"
json_attributes:
- position
- state
- tilt_position
And I can see correct data in Developer tools
tom_l
July 26, 2023, 10:07am
9
You should use the value_template for the state, rather than just printing the text “OK” no matter wat at.