Dash Hacks: Hacking the Amazon Dash to Launch a Random Steam Game

Combining Windows, an Amazon Dash Button, and the Steam API


There are so many games on Steam.  Between the deals and the bundles most users build up an impressive backlog.  That backlog tends to become so huge that when we actually get around to clearing it, we don't know where to start.

Lucky for us, Amazon has made a button that can solve all of our problems, with a little bit of work.

Here's what we need to do:

  1. Prevent the Dash Button from ordering anything
  2. Use scapy to listen in on the WiFi network for a signal from the Dash Button
  3. Write a python script that uses the Steam API to get a list of your games and launch one at random.

Fortunately, parts 1 & 2 have already been figured out for us.  

Ted Benson wrote an article with instruction to prevent the dash button from ordering.

Unfortunately, the rest of his article is not as useful as he is using scapy with macOS.  This doesn't help us as we are using Windows.  But we are not the only ones with that issue.  

Gad Berger provides an excellent article on getting scapy to work easily with Windows.

Using his dash.py file, we are able to use scapy and listen in on our network for our Dash Button.  

Now that we have our Dash Button registering, we can bind it to a function.

In this case we want to pull from our list of games, find the ones that we haven't played and then randomly select one of those to launch.

To get our list of games, we need to register for a Steam API key.

You can sign up for an api key here: https://steamcommunity.com/dev/apikey

We will also need our Steam Id, which can be found here: https://steamid.io/ (You will want the steamID64 value)

Here is how we grab our list of games (full documentation of the Steam API available here):

steam.py
import requests

STEAM_API_KEY = "YOUR API KEY HERE"
STEAM_ID = "YOUR STEAM ID HERE"
STEAM_API_URL = "https://api.steampowered.com/"

def get_owned_games(api_key=STEAM_API_KEY, sid=STEAM_ID):
    game_list = []
    params = {'key': api_key, 'steamid': sid, 'format': 'json'}
    r = requests.get("{0}{1}".format(STEAM_API_URL, "IPlayerService/GetOwnedGames/v0001/"), params=params)
    print r.json()

You will see in the response that there is an attribute for each game called 'playtime_forever'.  It's value represents the number of minutes you have played that game.  To filter out the games that we've played we'll filter the response into a list and only include games that have had less than 10 minutes of playtime (we won't make it 0 minutes, as there are many instances where a user will have booted up their game, but not actually played it yet.)

steam.py
import requests

STEAM_API_KEY = "YOUR API KEY HERE"
STEAM_ID = "YOUR STEAM ID HERE"
STEAM_API_URL = "https://api.steampowered.com/"
PLAYTIME_LIMIT = 10

def get_owned_games(api_key=STEAM_API_KEY, sid=STEAM_ID):
    game_list = []
    params = {'key': api_key, 'steamid': sid, 'format': 'json'}
    r = requests.get("{0}{1}".format(STEAM_API_URL, "IPlayerService/GetOwnedGames/v0001/"), params=params)
    for obj in r.json()['response']['games']:
        if PLAYTIME_LIMIT != None:
            if obj['playtime_forever'] <= PLAYTIME_LIMIT:
                game_list.append(obj)
        else:
            game_list.append(obj)
    return game_list

Alright, so now we have a list of games that we can choose from.  Getting a random game from a list is easy.

steam.py
import random

def get_random_game(game_list=get_owned_games()):
    return random.choice(game_list)

Now that we have our game, we need to launch it. Steam has commands that we can use with the explorer to launch certain games based off of their appid

steam.py
import os

def launch_game(appid):
    command = "explorer steam://run/{0}".format(appid)
    os.system(command)

Last thing we need to do in the file is hook it all together into a single command

steam.py
def run():
    launch_game(get_random_game()['appid'])

In the end the file will look like this

steam.py
import os
import random
import requests

STEAM_API_KEY = "YOUR API KEY HERE"
STEAM_ID = "YOUR STEAM ID HERE"
STEAM_API_URL = "https://api.steampowered.com/"
PLAYTIME_LIMIT = 10

def get_owned_games(api_key=STEAM_API_KEY, sid=STEAM_ID):
    game_list = []
    params = {'key': api_key, 'steamid': sid, 'format': 'json'}
    r = requests.get("{0}{1}".format(STEAM_API_URL, "IPlayerService/GetOwnedGames/v0001/"), params=params)
    for obj in r.json()['response']['games']:
        if PLAYTIME_LIMIT != None:
            if obj['playtime_forever'] <= PLAYTIME_LIMIT:
                game_list.append(obj)
        else:
            game_list.append(obj)
    return game_list

def get_random_game(game_list=get_owned_games()):
    return random.choice(game_list)

def launch_game(appid):
    command = "explorer steam://run/{0}".format(appid)
    os.system(command)

def run():
    launch_game(get_random_game()['appid'])

From there, you just need to import the run command into your dash.py file and have it trigger off of the Dash Button.

dash.py
from steam import run

def dash_button_press(mac):
    if mac in dash_macs:
        print("{0} button pressed".format(dash_macs[mac]))
    else:
        print("[{0}] unknown device".format(mac))

    # Your dash button will probably not be Campbells
    if dash_macs[mac] == "Campbells":
        run()

All that's left is running the script. When it's running, the next time you push your Dash Button, it will boot up a game from your backlog.

If you would like access to the source code or would like to contribute, you can access the git repository here.

View on GitHub