Skip to content

Instantly share code, notes, and snippets.

@Komzpa
Created June 30, 2024 21:37
Show Gist options
  • Save Komzpa/396e66fb99592c14ba88e1bca21c11eb to your computer and use it in GitHub Desktop.
Save Komzpa/396e66fb99592c14ba88e1bca21c11eb to your computer and use it in GitHub Desktop.
Support for Aquara FP2 Sleep sensor using REST in Home Assistant
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
@Komzpa
Copy link
Author

Komzpa commented Jun 30, 2024

How to use:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment