Code for .sh file
#!/bin/bash
IP_ADDR=192.168.1.101
LIVE_ID=FD008DA9A799XXXX (I have blocked the last 4 digits of my live id for security reasons.)
python xbox-remote-power.py -a $IP_ADDR -i $LIVE_ID
Code for .py file
#!/usr/bin/env python
import sys, socket, select, time
from argparse import ArgumentParser
XBOX_PORT = 5050
XBOX_PING = "dd00000a000000000000000400000002"
py3 = sys.version_info[0] > 2
def main():
parser = ArgumentParser(description="Send power on packets to a Xbox One.")
parser.add_argument('-a', '--address', dest='ip_addr', help="IP Address of Xbox One", default='')
parser.add_argument('-i', '--id', dest='live_id', help="Live ID of Xbox One", default='')
parser.add_argument('-f', dest='forever', help="Send packets until Xbox is on", action='store_true')
args = parser.parse_args()
if not args.ip_addr:
args.ip_addr = user_input("Enter the IP address: 192.168.1.101")
if not args.live_id:
args.live_id = user_input("Enter the Live ID: FD008DA9A799XXXX")
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setblocking(0)
s.bind(("", 0))
s.connect((args.ip_addr, XBOX_PORT))
if isinstance(args.live_id, str):
live_id = args.live_id.encode()
else:
live_id = args.live_id
power_payload = b'\x00' + chr(len(live_id)).encode() + live_id + b'\x00'
power_header = b'\xdd\x02\x00' + chr(len(power_payload)).encode() + b'\x00\x00'
power_packet = power_header + power_payload
print("Sending power on packets to {0}...".format(args.ip_addr))
send_power(s, power_packet)
print("Xbox should turn on now, pinging to make sure...")
ping_result = send_ping(s)
if ping_result:
print("Ping successful!")
else:
print("Failed to ping Xbox

")
result = ""
if not args.forever:
while result not in ("y", "n"):
result = user_input("Do you wish to keep trying? (y/n): ").lower()
if args.forever or result == "y":
print("Sending power packets and pinging until Xbox is on...")
while not ping_result:
send_power(s, power_packet)
ping_result = send_ping(s)
print("Ping successful!")
s.close()
def send_power(s, data, times=5):
for i in range(0, times):
s.send(data)
time.sleep(1)
def send_ping(s):
s.send(bytearray.fromhex(XBOX_PING))
return select.select(
, [], [], 5)[0]
def user_input(text):
response = ""
while response == "":
if py3:
response = input(text)
else:
response = raw_input(text)
return response
if __name__ == "__main__":
main()
And the code for running the fake wemo switch server so echo can see and control
""" fauxmo_minimal.py - Fabricate.IO
This is a demo python file showing what can be done with the debounce_handler.
The handler prints True when you say "Alexa, device on" and False when you say
"Alexa, device off".
If you have two or more Echos, it only handles the one that hears you more clearly.
You can have an Echo per room and not worry about your handlers triggering for
those other rooms.
The IP of the triggering Echo is also passed into the act() function, so you can
do different things based on which Echo triggered the handler.
"""
import fauxmo
import logging
import time
from debounce_handler import debounce_handler
logging.basicConfig(level=logging.DEBUG)
class device_handler(debounce_handler):
"""Publishes the on/off state requested,
and the IP address of the Echo making the request.
"""
TRIGGERS = {"xbox": 52000}
def act(self, client_address, state, name):
print "State", state, "on ", name, "from client @", client_address
import subprocess
subprocess.call(['/home/pi/echoxbox/xbox-remote-power-master/xbox-remote-power.sh'])
return True
if __name__ == "__main__":
# Startup the fauxmo server
fauxmo.DEBUG = True
p = fauxmo.poller()
u = fauxmo.upnp_broadcast_responder()
u.init_socket()
p.add(u)
# Register the device callback as a fauxmo handler
d = device_handler()
for trig, port in d.TRIGGERS.items():
fauxmo.fauxmo(trig, u, p, None, port, d)
# Loop and poll for incoming Echo requests
logging.debug("Entering fauxmo polling loop,Ask Alexa to find my devices")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception, e:
logging.critical("Critical exception: " + str(e))
break