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
This component will set up the following platforms.
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
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
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'
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
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?