Xbox sensor

Good to hear it’s up and running for you!

  1. you would probably need to add in an additional else statement to rename the template if the value is blank to your desired state. Some detail on multi if/else statements here.

  2. You should be able to use an automation based on the state of the template sensor that we have setup. If the state of the xbox template sensor = “Netflix” then dim ‘light’ to 20%.

signed in, and trying to extract the current playing game from the sensor (which works btw)

Imitate available variables:
{'XboxOne Background': 'Home', 'XboxOne Full': 'The Sims™ 4'}

how would i define the template to extract the ‘XboxOne Full’ attribute?? spaces aren’t very nice here.

— edit—

found it: .attributes[“XboxOne Full”]}}

Would it be possible to scrape for other UID’s on the main account, and possibly show a screen from the current game/bluray being played.
Trying also to find an option to show the account icon, would be cool.

hi,

been trying to mitigate the sensor Unknown state, which arises when Xbox.api is overlimit. The sensor isnt created, but the Background and Full template sensors appear with the ugly unknown…

got as far as this (rebuilt the template ) but neither "unknown’ nor unknown have the desired result.

Please have a look how this could be accomplished:

xboxapi_current:
        value_template: '{%- if states.sensor.gamertag == "Offline" %}Offline
                         {%- elif states.sensor.gamertag == "unknown" %}Offline
                         {%- else %}
                         {{ states.sensor.gamertag.attributes["XboxOne Full"] }}
                         {%- endif %}'
        
        icon_template: '{%- if states.sensor.gamertag == "Offline" %}mdi:xbox-controller-off
                        {%- elif states.sensor.gamertag == "unknown" %}mdi:xbox-controller-off
                        {%- else %}mdi:xbox-controller
                        {%- endif %}' 

customize and the main device tracker…

homeassistant:
  customize:
    sensor.gamertag:
      entity_picture: /local/gamertag.png
      templates:
        theme: >
          if (state === 'Online') return 'green'; else return null;
        _stateDisplay: if (state === 'Unknown') return 'Offline'; else return state;

    sensor.xboxapi_current:
      friendly_name: Xbox current
      templates:
        theme: '{%- if states.sensor.gamertag == "Offline" %}null
                         {%- elif states.sensor.gamertag == unknown %}null
                         {%- else %}
                         "green"
                         {%- endif %}'
        rgb_color: "if (state !== 'Offline') return 'green'; else return null;"

    sensor.xboxapi_background:
      friendly_name: Xbox background
      templates:
        theme: '{%- if states.sensor.gamertag == "Offline" %}null
                         {%- elif states.sensor.gamertag == unknown %}null
                         {%- else %}
                         "green"
                         {%- endif %}'
        rgb_color: "if (state !== 'Offline') return 'green'; else return null;"

    device_tracker.xboxone:
      templates:
        theme: >
          if (state === 'home') return 'green'; else return null;
        _stateDisplay: if (state === 'home') return 'Online'; else return 'Offline';
    
    device_tracker.xboxone_wifi:
      templates:
        theme: >
          if (state === 'home') return 'green'; else return null;
        _stateDisplay: if (state === 'home') return 'Online'; else return 'Offline';

UPDATE: This was a permissions issue in Permission denied: ‘/srv/homeassistant/lib/python3.6/site-packages/xboxapi-0.1.1.dist-info’ and is now working!

I seem to be stuck getting the Dependency installed. Below is the error I am gettting, I have tried all of these and still does not work…Any thoughts?

sudo pip3 install xboxapi
sudo pip install xboxapi
sudo pip3 install xboxapi==0.1.1
pip3 install xboxapi==0.1.1
pip install xboxapi==0.1.1

Unable to install package xboxapi==0.1.1: Exception:
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/srv/homeassistant/lib/python3.6/site-packages/pip/commands/install.py”, line 342, in run
prefix=options.prefix_path,
File “/srv/homeassistant/lib/python3.6/site-packages/pip/req/req_set.py”, line 784, in install
**kwargs
File “/srv/homeassistant/lib/python3.6/site-packages/pip/req/req_install.py”, line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File “/srv/homeassistant/lib/python3.6/site-packages/pip/req/req_install.py”, line 1064, in move_wheel_files
isolated=self.isolated,
File “/srv/homeassistant/lib/python3.6/site-packages/pip/wheel.py”, line 345, in move_wheel_files
clobber(source, lib_dir, True)
File “/srv/homeassistant/lib/python3.6/site-packages/pip/wheel.py”, line 316, in clobber
ensure_dir(destdir)
File “/srv/homeassistant/lib/python3.6/site-packages/pip/utils/init.py”, line 83, in ensure_dir
os.makedirs(path)
File “/usr/local/lib/python3.6/os.py”, line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: ‘/srv/homeassistant/lib/python3.6/site-packages/xboxapi-0.1.1.dist-info’
2018-02-20 13:30:54 ERROR (MainThread) [homeassistant.setup] Not initializing sensor.xbox_live because could not install dependency xboxapi==0.1.1
2018-02-20 13:30:54 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.xbox_live: Could not install all requirements.

I’m excited about the potential for this component based on what’s available through the xboxapi. Does anyone know how to send messages to a gamertag/xiud?
There is a json post example on the website, and I am using the paid level so I have access to that function.
I’m just not sure how I can get HA to send the correctly formatted command to xboxapi.

I’m guessing it would look something like this:

$ curl -H “X-Auth: mycrazylongkey” -H “Content-Type: application/json” -X POST -d ‘{ “to”: [“thexuid” ], “message”: “This is an example message sent via XboxAPI :smiley:” }’ https://xboxapi.com/v2/messages

How can I send that from Home Assistant? shell command?