Created
June 30, 2024 21:37
-
-
Save Komzpa/396e66fb99592c14ba88e1bca21c11eb to your computer and use it in GitHub Desktop.
Support for Aquara FP2 Sleep sensor using REST in Home Assistant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rest: | |
resource: https://rpc-ger.aqara.com/app/v1.0/lumi/res/query | |
method: POST | |
scan_interval: 3 | |
headers: | |
Sys-Type: 1 | |
Appid: FIXME | |
Userid: FIXME | |
Token: FIXME | |
Content-Type: application/json; charset=utf-8 | |
payload: '{"data":[{"options":["heartrate_value","respiration_rate_value","sleep_state","body_movement_value","lux","device_offline_status"],"subjectId":"FIXME"}]}' | |
sensor: | |
- name: aquara_fp2_bed_heartrate_value | |
unique_id: "e080fb23-1aca-4f3f-844e-c715f4a73c20" | |
availability: "{{ is_state('binary_sensor.bedroom_presence_presence_sensor_1', 'on') }}" | |
value_template: "{{ value_json.result[0].value | float }}" | |
unit_of_measurement: "bpm" | |
state_class: "measurement" | |
json_attributes_path: "$.[0]" | |
json_attributes: | |
- attr | |
- value | |
- subjectId | |
- timeStamp | |
- name: aquara_fp2_bed_respiration_rate_value | |
unique_id: "6b6a384d-435a-4d91-9cbb-b1c10d228ff1" | |
availability: "{{ is_state('binary_sensor.bedroom_presence_presence_sensor_1', 'on') }}" | |
value_template: "{{ value_json.result[1].value | float }}" | |
unit_of_measurement: "bpm" | |
state_class: "measurement" | |
json_attributes_path: "$.[1]" | |
json_attributes: | |
- attr | |
- value | |
- subjectId | |
- timeStamp | |
- name: aquara_fp2_bed_sleep_state | |
unique_id: "9283e24a-5a40-4503-aa34-d30f29af0642" | |
value_template: >- | |
{% set sleep_states = { | |
0: 'Out of Bed', | |
1: 'In Bed', | |
2: 'Fully Awake', | |
3: 'REM Sleep', | |
4: 'Light Sleep', | |
5: 'Deep Sleep' | |
} %} | |
{{ sleep_states[value_json.result[2].value | int] }} | |
json_attributes_path: "$.[2]" | |
json_attributes: | |
- attr | |
- value | |
- subjectId | |
- timeStamp | |
- name: aquara_fp2_bed_body_movement_value | |
unique_id: "01440a16-90e0-4408-87fd-c5bda8c81ef3" | |
availability: "{{ is_state('binary_sensor.bedroom_presence_presence_sensor_1', 'on') }}" | |
value_template: "{{ value_json.result[4].value | float }}" | |
state_class: "measurement" | |
json_attributes_path: "$.[4]" | |
json_attributes: | |
- attr | |
- value | |
- subjectId | |
- timeStamp | |
- name: aquara_fp2_bed_lux | |
unique_id: "96e1f524-0da2-4b1f-9a5c-b5ac1c836154" | |
availability: "{{ is_state('binary_sensor.bedroom_presence_presence_sensor_1', 'on') }}" | |
value_template: "{{ value_json.result[5].value | float }}" | |
unit_of_measurement: "lux" | |
state_class: "measurement" | |
json_attributes_path: "$.[5]" | |
json_attributes: | |
- attr | |
- value | |
- subjectId | |
- timeStamp | |
- name: aquara_fp2_bed_device_offline_status | |
unique_id: "e21f6835-943e-40a7-b814-ff9e319e4ab5" | |
availability: "{{ is_state('binary_sensor.bedroom_presence_presence_sensor_1', 'on') }}" | |
value_template: "{{ value_json.result[3].value | float }}" | |
state_class: "measurement" | |
json_attributes_path: "$.[3]" | |
json_attributes: | |
- attr | |
- value | |
- subjectId | |
- timeStamp |
Just in case, the solution above still works for me. May the difference be region-dependent? Yours seems to phone home to kr=Korea, my seems to be in ger=Germany.
Yes my server is Kr
I think the API specs used in my region are different. Thanks for the answer.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is now deprecated.
I captured the API used in my app, and it seems that
https://rpc-ger.aqara.com/app/v1.0/lumi/res/query
no longer works.Instead, the API call is made to
https://rpc-kr.aqara.com/app/v1.0/lumi/res/query/by/resourceId
.I also captured the token and appId to use the retrieved data.
And The format of the data included in the headers is slightly different as well.
API requests call data using resourceIds rather than names. This can be found in the Aqara Developer Console.