Destiny 2 custom sensor

I’ve created a custom sensor that hooks into the Destiny 2 API and reports the subclass of your active / most recently played character. I use it to update the lighting in my man cave based on the state of the sensor.

It’s available over on my GitHub:

And here’s a demo of it in action:

Note: My first bash at a custom component for HA so any feedback is welcomed!

5 Likes

brilliant!

Can you explain how to configure it to my account/character?

This is really cool. Any other plans for other sensors or improvements? @danrspencer

Also, what requirements from an API perspective are needed? Redirect URL?

1 Like

I see your automations are setting the playing game, etc. Have you seen this: Playstation 4/PS4 custom component

Cool, digging into the api a bit… Would be neat to have a character sensor with attributes like, Power/Light, Emblem, current subclass, maybe even level progression stats.

My documentation/readme should explain how to set it up. Let me know if you struggle somewhere.

I’m using the PS4 component. I use it to only update the light colour from Destiny2 sensor when Destiny2 is running.

I can probably add more to this sensor. I’m throwing away loads of data that I get from the Destiny2 API. I’ve not bothered yet because it does everything I need it to for my automations. If there’s anything specific you’re after I can look at adding it.

Can you help me with the configuration of the app at bungie’s website? I installed the sensor, configured everything like the read.me and used the api key from the app, but I always get the status as unknown.

You’ll have to give me a few more details before I can be of any help. Are you getting any errors in the logs? Can you make a request to the API via curl qith your key?

e.g.

curl --header “X-API-Key: ##your-api-key##” “https://www.bungie.net/Platform/Destiny2/2/Profile/4611686018428481758/?components=200,205

Can you explain the application setup for those of us that may not be as savvy with redirects? Not really sure how to set that part up on the Bungie site.

Thanks for any assistance

1 Like

I’m getting this in the logs and also getting errors from the Api key with the curl command.

ERROR [homeassistant.helpers.entity] Update for sensor.destiny2 fails
Traceback (most recent call last):
File “/home/homeassistant/.homeassistant/custom_components/sensor/destiny2.py”, line 114, in update
characters = response.json()[‘Response’][‘characters’][‘data’]
KeyError: ‘Response’

@danrspencer or others, wanted to check back in to see if you could help me out? I’m not quite sure what I need to input for the redirect on the application page. I’m assuming that I need some sort of webpage? I’d like to set this up the easiest way possible so any guidance would be awesome.

Thanks All!

It’s finnaly working, I was using the wrong membership id. For the configuration at bungie’s app I have it like in the images, hope it helps.

Awesome, Thanks! I was able to get the api key to work. However, the sensor is showing up as unknown (I did click the authorization link and approved access. It then took me to my home assistant page).

destiny2

I’ve double checked my sensor code and made sure the destiny2_api_key was correct:
https://www.bungie.net/en/Profile/254/13081218/Xecuter83

- platform: destiny2
  membership_type: 254
  destiny_membership_id: 13081218
  api_key: !secret destiny2_api_key

I have copied the python script to the /custom_components/sensor folder as instructed:

Im getting the same errors as you:

    2017-10-13 16:58:31 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.destiny2 fails
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/sensor/destiny2.py", line 113, in update
    characters = response.json()['Response']['characters']['data']
KeyError: 'Response'

you mentioned you were using the wrong membership ID, could you elaborate? What i have in the sensor above is what i see on the bungie site when i click view profile.

Thanks

You’re making the same mistake as me. On you profile page click on your specific platform(psn, xbox), when that page opens the values of membership type/id will change, because they are platform specific.

For your account the correct values are:

membership_type: 2
destiny_membership_id: 4611686018458754475

Hope it works :wink:

Will test and let you know, thanks!

This Worked! Thanks David.

Not sure why I was seeing something different than what you posted. I also worked tonight on the automations for changing the light colors based on the sensors and all is now working like the video above.

Thanks again for helping me through!