Skip to content

Instantly share code, notes, and snippets.

@thatkookooguy
Last active December 25, 2020 06:58
Show Gist options
  • Save thatkookooguy/abc9cf31060ac3672db510ef534b4fe5 to your computer and use it in GitHub Desktop.
Save thatkookooguy/abc9cf31060ac3672db510ef534b4fe5 to your computer and use it in GitHub Desktop.

I did something similar for myself. It should work the same for a group of steam friends if the data is the same (which I guess it is if you're using a steam sensor for each one of them).

I'll just say up-front that this is a lot of setup to get this to happen. But it shouldn't! I plan to make this into a custom HACS card since just getting all this data directly from the steam sensor will be much easier with a custom card. I'll keep you posted when that happens, but I hope this will get you what you want in the meanwhile :slight_smile:

My setup shows the following things (see image for reference):

  • my steam entity without a now playing section when I'm not playing a game
  • a "now playing" section once I start playing a game
  • an hassio notification when I start playing a game

Here's how I set it up:

Integrate Steam

First, you'll need the steam integration. I think you already have that part (for each friend) :slight_smile:

Create Additional Sensors for Steam Now Playing

for every account you want to see an the "now playing" part, you need to create two additional sensors. One for the name of the game, and one for the game picture.

Here's how I set it up:

# Steam Account Integration
- platform: steam_online
  api_key: <api_key>
  accounts:
    - <account_id64>
# Current Steam game+picture for specific account  
- platform: template
  sensors:
    # you'll probably want to prefix the friend's name here to separate them
    steam_now_playing: 
      friendly_name: "Now Playing"
      value_template: "{{ states.sensor.steam_<account_id64>.attributes.game }}"
    steam_now_playing_picture:
      friendly_name: "Now Playing Game Picture"
      value_template: '{% if states.sensor.steam_<account_id64>.attributes.game_image_header is defined %}{{ states.sensor.steam_<account_id64>.attributes.game_image_header }}{% else %}none{% endif %}'

you need to replace the <account_id64> to the steam account id you want to do this for

This will create two new sensors:

  • sensor.steam_now_playing - will hold the game that is currently being played or an empty string if no game is being played atm
  • sensor.steam_now_playing_picture - will hold the game image to display in your UI. This attribute will contain the word 'none' if no game is being played. **This is important in order to hide the Now Playing section in the UI and for the automation so we can filter based on this value.

Creating the card itself

Here's what I did for the card:

cards:
  - entities:
      - entity: sensor.steam_<account_id64>
    type: glance
  - card:
      entity: sensor.steam_now_playing
      icon: ' '
      name: Now Playing
      type: entity
    conditions:
      - entity: sensor.steam_now_playing_picture
        state_not: none
    type: conditional
  - card:
      type: markdown
      content: >-
        ![Now Playing]({{
        states.sensor.steam_now_playing_picture.state }})
    conditions:
      - entity: sensor.steam_now_playing_picture
        state_not: none
    type: conditional
title: Steam
type: 'custom:vertical-stack-in-card'

The wrapping card is a custom:vertical-stack-in-card

  1. The first card shows the steam account id+picture+online status using a glance card
  2. The second card is a conditional card that wraps the Now Playing sensor entity card.
  3. The third card is a conditional card as well that wraps a markdown card with the picture directly rendered from steam. I'm using a markdown card here and not a picture card, because a picture card requires a local image, which will require us to save the banner inside an automation script (reply here if you want me to explain how to do that as well).

Notification

In order to show a notification once an account goes online, create the following automation:

- alias: Steam Notification
  description: ''
  trigger:
  - entity_id: sensor.steam_now_playing_picture
    from: none
    platform: state
  condition: []
  action:
  - data_template:
      message: '[{{ states.sensor.steam_now_playing.state }}<br><br>![{{ states.sensor.steam_now_playing.state
        }}]({{trigger.to_state.state}})](https://store.steampowered.com/app/{{ states.sensor.steam_<account_id64>.attributes.game_id
        }})'
      title: Steam - Now Playing
    service: persistent_notification.create

Hope this helped! if you have any more questions you're welcome to ask :slight_smile:

@thatkookooguy
Copy link
Author

image

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment