LordBoos / discord_game

Home Assistant custom component to get online and game status of Discord users
MIT License
57 stars 9 forks source link

It is possible to poll the sensor for different actions reported by Discord? #7

Closed NMe84 closed 4 years ago

NMe84 commented 4 years ago

I would like to use the state my Discord reports in some automations, so that I can for instance automatically turn the brightness of my lights down if I start playing a game. The way things are now I don't think you can do anything besides seeing whether or not my account is online, which it is pretty much 24/7.

Is it currently possible to watch game, streaming, listening or watching status for use in automation and am I just missing it? And if it's not possible, is this something that would be possible to add and you would consider adding?

LordBoos commented 4 years ago

Yes that is possible by creating custom template sensors from the attributes of the main sensor.

sensor:
  - platform: discord_game
    token: !secret discord_api_key
    members:
      - Username#number
  - platform: template
    sensors:
      discord_username_number_game:
        value_template: '{{ states.sensor.discord_username_number.attributes.game}}'

Or you can use value template directly in the automation if you do not need the custom sensor itself for other reasons like displaying the data in lovelace. Can be used with any of the attributes.

NMe84 commented 4 years ago

Awesome, works great!