Hello everyone,
I’ve just created a custom REST sensor for monitoring the occupancy of fitness studios of the german fitness studio XTRAFIT directly within Home Assistant.
This setup allows you to track the occupancy of your selected gym as a percentage. The API is queried every 5 minutes and the sensor directly calculates the occupancy using a simple template.
Configuration
- sensor:
- platform: rest
name: Fitnessstudio Auslastung
resource: https://exerp.xtrafit.de/api/centers/capacity
method: GET
scan_interval: 300
json_attributes_path: "$.capacityInfos[?(@.centerId==YOUR_CENTER_ID)]"
json_attributes:
- centerId
- currentlyCheckedInCount
- maximumAllowedCheckedIn
- numberOfAvailableSpots
- webName
value_template: >-
{% set center = value_json.capacityInfos | selectattr('centerId', 'eq', YOUR_CENTER_ID) | list | first %}
{% if center and center.maximumAllowedCheckedIn | int > 0 %}
{{ (center.currentlyCheckedInCount | int / center.maximumAllowedCheckedIn | int * 100) | round(0) }}
{% else %}
0
{% endif %}
unit_of_measurement: "%"
icon: mdi:weight-lifter
How to change your location
- Replace
YOUR_CENTER_ID
with the ID of your desired gym. - You can find the available IDs here: https://exerp.xtrafit.de/api/centers/capacity.
Example: Wiesbaden Hauptbahnhof (ID: 260)
- sensor:
- platform: rest
name: Fitnessstudio Auslastung Wiesbaden
resource: https://exerp.xtrafit.de/api/centers/capacity
method: GET
scan_interval: 300
json_attributes_path: "$.capacityInfos[?(@.centerId==260)]"
json_attributes:
- centerId
- currentlyCheckedInCount
- maximumAllowedCheckedIn
- numberOfAvailableSpots
- webName
value_template: >-
{% set center = value_json.capacityInfos | selectattr('centerId', 'eq', 260) | list | first %}
{% if center and center.maximumAllowedCheckedIn | int > 0 %}
{{ (center.currentlyCheckedInCount | int / center.maximumAllowedCheckedIn | int * 100) | round(0) }}
{% else %}
0
{% endif %}
unit_of_measurement: "%"
icon: mdi:weight-lifter
Let me know what you think!