Counter-Strike: Global Offensive game state integration

From time to time I like to play a round of CS:GO. I’m also watching some tournaments on Twitch and always liked how they sync the stage to the game state. That is something I wanted to have in my own home.

Thankfully CS:GO provides a simple game state subscription that is easy to integrate into HomeAssistant.
A few hours later, the CS:GO game state integration was born. It adds a webhook to HomeAssistant that can be triggered by the CS:GO client. Some small logic parsed the webhook messages and keeps track of the game state to fire events in HomeAssistant. Those events can then be used to trigger automations.

Now everyone can immerse with the game.

Watch me play against harmless bots for demonstration

My automation consists of scripts that perfom all the actions and automations that are triggering the scripts:

scripts.yaml

csgo_freezetime:
  alias: CSGO - Freezetime
  sequence:
  - data:
      entity_id:
      - script.csgo_flashloop1
      - script.csgo_flashloop2
    service: script.turn_off
  - data:
      rgb_color:
      - 83
      - 52
      - 235
      transition: 0.5
    entity_id: light.example
    service: light.turn_on
csgo_begin_end:
  alias: CSGO - Round start/end
  sequence:
  - data:
      entity_id:
      - script.csgo_flashloop1
      - script.csgo_flashloop2
    service: script.turn_off
  - data:
      transition: 1
      xy_color:
      - 0.45989990234
      - 0.41059875488
    entity_id: light.example
    service: light.turn_on
csgo_bomb_planted:
  alias: CSGO - Bomb planted
  sequence:
  - data:
      rgb_color:
      - 255
      - 190
      - 0
      transition: 0.5
    entity_id: light.example
    service: light.turn_on
  - delay: '1'
  - service: script.csgo_flashloop1
csgo_bomb_defused:
  alias: CSGO - Bomb defused
  sequence:
  - data:
      entity_id:
      - script.csgo_flashloop1
      - script.csgo_flashloop2
    service: script.turn_off
  - data:
      rgb_color:
      - 0
      - 255
      - 0
      transition: 0.5
    entity_id: light.example
    service: light.turn_on
csgo_bomb_exploded:
  alias: CSGO - Bomb exploded
  sequence:
  - data:
      entity_id:
      - script.csgo_flashloop1
      - script.csgo_flashloop2
    service: script.turn_off
  - data:
      rgb_color:
      - 255
      - 0
      - 0
      transition: 0.5
    entity_id: light.example
    service: light.turn_on
csgo_flashloop1:
  alias: CSGO - Flashloop 1
  sequence:
  - data: {}
    entity_id: script.csgo_flashloop2
    service: script.turn_off
  - service: script.csgo_flashloop2
  - data:
      flash: long
    entity_id: light.example
    service: light.turn_on
  - delay: '10'
csgo_flashloop2:
  alias: CSGO - Flashloop 2
  sequence:
  - delay: '1'
  - timeout: 00:00:15
    wait_template: '{{ states.script.csgo_flashloop1.state == "off" }}'
  - service: script.csgo_flashloop1

automations.yaml

- id: '00000001'
  alias: CSGO - Freezetime starts
  description: ''
  trigger:
  - event_data: {}
    event_type: csgo_round_freeze
    platform: event
  condition:
  - condition: device
    device_id: 12345
    domain: light
    entity_id: light.example
    type: is_on
  action:
  - data: {}
    entity_id: script.csgo_freezetime
    service: script.turn_on
- id: '00000002'
  alias: CSGO - Round starts or game ends
  description: ''
  trigger:
  - event_data: {}
    event_type: csgo_round_started
    platform: event
  - event_data: {}
    event_type: csgo_game_stopped
    platform: event
  condition:
  - condition: device
    device_id: 12345
    domain: light
    entity_id: light.example
    type: is_on
  action:
  - data: {}
    entity_id: script.csgo_begin_end
    service: script.turn_on
- id: '00000003'
  alias: CSGO - Bomb planted
  description: ''
  trigger:
  - event_data: {}
    event_type: csgo_bomb_planted
    platform: event
  condition:
  - condition: device
    device_id: 12345
    domain: light
    entity_id: light.example
    type: is_on
  action:
  - data: {}
    entity_id: script.csgo_bomb_planted
    service: script.turn_on
- id: '00000004'
  alias: CSGO - Bomb exploded
  description: ''
  trigger:
  - event_data: {}
    event_type: csgo_bomb_exploded
    platform: event
  condition:
  - condition: device
    device_id: 12345
    domain: light
    entity_id: light.example
    type: is_on
  action:
  - data: {}
    entity_id: script.csgo_bomb_exploded
    service: script.turn_on
- id: '00000005'
  alias: CSGO - Bomb defused
  description: ''
  trigger:
  - event_data: {}
    event_type: csgo_bomb_defused
    platform: event
  condition:
  - condition: device
    device_id: 12345
    domain: light
    entity_id: light.example
    type: is_on
  action:
  - data: {}
    entity_id: script.csgo_bomb_defused
    service: script.turn_on

Scripts and automations can be pasted to the according files and are fully compatible with the UI editors.

Installation instructions using HACS

Have fun.

4 Likes

Empty post for updates

Nice!

May I ask what bulb you were using in your video?

Hey Yoinkz,

great that you like the idea.
It’s three IKEA TRÅDFRI RGB bulbs set up as a group and connected using zigbee2mqtt.

Argh yes… I only have the gu10 bulbs myself in my gaming room (only cold and warm white) . But I have installed a 10 m. LED strip in the ceiling.

Still using the traditional gateway. I guess you get better response by using the zigbee2mqtt?

That’s really cool, I’d be tempted set an automation to make the lights flash when the bomb explodes, but that may soon become annoying :smiley:

The good thing about how it’s implemented is that it only fires the events and you’re completely free to trigger whatever you want. Feel free to start off some fireworks :slight_smile:

I’ve never used the tradfri gateway. I started with zigbee2mqtt right from the beginning because I wanted to integrate lots of Xiaomi sensors, some Osram power plugs and floor heating controls - all Zigbee.

Same here, I just never got started :frowning:. Off topic, what device do you use for zigbee then and what hardware are you running it all on?

zigbee2mqtt is running on a Raspberry Pi 3B+ with a Texas Instruments CC2531 sniffer.
I’m using the latest source routing firmware.

Home Assistant itself in running on an Intel NUC. Ubuntu 19.10 server as the base system with Home Assistant Supervisor on top.
You can read a lot more about my installation and check my actual configuration on GitHub - lociii/homeassistant-config: My HomeAssistant config

That’s great, thanks for your time i’m already using it for my cs:go games !

1 Like

I just learned about this. It is awesome. A while back I created a project to link my gas fireplace to HA. Link is below. Anyways, the fireplace takes a few seconds to actually light. So I need to listen for the bomb_planted event, wait about 35 seconds, and then kick off the fireplace. BUT, if the bomb never goes off(the next round starts before that 35 seconds is over), then I need to cancel that automation. Anyone know how to do that?

You could do that with a script.

  • Automation listens to bomb planted and triggers a script immediately
  • Script delays for 35 seconds and then starts the fireplace
  • Another automation listens to bomb defused or round start, etc. and cancels the script

Does that make sense for you?

Yes. That makes sense. I also created a separate post asking for this, and someone responded to start a timer. I think that’s the way to go:

1 Like

I got all this working. Here’s my write up on it with video.

Also, can your integration pull other data like player health and stuff like that?

There are way more data point to subscribe and listen to. However most of them are only available in GOTV or spectator mode. This is what broadcasters and tournaments use to control their UI and stage effects.
https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Game_State_Integration

I didn’t add those as I am using the integration while playing myself.
Feel free to figure out how they’re working and add a pull request.
Unfortunately the documentation of the dev page is a bit sparse but it lists some already made implementations that can be used for inspiration.

Have fun!

Hi guy i have install HACS and csgo game stat but it does not appear.

I have Home assistant 2020.12.1 with HACS 1.9.0 can you help me please.Thanks

Hey,

did you follow the setup instructions on https://github.com/lociii/homeassistant-csgo/blob/1d860db2dc7804c9ae2429c88ee5c3aae6c2b13c/info.md?
It’s not enough to install the extension but you need to set it up in HA and add a config to your CSGO installation.

Best, Jens

I’ll be having a little play with this over the next few days, so cool. Any updates on how it’s all working for you, any new additions to your automation? :smiley:

I’ve unfortnately stopped playing CS:GO because of all the cheaters. Maybe I’ll have a look at it again soon. Sounds like the last changes might have improved the experience.