Custom Component: Discord status and game sensor

Absolutely amazing mate!! Thank you!

[edit] Unrelated to LordBoos’ component, but I’ve found that when asleep, docked and connected via wired ethernet, Switch sysmodules (including Discord presence) remain active for at least 12 hours and presumably indefinitely. This causes issues with using presence or other sysmodules to detect the sleep/awake state accurately. I’m working around this by disabling “display home menu as a status” closing the game and exiting to Home when I’m done playing, but this is a bit of a pain since I can’t leave games suspended. If anyone knows a better solution please let me know :slight_smile:

Many thanks for the integration @LordBoos

Can anyone advise me how to write a automation to trigger the game server to start when a server member starts a game and close if every ones out for an hour. So far i’ve for the below which gets it started. Issue is ark server uses 30% of my RAM and i want to run a similar setting for factorio. The switch is via MQTT to unraid.

- alias: "ark on"
  trigger:
    - platform: state
      entity_id: sensor.discord_gruff_mumeen_0004 #me
      attribute: game
      to: ark
    - platform: state
      entity_id: sensor.discord_ #freind1
      attribute: game
      to: ark
    - platform: state
      entity_id: sensor.discord_ #freind2
      attribute: game
      to: ark
    - platform: state
      entity_id: sensor.discord_ #freind3
      attribute: game
      to: ark
    - platform: state
      entity_id: sensor.discord_ #freind4
      attribute: game
      to: ark
  action:
    service: switch.turn_on
    entity_id: switch.storage_docker_arksurvivalevolved

New version 4.0.1 has just been released with new features and breaking changes, so be wary when updating.

WARNING breaking changes:

  • Changed entity_id to sensor.discord_user_{discord_user_id}
    • This ID cannot be changed by user so it will not change even if user changes his username
    • This will break your lovelace configuration and custom template sensors using this integration
  • You can now only add users using their unique Discord User ID
    • Due to internal changes, support for adding user’s using their username has been removed
    • See README.md or info.md to find out how to get user’s Discord User ID (it’s easy)

New additions:

  • Added unique_id to entities
    • This will enable HA UI for discord_game entities

New attributes:

  • User ID
    • Discord user’s static unique ID
  • User name
    • Discord user’s global user name
  • Display name
    • Discord user’s name on the same server as the bot is
    • This name is the same as user name unless the user changed his nickname on the server with the bot
  • Roles
    • Discord user’s roles on the same server as the bot is
    • By default, every user has role @everyone as a first role

New voice related attributes:

  • Voice channel
    • Name of the voice channel the user is currently connected to
  • Voice server deafened
    • True/False value indicating if user is server deafened
  • Voice server muted
    • True/False value indicating if user is server muted
  • Voice self deafened
    • True/False value indicating if user is self deafened
  • Voice self muted
    • True/False value indicating if user is self muted
  • Voice streaming
    • True/False value indicating if user is currently streaming in a voice channel using Go Live
  • Voice broadcasting video
    • True/False value indicating if user is currently broadcasting video (webcam)
  • Voice afk
    • True/False value indicating if user is currently in the servers AFK voice channel

Had this working a dream before this recent update. Tried to fix it by uninstalling, reinstalling, double checking my config.yaml but my discord sensors are now nowhere to be seen.

I have the following in my sensors.yaml, where it was before (when it worked). With the recent update I changed the members from “MyUsername#4566” etc to the numbers below using the method outlined in the readme.

  - platform: discord_game
    token: MuB7YoiuODgwNzcxNDI0MjU5.DJ9nXT.xxxxxxxxxxxxxxxxxxxxxxxxxx
    image_format: png
    members:
      - 328564250712385589
      - 284111892916165367
      - 800690717812724495

I cannot see any errors in HA logs and I am running v4.0.3 in HACS

Any advice would be really appreciated as I have quite a number of automations using discord

Entity IDs have changed, please check your entities for new ones.

Thanks for the quick response. I also tried searching “discord” in my entities and could not find anything (apart from the automations I set up using that word)

Thank you for a cool component @LordBoos!

Any suggestions to how to get game images? Is this depending on the game or some setting in Discord? I am using it on PC/Windows.

Thanks again.

game: Days Gone
game_state: null
game_details: null
game_image_small: null
game_image_large: null
game_image_small_text: null
game_image_large_text: null

AFAIK the images are only available if the game is using Discord Rich Presence. I will check it again to see if there were any API changes, but no promises.

@oyvindhauge Turns out it is possible. I’ve released version 4.1.0 which adds images for most (bot not all) games. If the game has icon on Discord, it should show up in sensor.

1 Like

Great! Than you very much for a fast reply. Is there something I need to do (except updating to 4.1.0)? I do unfortunately not see any images/ulrs to images. I could be unlucky as I have just tested three games (Apex, Days Gone and Zombie Army 4). Apex does appear to have an icon in Discord:

image

Thanks again for a cool custom component :slight_smile:

From those 3 games only Apex Legends should work.
You can check by searching at this Discord API json: https://discordapp.com/api/applications/detectable
I’ve not tested Apex Legends personally though.
Image URL should be filled to “Game image small” attribute of discord_game sensor.
Can you enable debug log level for discord_game and see if there are any "FOUND app = " messages from discord_game?
To enable debug level, just change your logger config in HA configuration.yaml to

logger:
  default: info
  logs:
    custom_components.discord_game: debug
1 Like

Hi and thanks again.

It is working when I start the game using Origin, but not when I start it using Steam. When using Steam, I find no log entries. When using Origin I find the following:

2021-07-17 16:50:51 DEBUG (MainThread) [custom_components.discord_game.sensor] FOUND app = {'description': '', 'executables': [{'is_launcher': False, 'name': 'apex/r5apex.exe', 'os': 'win32'}], 'guild_id': '541484311354933258', 'hook': True, 'icon': '7564e6f23704870d70480f172f127677', 'id': '542075586886107149', 'name': 'Apex Legends', 'publishers': [{'id': '542075586886107157', 'name': 'Electronic Arts, Inc.'}], 'summary': '', 'third_party_skus': [{'distributor': 'origin', 'id': None, 'sku': None}], 'verify_key': '09ec3fea255d2f025b9b8aaa3aa39446d2428524830803d020483d628f06065c'}
2021-07-17 16:50:51 DEBUG (MainThread) [custom_components.discord_game.sensor] FOUND app = {'description': '', 'executables': [{'is_launcher': False, 'name': 'apex/r5apex.exe', 'os': 'win32'}], 'guild_id': '541484311354933258', 'hook': True, 'icon': '7564e6f23704870d70480f172f127677', 'id': '542075586886107149', 'name': 'Apex Legends', 'publishers': [{'id': '542075586886107157', 'name': 'Electronic Arts, Inc.'}], 'summary': '', 'third_party_skus': [{'distributor': 'origin', 'id': None, 'sku': None}], 'verify_key': '09ec3fea255d2f025b9b8aaa3aa39446d2428524830803d020483d628f06065c'}

I then get the following result in the sensor:

I guess that the Steam version is not recognized the same way as the Origin version.

Ok I’ve found that there is indeed a difference when the game is launched from Steam or from Origin. Discord has different application ids for those 2 and one is in the list, while second isn’t. I’ve fixed a bug where “Search by game name” function was only called when the game had application_id in Discord, so It will now work for you.
Also I’m now developing much more better version which will load images from Steam, not icons tho, but many more images. Basically those images you can see here in the Web assets cell: https://steamdb.info/app/1172470/info/

1 Like

I’ve just released a new version 4.2.0. This version contains fix for issue that sometimes game icons from Discord were not loaded properly.
This version also adds loading of game images from Steam.
Changelog:

  • Fixed game images sometimes not loading from Discord
  • Added game images loading from Steam, new attributes are following:
    • game_image_capsule_231x87
      game_image_capsule_467x181
      game_image_capsule_616x353
      game_image_header
      game_image_hero_capsule
      game_image_library_600x900
      game_image_library_hero
      game_image_logo
      game_image_page_bg_raw
    • Not all games have all the images, only those existing for the game will show up
    • This will mostly only work for games available on Steam, but there are exceptions. Eg. I’ve tested League of Legends and surprisingly Steam have some of the images available for it (even though those images are extremely outdated)
    • Games are loaded from Steam by name, generally this should work reliably, but in some cases where there are 2 or more games with the same name, wrong images may be shown. This is a limitation I’m not able to fix.
1 Like

Wow, this is great, this is just what I was looking for, I will test later!

Thanks for your great work! :slight_smile:

Do you know why I’m able to see only status about myself and all other users have status unknown ?

I’m not sure. Have you enabled PRESENCE INTENT and SERVER MEMBERS INTENT for your bot in Discord developer portal? And are you sure that you have correct User IDs set up for your other users? Also those users have to be present in the same server as the bot.

Oh yes, they’re not in my server. That will be problem, thanks.

This component is great! I have it configured properly and see all the info on my sensors when viewing the States pages under Developer Tools in HA. However, I’m not sure how to best to add this to Lovelace. Can someone point me in the general direction? Sorry- new to HA in general. Should I be looking at creating a template or something along those lines?

is there a lovelace card for this?