Skip to content

Instantly share code, notes, and snippets.

@fragtion
Created September 24, 2023 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fragtion/26fa89ac47bbf84742dba9264f3c679f to your computer and use it in GitHub Desktop.
Save fragtion/26fa89ac47bbf84742dba9264f3c679f to your computer and use it in GitHub Desktop.
leetify-cs2-stats-home-assistant
sensor:
- platform: rest
name: leetify
resource: https://api.leetify.com/api/profile/76561197990921651 #replace the profile id with your own profile id, from eg: https://api.leetify.com/api/profile/76561197990921651
json_attributes:
- games
- recentGameRatings
value_template: 'OK'
scan_interval: 600
- platform: template
sensors:
leetify_elo:
value_template: >
{% set games = state_attr('sensor.leetify', 'games') %}
{% set last_game = games | max(attribute='gameFinishedAt') %}
{{ last_game.skillLevel if last_game else None }}
leetify_aim:
value_template: "{{ state_attr('sensor.leetify', 'recentGameRatings').aim }}"
leetify_positioning:
value_template: "{{ state_attr('sensor.leetify', 'recentGameRatings').positioning }}"
leetify_utility:
value_template: "{{ state_attr('sensor.leetify', 'recentGameRatings').utility }}"
leetify_clutch:
value_template: "{{ state_attr('sensor.leetify', 'recentGameRatings').clutch }}"
leetify_ctleetify:
value_template: "{{ state_attr('sensor.leetify', 'recentGameRatings').ctLeetify }}"
leetify_tleetify:
value_template: "{{ state_attr('sensor.leetify', 'recentGameRatings').tLeetify }}"
leetify_leetify:
value_template: "{{ state_attr('sensor.leetify', 'recentGameRatings').leetify }}"
leetify_opening:
value_template: "{{ state_attr('sensor.leetify', 'recentGameRatings').opening }}"
leetify_win_rate:
value_template: >
{% set games = state_attr('sensor.leetify', 'games') %}
{% set last_30_games = games | sort(attribute='gameFinishedAt', reverse=true) | list %}
{% set last_30_games = last_30_games[0:30] %}
{% set total_games = last_30_games | length %}
{% set wins = last_30_games | selectattr('matchResult', 'eq', 'win') | list | length %}
{% set ties = last_30_games | selectattr('matchResult', 'eq', 'tie') | list | length %}
{% set losses = last_30_games | selectattr('matchResult', 'eq', 'loss') | list | length %}
{% set win_rate = (((wins + (ties * 0.5)) * 100) / total_games) | round(2) %}
{{ win_rate if total_games > 0 else 0.0 }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment