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