A module for Waybar that can show and toggle sensors from Home Assistant
Download waybarha.py anywhere you have permission to read it
Edit the file to set your server's URL and the access token.
In your waybar's .jsonc, add one entry per entity you want to read/toggle. Examples:
"custom/ha1": {
"format": " {text}",
"exec": "/path/to/waybarha.py switch.lamp",
"on-click": "/path/to/waybarha.py --toggle switch.lamp",
"return-type": "json", /* this script outputs json; if you omit this the label will be a json output*/
"interval": 5
},
"custom/ha2": {
"format": " {text}",
"exec": "/path/to/waybarha.py switch.floor_lamp",
"on-click": "/path/to/waybarha.py --toggle switch.floor_lamp",
"return-type": "json",
"interval": 5
},
"custom/ha3": {
"format": " {text}",
"exec": "/path/to/waybarha.py sensor.2022_santa_cruz_fuel_level",
"return-type": "json",
"interval": 600 // 10 minutes
}
Hint: if "format": " {text}" has a square instead of a proper character (it's a light bulb) you need to install and use a nerd font.
This plugin exposes the entity's state as 'text', unless the entity's name starts with "switch" in which case the on/off states are exposed via css classes for styling.
Example of style.css:
#custom-ha1 {
background: @background-primary;
color: @sapphire;
border-left: 4px solid @sapphire;
margin: 6px 0;
padding: 8px 12px;
}
#custom-ha1.on { // highlight by swapping foreground and background when the switch is on
background: @sapphire;
color: @background-primary;
}
#custom-ha1.off {
opacity: 0.7;
}
#custom-ha2 {
background: @background-primary;
color: @teal;
border-left: 4px solid @teal;
margin: 6px 0;
padding: 8px 12px;
}
#custom-ha2.on {
background: @teal;
color: @background-primary;
}
#custom-ha2.off {
opacity: 0.7;
}
#custom-ha3 {
background: @background-primary;
color: @lavender;
border-left: 4px solid @lavender;
margin: 6px 0;
padding: 8px 12px;
border-radius: 12px 0 0 12px;
}
The script takes 2 arguments:
- optional - - toggle means this is a switch to toggle and can be omitted
- the entity's id
./waybarha.py --help
usage: waybarha.py [-h] [-t] entity
Waybar home assistant module to query/toggle an entity
positional arguments:
entity entity to read or toggle - ex: 'switch.lamp'
options:
-h, --help show this help message and exit
-t, --toggle toggle entity on/off; entity's state will be read if omitted
