Fancy Waybar Configurations
By Speedsquirrel - July 28, 2025
1. Waybar Folder Structure
waybar
├── brightness
├── config
├── scripts
│ ├── ice_speed.sh
│ └── mqtt_co2.sh
├── style.css
└── update_brightness.sh
To display the brightness of my screen (e.g., on a laptop), I created a small shell script that gets triggered every time I adjust the brightness through my window manager:
#!/bin/bash
light -G | awk '{printf "☀ %.0f%%\n", $1}' > /home/user/.config/waybar/brightness
The script saves the current brightness level to /home/user/.config/waybar/brightness
, which is then read and displayed by my Waybar configuration:
"custom/brightness": {
"format": "{}",
"exec": "cat /home/user/.config/waybar/brightness",
"interval": 1
},
2. Displaying ICE Train Speed in Waybar
I also created a small script that shows me how fast the train I’m currently on is moving, by using the iceportal
API.
If I’m connected to the ICE Wi-Fi (WIFIonICE
), the script automatically fetches the current train speed:
#!/bin/bash
SSID=$(nmcli -t -f active,ssid dev wifi | grep '^yes' | cut -d: -f2)
if [ "$SSID" = "WIFIonICE" ]; then
SPEED=$(curl -s https://iceportal.de/api1/rs/status | jq -r '.speed')
if [[ "$SPEED" == "null" || -z "$SPEED" ]]; then
echo "{\"text\": \"🚅 ???\", \"tooltip\": \"No speed available\"}"
elif (( $(echo "$SPEED > 200" | bc -l) )); then
echo "{\"text\": \"🚀 ${SPEED} km/h\", \"tooltip\": \"ICE speed\"}"
else
echo "{\"text\": \"🚅 ${SPEED} km/h\", \"tooltip\": \"ICE speed\"}"
fi
else
echo "{\"text\": \"\", \"tooltip\": \"\"}"
fi
This script is then integrated into the config.jsonc
of Waybar:
"custom/ice_speed": {
"exec": "~/.config/waybar/scripts/ice_speed.sh",
"interval": 5,
"return-type": "json",
"format": "{}",
"tooltip": true
},
3. Integrating CO₂ Traffic Light Data into Waybar (via MQTT)
Step 1: Install MQTT Broker
First, you need to install mosquitto
:
sudo dnf install mosquitto
Make sure Mosquitto listens on all interfaces. Edit the file /etc/mosquitto/mosquitto.conf
if necessary:
listener 1883
allow_anonymous true
If needed, open the port in your firewall:
sudo firewall-cmd --permanent --add-port=1883/tcp
sudo firewall-cmd --reload
Step 2: Configure the CO₂ Traffic Light
Flash your CO₂ traffic light with custom firmware that supports MQTT. Then configure it to publish to your MQTT broker (use your PC’s IP address as the broker
, and leave the username empty if no authentication is required).
The device will send data to a topic like:
Co2/Ampel_1
Example payload:
{"co2":"872","temp":"20.31","hum":"42","lux":"318"}
Step 3: Create a Waybar Script
Create a script called mqtt_co2.sh
under ~/.config/waybar/scripts/
:
#!/bin/bash
payload=$(mosquitto_sub -h localhost -t "Co2/Ampel_1" -C 1)
co2=$(echo "$payload" | jq -r .co2)
text="CO₂: ${co2} ppm"
class=""
if [[ "$co2" -lt 800 ]]; then
class="green"
elif [[ "$co2" -lt 1000 ]]; then
class="yellow"
elif [[ "$co2" -lt 1200 ]]; then
class="red"
else
class="blinking"
fi
echo "{\"text\": \"$text\", \"tooltip\": \"CO₂ value from sensor\", \"class\": \"$class\"}"
Step 4: Add the Module to Waybar
In your config.jsonc
, add the module:
"custom/co2": {
"exec": "~/.config/waybar/scripts/mqtt_co2.sh",
"interval": 10,
"return-type": "json"
}
Also define the required CSS classes in your style.css
:
#custom-co2.green {
color: #00ff00;
}
#custom-co2.yellow {
color: #ffff00;
}
#custom-co2.red {
color: #ff0000;
}
#custom-co2.blinking {
color: #ff0000;
animation: blink 1s infinite;
}
@keyframes blink {
50% {
opacity: 0;
}
}