[Custom Component] Fortnite Stats Sensor

Fortnite Stats

This ‘fortnite’ component is a Home Assistant custom sensor which shows you various stats accumulated while playing the very popular F2P game, Fortnite: Battle Royale.

Why?

It can show you how well you’re playing the game with stats like:

  • Total kills you’ve earned
  • Kill/Death Ratio
  • Kills Per Game
  • Total Matches Played Per Mode
  • Your Fortnite Score
  • Your Score Earned Per Match
  • Your Win Ratio

And how many times you finish in the:

  • Top 1
  • Top 3
  • Top 5
  • Top 6
  • Top 10
  • Top 12
  • Top 25

Purpose

This is my first Home-Assistant Custom Component, so it’s been a fun learning experience for me contributing to Open Source Software! This wouldn’t been possible without the help from @xcodinas (github username) for building the fortnite-python library and from @clyra for helping refine my initial script and idea by further developing it towards a more finished product. From there I’ve added some extra tweaks, wrote the documentation, and published it in the Home-Assistant Community Store (HACS).

Screenshots

fortnite-stats-overview-kills-screenshot fortnite-stats-solo-screenshot fortnite-stats-duo-screenshot fortnite-stats-squads-screenshot

This component will set up the following platforms.

Platform Description
sensor Show stats pulled from fortnite API on https://fortnitetracker.com

Manual Installation

Download the fortnite.zip file from the latest release. Unpack the release and copy the custom_components/fortnite directory into the custom_components directory of your Home Assistant installation. Configure the fortnite sensor. Restart Home Assistant.

Installation via HACS (Preferred Method)

Ensure that HACS is installed. Search for and install the “fortnite” integration. Configure the fortnite sensor in configuration.yaml . Restart Home Assistant.

Configuration is done in YAML -> configuration.yaml

My username is Captain_Crunch88 and I play on the Nintendo Switch (use “GAMEPAD” in the config) if you want to test out the sensor. You’ll need to register for an api key at https://fortnitetracker.com/site-api

sensor:
  - platform: fortnite
    name: Fortnite Solo Stats
    api_key: 12345678-90ab-cdef-ghij-lmnopqrstuvw
    player_id: Captain_Crunch88
    game_platform: "GAMEPAD"
    game_mode: "SOLO"
  - platform: fortnite
    name: Fortnite Duo Stats
    api_key: 12345678-90ab-cdef-ghij-lmnopqrstuvw
    player_id: Captain_Crunch88
    game_platform: "GAMEPAD"
    game_mode: "DUO"
  - platform: fortnite
    name: Fortnite Squads Stats
    api_key: 12345678-90ab-cdef-ghij-lmnopqrstuvw
    player_id: Captain_Crunch88
    game_platform: "GAMEPAD"
    game_mode: "SQUAD"

If you play on multiple platforms, you’ll need to create multiple sensors for each platform you play on. For example if you play on the PC and Nintndo Switch, you’d use PC in one sensor and GAMEPAD in the other sensor. At this time there is no aggregate sensor, but maybe you can submit a pull request for a Template Sensor in Home Assistant to aggregate it!

Game Platform Config Value (ALL CAPS!)
PC PC
Xbox XBOX
PlayStation PSN
iPad & iPhone TOUCH
Nintendo Switch GAMEPAD
KBM KBM

This custom-component was last tested on version 0.114.4 of Home-Assistant

Contributions are welcome!

If you want to contribute to this please read the Contribution guidelines

2 Likes

Hey

Imay be stupid, but i cant get this to work.
I installed it through HACS, added the example config to configuration.yml
But i get this error in core logs:


2021-05-02 21:07:18 ERROR (MainThread) [homeassistant.components.sensor] fortnite: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 358, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 466, in async_device_update
    await task
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/fortnite/sensor.py", line 80, in update
    self.data.update_stats()
  File "/config/custom_components/fortnite/sensor.py", line 102, in update_stats
    self.stats = self.fplayer.get_stats(self.mode)
AttributeError: 'FortniteData' object has no attribute 'fplayer'

Any ideas ?

Hey thanks for trying it out! It’s my first custom component so there may be some issues, but let’s see if we can get this working for you.

First, have you registered for an api key at https://fortnitetracker.com/site-api ?

The api key in the example config is not an actual api key since there is a limit to the number of requests you can make.

Also, can you provide some details on what version of home assistant you’re running and what platform you play Fortnite on?

Hmm, it seems like i mesed up my Epic name in some strange way, nothing wrong with your code.
I call myself human1344 when playing, but wheni type that name in the searchbox at “https://fortnitetracker.com/” it say: “No profile found” BUT when press enter/search/the little arrow it show stats from the user,really strange.

I tried with my API and your user and it works as it should, nothing wrong with your code/component.

Anyway, here’s what i use:

Running as VM on Proxmox
Home assistant Core: core-2021.2.3
HACS:
  Integration version: 	1.12.3
  Frontend version: 	20210429001005

My configuration.yaml:

# Fortnite
sensor:
  - platform: fortnite
    name: "Fortnite LTM Stats"
    api_key: "<MY_OWN_API>"
    player_id: "human1344"
    game_platform: "PSN"
    game_mode: "SOLO"

And i’m play on PS4.

Hey good job. Is there a way to get the stats for Trios and LTM’s now?

Thanks! I don’t believe so because of the api that’s used to pull the stats doesn’t have it but I’m open to pull requests if you can figure it out!

Anyone who has recently deployed and configured this?
The URL in the documentation to register for an API key does not work.
I’ve registered for an account on the fortnitetracker.com website. The only way to obtain an API key seems to be to create an application. I’ve created a dummy application (called it homeassistant), its status is “Your application for production use has been received and is awaiting review.”.

So far, the homeassistant logs are generating this error:

2024-01-06 17:34:36.773 ERROR (MainThread) [homeassistant.components.sensor] fortnite: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 575, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 961, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/fortnite/sensor.py", line 85, in update
    self.data.update_stats()
  File "/config/custom_components/fortnite/sensor.py", line 107, in update_stats
    self.stats = self.fplayer.get_stats(self.mode)
                 ^^^^^^^^^^^^
AttributeError: 'FortniteData' object has no attribute 'fplayer'

I am not sure if these errors are because of the “pending review” status, or if I am overlooking something else…? Any ideas?

Thanks.

Thanks for looking into this. I haven’t updated this in a few years and I need to find someone else to maintain it :sweat_smile: