Steam sensor - game detection?

I’ve set up the Steam component and it creates sensor.steam_ with the state online/offline as well as the profile name and entity_picture, but it seems like the component is also supposed to detect what game is being played and I can’t figure out how to fetch that data.

{{ states.sensor.steam_id.attributes.game }} returns blank in dev/template, and the status remains ‘online’ even if I launch a game.

I’ve checked my Steam profile settings and changed it all to public in case that was the issue, but still no dice.

I’m playing around with this, too. If you open a Steam game and then Alt+Tab out of it and go to HA, the sensor displays the game you’re playing. The attribute is called ‘game’.

I came here looking for answers, but I found questions :slight_smile:
If I figure it out, I’ll let you know.

I got it to work. I have a normal Steam sensor that tells me the online/offline status of my account. Then I created a template sensor that ‘senses’ the ‘game’ attribute of the first sensor.

Hope this helps anyone.

sensor:
  # Steam
  - platform: steam_online
    api_key: !secret steam_apikey
    accounts:
      - My-Account-ID
  
  # Current Steam game  
  - platform: template
    sensors:
      steam_game:
        friendly_name: "Game"
        value_template: "{{ states.sensor.steam_My-Account-ID.attributes.game }}"
3 Likes

Did you got this to work? I’ve tried the game sensor but i just receive a blank output. The online/offline sensor works just fine. But how do you got the game sensor to work - and/or is it still working? :slight_smile:

I have it up running, Rasser. Same method as above. It should work for you too.

Sorry for the late reply. Yeah, it still works like a charm. Here’s my code:

  # Steam
  - platform: steam_online
    api_key: !secret steam_apikey
    accounts:
      - <<redacted>>
  
  # Current Steam game  
  - platform: template
    sensors:
      steam_game:
        friendly_name: "Game"
        value_template: "{{ states.sensor.steam_<<redacted>>.attributes.game }}"
1 Like

Is it possible to have two platform sensors, for my littlebrothers account, so I can see what he’s playing also? I can only get one to work?

And another question:

Can some one help me build an automation for this game attribute?
Like when I start playing CS:GO, the lights in the living room will turn off?

Thanks!

Sure, you should be able to set up multiple accounts like so:
(I’m writing off the top of my head so I might have messed something up)

sensors.yaml:

# Steam Account Setup 
- platform: steam_online
  api_key: !secret steamkey
  accounts:
    - [account 1]
    - [account 2]

# Current Steam game (account 1)
- platform: template
  sensors:
    steam_game1:
      friendly_name: "Game"
      value_template: "{{ states.sensor.steam_account1.attributes.game }}"

# Current Steam game (account 2)
- platform: template
  sensors:
    steam_game2:
      friendly_name: "Game"
      value_template: "{{ states.sensor.steam_account2.attributes.game }}"

automations.yaml:

trigger:
  platform: state
  entity_id: steam_game1
  to: 'Counterstrike: Global Offensive' [you'll have to check the exact name]
1 Like

Thank you very much poebae!

But I can’t get the automations to work:

- alias: Playing Counter Strike Global Offensive
  trigger:
    platform: state
    entity_id: steam_game_1
    to: 'Counter Strike: Global Offensive'
  action:
    service: light.turn_off
    data:
      entity_id:
        - light.vindueslampe
        - light.lselampe
        - light.sofalampe
        - light.skrivebordslampe

What am I doing wrong?

Firstly, are your Steam sensors giving the correct readings? If so, the only thing I can see wrong is that you don’t need the "data: " part of the action.

Just use:

service: light.turn_off
entity_id:
  - light1
  - light2
  - etc

While you’re at it, I might suggest an automation to turn the lights back on when you quit the game:

You should be able to do that with:

trigger:
  platform: state
  entity_id: sensor.steam_game_1
  to: ''

I get an error on the automation, if I don’t set the ‘game’ attribute on the entity_id like this:
entity_id: steam_game_1.game

The error:
- Invalid config for [automation]: Entity ID steam_game_1 is an invalid entity id for dictionary value @ data['trigger'][0]['entity_id']. Got None. (See /config/configuration.yaml, line 69). Please check the docs at https://home-assistant.io/components/automation/

Do you know why?
I have written the game name exactly as it shows when im launching it, Counter-Strike: Global Offensive.

Im so stupid :blush:

I needed to add sensor in front of steam_game_1…
sensor.steam_game_1 did the job.

Thank you very much for the help!

Sorry, silly mistake. It should be sensor.steam_game_1 :slight_smile:

1 Like

Ahh nice, you got there a second before me :slight_smile: no problem!

Steam sensors gives the following errors today:

Logger: homeassistant.helpers.entity
Source: components/steam_online/sensor.py:137
First occurred: 8:55:38 PM (16 occurrences)
Last logged: 9:10:50 PM

Update for sensor.steam_xxxxxxxxxxxxxxxxxxx fails
Update for sensor.steam_xxxxxxxxxxxxxxxxxxx fails
Update for sensor.steam_xxxxxxxxxxxxxxxxxxx fails
Update for sensor.steam_xxxxxxxxxxxxxxxxxxx fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/steam/api.py", line 153, in download
    timeout=self._timeout)
  File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/local/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/local/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 476, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/steam_online/sensor.py", line 111, in update
    self._game = self._get_current_game()
  File "/usr/src/homeassistant/homeassistant/components/steam_online/sensor.py", line 137, in _get_current_game
    game_id = self._profile.current_game[0]
  File "/usr/local/lib/python3.7/site-packages/steam/user.py", line 171, in current_game
    obj = self._prof
  File "/usr/local/lib/python3.7/site-packages/steam/user.py", line 197, in _prof
    res = self._api["response"]["players"]
  File "/usr/local/lib/python3.7/site-packages/steam/api.py", line 220, in __getitem__
    return self.__handle_accessor("__getitem__", *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/steam/api.py", line 200, in __handle_accessor
    self.call()
  File "/usr/local/lib/python3.7/site-packages/steam/api.py", line 242, in call
    data = self._downloader.download()
  File "/usr/local/lib/python3.7/site-packages/steam/api.py", line 171, in download
    raise HTTPError("Server connection failed: {0} ({1})".format(reason, code))
steam.api.HTTPError: Server connection failed: Forbidden (403) 

Same to me. I got error about Unavailable service.
I found only this git pull about issue https://github.com/home-assistant/core/pull/23941

If you’re interested in showing steam profiles or a friends list, you can use my steam card!
It shows the now playing image and data from the sensor, or a list of steam integrations for a friend list.



1 Like

thanks for this card, is there a way to get the second screen over the third?

Posting here since it’s others with the same interest as me :slight_smile:

Steam status has been very problematic lately, it seems it’s working for a few days, then you get more and more “unavailable” status, before it just shuts down completely. Has Steam made some changes to their API so that they are throttling 3rd party integrations, or is there some other issue?

I have about 25 accounts on my Steam list where I show status, and it’s worked perfectly fine for a very long time, but now a month or so ago it just started giving a lot of issues. Has anyone of you seen this same issue, and/or have you seen a possible fix for it?