Skip to content

Commit be8fad2

Browse files
committed
docs: add getting started with docker compose section
1 parent 919126c commit be8fad2

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,102 @@ On graceful shutdown, **cs2mqtt** will publish an offline message to this topic
6767
When a Counter-Strike 2 game instance submits data for the first time, **cs2mqtt** will automatically create an MQTT device for it, as described above, and publish online messages to `cs2mqtt/{steamId64}/+/status` topics.
6868
If a player disconnects from a game server, the topics related to `player_state`, `map`, and `round` will immediately be set to `offline`.
6969
When a player closes their Counter-Strike 2 game, there is no data transmitted, and there's nothing to indicate they've quit. As a result, **cs2mqtt** listens for heartbeats and eventually sets the entire device to an offline availability state once the timeout is reached.
70+
71+
## Running **cs2mqtt** with Docker Compose
72+
73+
In this example, it is expected that an MQTT broker, such as [Mosquitto](https://mosquitto.org/), is already set up and configured with the [MQTT integration](https://www.home-assistant.io/integrations/mqtt/) in [Home Assistant](https://www.home-assistant.io/).
74+
75+
### docker-compose.yml
76+
77+
```yaml
78+
services:
79+
cs2mqtt:
80+
image: ghcr.io/lupusbytes/cs2mqtt:latest
81+
container_name: cs2mqtt
82+
ports:
83+
- "5000:8080"
84+
environment:
85+
MQTT__Host: 127.0.0.1 # MQTT broker address
86+
MQTT__Port: 1883 # MQTT broker port
87+
MQTT__UseTLS: false # Set to true if your broker uses TLS (optional, default: false)
88+
MQTT__Username: c2m # MQTT client username (optional)
89+
MQTT__Password: password # MQTT client password (optional)
90+
MQTT__ClientId: cs2mqtt # MQTT client ID (optional)
91+
MQTT__ProtocolVersion: 5.0.0 # Allowed values are 3.1.0, 3.1.1, or 5.0.0 (optional, default: 5.0.0)
92+
93+
restart: unless-stopped
94+
```
95+
96+
>⚠️ Make sure you replace the host, username, and password with values matching your setup, and that the MQTT client is not also used by another application.
97+
If the broker is configured to allow anonymous access, the username and password can be omitted.
98+
99+
### Connecting **Counter-Strike 2** to **cs2mqtt**
100+
101+
To make **Counter-Strike 2** send game state data to **cs2mqtt**, you need to create a config file within the game's directory.
102+
103+
If **Steam** and **Counter-Strike 2** are installed with default options, the path where you need to create your config is:
104+
105+
```
106+
C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\game\csgo\cfg
107+
```
108+
109+
Once you have located the correct path, create a new file there called **gamestate_integration_cs2mqtt.cfg** with the following content:
110+
111+
```
112+
"cs2mqtt"
113+
{
114+
"uri" "http://127.0.0.1:5000"
115+
"timeout" "5.0"
116+
"buffer" "0.1"
117+
"throttle" "0.5"
118+
"heartbeat" "60.0"
119+
"data"
120+
{
121+
"provider" "1"
122+
"map" "1"
123+
"round" "1"
124+
"player_id" "1"
125+
"player_state" "1"
126+
}
127+
}
128+
```
129+
130+
> 💡 Tip
131+
>
132+
>In Windows File Explorer, it can be tricky to create a new file with a specific file extension (like `.cfg`).
133+
A simple workaround is to copy one of the many pre-existing `.cfg` files in the folder, rename it, and then replace its contents using Notepad.
134+
135+
>⚠️ Make sure you replace the `uri` with the IP address or hostname of the host that is running **cs2mqtt**.
136+
137+
The next time you launch **Counter-Strike 2**, **cs2mqtt** will use the [MQTT discovery protocol](https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery) to make [Home Assistant](https://www.home-assistant.io/) create an MQTT device named `CS2 STEAM_{X}:{Y}:{Z}`, matching your SteamID. On the very first game launch, the device will not have many sensors, but after joining or creating a game server, all sensors will automatically be discovered.
138+
139+
### Additional configuration options
140+
141+
It is possible to require authentication between **Counter-Strike 2** and **cs2mqtt**.
142+
To do this, pick a password and add it as an environment variable in the **cs2mqtt** docker-compose.yml like:
143+
144+
```yaml
145+
GameStateOptions__Token: password
146+
```
147+
148+
Then also add the same password to **gamestate_integration_cs2mqtt.cfg** in the root object:
149+
150+
```
151+
"auth"
152+
{
153+
"token" "password"
154+
}
155+
```
156+
157+
###
158+
159+
### Limiting what game state data is sent
160+
161+
It is possible to remove any of the following entries from the data object in **gamestate_integration_cs2mqtt.cfg**:
162+
- `map`
163+
- `round`
164+
- `player_id`
165+
- `player_state`
166+
167+
This will stop **Counter-Strike 2** from sending data about the removed topics.
168+
The only required entry is `provider`.

0 commit comments

Comments
 (0)