Roku TV and Xbox one power up

Ok... I've seen this thread a few time in the past day... and it's just sad...

To implement the OPs request does NOT involve a websocket and should not involve an external server...

The referenced code builds and sends a special UDP packet to an Xbox at a specific address...

So in hubitat, you would need a small driver with a switch capability, and the code to collect the IP address and Xbox Live ID then build and sent the UDP packet...

/**
 *  XBOX Power On Device Type
 *
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 *  Original Author: CybrMage
 *
***********************************************************************************************************************/
public static String version()      {  return "v0.0.2"  }

metadata {
	definition (name: "XBOX Power ON", namespace: "cybr", author: "CybrMage")
	{
		capability "Switch"

		command "on"
	}

	preferences {
		input name: "XboxIP", type: "text", title: "XBOX IP Address",  defaultValue: "",  required: true
		input name: "XboxID", type: "text", title: "XBOX Live Device ID", defaultValue: "",  required: true
		input ("debug", "bool", title: "Enable debug logging", defaultValue: false)
	}
}

def log_debug(logMsg) {
	if (debug == true) { log.debug(logMsg) }
}


def installed()
{
    log_debug("XBOX Power ON Driver - installed - ip: ${XboxIP}  ID: ${XboxID}")
}


def initialize()
{
    log_debug("XBOX Power ON Driver - initialize - ip: ${XboxIP}  ID: ${XboxID}")
}

def updated()
{
    log_debug("XBOX Power ON Driver - updated - ip: ${XboxIP}  ID: ${XboxID}")
}



def on()
{
	log_debug "Executing 'Power On'"
	if ((XboxID == null) || (XboxID == "")) {
		log_debug("XBOX Live ID not set")
		return
	}
	def IDlen = XboxID.length()
	def payloadLen = (XboxID.length() + 3)
	def encID = hubitat.helper.HexUtils.byteArrayToHexString(XboxID.toUpperCase() as Byte[])

	def UDPmessage = "00" + hubitat.helper.HexUtils.integerToHexString(IDlen,1) + encID + "00"
	def UDPheader = "DD0200" + hubitat.helper.HexUtils.integerToHexString(payloadLen,1) + "0000"
	def UDPdata = UDPheader + UDPmessage
	
	sendUDP(UDPdata)
}

def off()
{
	log_debug "'Power Off' not supported"
}

def sendUDP(String message)
{
	// message should be a hex encoded string
	if ((XboxIP == null) || (XboxIP == "")) {
		log_debug("Xbox IP address not set")
		return
	}
	log_debug("sendUDP: sending [${message}] to [${XboxIP}:5050]")
	def myHubAction = new hubitat.device.HubAction(
		message, 
		hubitat.device.Protocol.LAN, 
		[
			type: hubitat.device.HubAction.Type.LAN_TYPE_UDPCLIENT, 
			destinationAddress: "${XboxIP}:5050",
			encoding: hubitat.device.HubAction.Encoding.HEX_STRING,
			ignoreResponse: true
		]
	)
	sendHubCommand(myHubAction)
}

You would then create a virtual device using the driver, then enter the IP address and the Live ID, save the preferences, then use the "on" command to send the UDP packet.

4 Likes

Awesome thank you so much. I'm at work now but really excited to try this out this evening. @cybrmage did you write the code? This is exactly what I was looking for fingers crossed it works!

Got my answer thank you much (Original Author: CybrMage) this is great where do I go to support you man. You are the best brother!

This is great, thanks!
I had another thread bookmarked where this was being discussed, but nobody had written a solution yet - I will link them back to your solution.

One thing that might be helpful to add to your post or driver - you mentioned the "Live ID" and I wrongly assumed this was my Xbox Live ID name or email. What was needed was the "Xbox Live Device ID", which can be retrieved from Settings - System - Console Info on the Xbox itself.

I got this setup and configured. It is working although it seems a little buggy. Got the power on option to work 2 out of 5 tries and the off button never did work. This may be something with Xbox's solution or something though. Not sure if it has improved since I first tried years ago to boot it from my server so I could play remotely. I have a domain name and dynamic dns setup for remote access to some of my network resources. Anyone else have issues let me know. Not sure how much time I will have this evening but plan on digging into it more this weekend for sure.

Also wanted to mention make sure you power it off if it is already on before trying to use the virtual device. Mine was already on and I was not able to even get the power on to work initially prior to power it off. Could just be coincidence but I tried 20 times at least and nothing.

In the code they didnโ€™t implement the off command. Not sure if the UDP request is 100% correct either.

AWWW ok no problem @aaron I'm just happy we have something to use. Just want to make sure we document any/all issues for others. I know I used this script or one like it years ago and seen some dependencies as well. Anyway I just want to make sure @cybrmage knows these are not complaints only trying to document and figure it out for others who come after us.

Oh did I mention how flipping awesome this is? I really need to learn to code and develop I just have such a hard time wrapping my head around it.

This is what I'm seeing in my logs this morning.

dev:5452019-08-31 07:44:18.821 am warnError occured with UDP message: SocketTimeoutException: Receive timed out

dev:5452019-08-31 07:44:15.805 am debug'Power Off' not supported

dev:5452019-08-31 07:44:15.037 am debug'Power Off' not supported

dev:5452019-08-31 07:44:13.301 am warnError occured with UDP message: SocketTimeoutException: Receive timed out

dev:5452019-08-31 07:44:08.804 am debugsendUDP: sending [DD020013000000104644303033363046364542343031394400] to [10.1.10.71:5050]

dev:5452019-08-31 07:44:08.799 am debugExecuting 'Power On'

dev:5452019-08-31 07:44:03.280 am debugsendUDP: sending [DD020013000000104644303033363046364542343031394400] to [10.1.10.71:5050]

dev:5452019-08-31 07:44:03.271 am debugExecuting 'Power On'

So I did a lot more research surrounding turning on/off an Xbox.

Xbox turning on can be initiated from a UDP call to IP_Addy:5050.

Turning off an XBOX can only be initiated from the controller, Xbox button or from Xbox live. So there is no way to turn off an Xbox without developing connectivity to Xbox live and acquiring a temporary token.

Turn off can be performed with the smartglass API (the ip_Addy:5050 system)... But the smartglass API only supports two commands (Power On and Discovery) that are unencrypted. The encrypted commands require AES encryption, and therefore can not (at this time) be implemented on the hubitat.

You can do this in Hubitat. It just needs to send the off command through Xbox live verses direct. Hence my comment and research. I installed and tore apart the Python Smartglass code today. Without a valid token you cannot connect locally. BUT you could initiate a power off through Xbox live but again this requires a lot of programming. So nothing quick and dirty unfortunately.

You can't do encryption in Hubitat code (there's a couple of people requesting it here, but no official response) - it doesn't matter how much programming you do if you can't access the classes you need :slight_smile:

1 Like

I use Hubitat with a virtual contact that turns on or off Xbox.

Thatโ€™s how Iโ€™m doing it

@mik3 Can you share more info?

Sorry I left the Alexa part out. Alexa actually turns it off or on based off a contact sensor thatโ€™s trigger in Hubitat.

1 Like

Oh ok that makes sense. Thanks for the info.

Last night my TV input switched and my Xbox powered on as expected. I think this is the first time it worked as expected. Not sure why it is so intermittent but looks like we are making progress at least. Anyone had a chance to implement this one? What are your results if so?

I have it running, but I've only used it twice - it worked both times.

Ok it worked again this evening. I think what was going on is I had issues with my hub very laggy worked with support today and it is working much better. So I'm hoping that was my issue in seeing it being so inconsistent.

Well since I set my hub up to reboot every few days this has ran perfectly with no issues. Looks like I'm suffering the hub slowdown every few days like others which causes issues with my rules running. Thank you @cybrmage much appreciated friend!