add bedroom light control to waybar
This commit is contained in:
@@ -262,6 +262,7 @@ in
|
||||
isNormalUser = lib.mkDefault true;
|
||||
extraGroups = [
|
||||
"wheel"
|
||||
"keys"
|
||||
"networkmanager"
|
||||
"ratbagd"
|
||||
"input"
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
modules-right = [
|
||||
"tray"
|
||||
"custom/updates"
|
||||
"custom/lights"
|
||||
"temperature"
|
||||
"temperature#gpu"
|
||||
"keyboard-state#capslock"
|
||||
@@ -49,7 +50,7 @@
|
||||
tooltip = true;
|
||||
format = { };
|
||||
interval = 30;
|
||||
exec = "sudo waybar-weather";
|
||||
exec = "waybar-weather";
|
||||
return-type = "json";
|
||||
};
|
||||
|
||||
@@ -57,10 +58,18 @@
|
||||
tooltip = true;
|
||||
format = { };
|
||||
interval = 30;
|
||||
exec = "sudo waybar-updates";
|
||||
exec = "waybar-updates";
|
||||
return-type = "json";
|
||||
};
|
||||
|
||||
"custom/lights" = {
|
||||
tooltip = false;
|
||||
format = "";
|
||||
# interval = 30;
|
||||
on-click = "nix-shell /home/matt/.config/waybar/scripts/hass.nix --run \"python /home/matt/.config/waybar/scripts/hass.py --toggle_light light.bedroom_lights\"";
|
||||
# return-type = "json";
|
||||
};
|
||||
|
||||
temperature = {
|
||||
hwmon-path = "/sys/class/hwmon/hwmon4/temp1_input";
|
||||
critical-threshold = 90;
|
||||
@@ -332,6 +341,14 @@
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
#custom-lights {
|
||||
color: @nord8;
|
||||
background-color: @nord0;
|
||||
padding: 0.5rem 1rem;
|
||||
margin: 5px 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
/* ------------- */
|
||||
|
||||
#tray {
|
||||
|
||||
18
hosts/desktop/hyprland/config/waybar/scripts/hass.nix
Normal file
18
hosts/desktop/hyprland/config/waybar/scripts/hass.nix
Normal file
@@ -0,0 +1,18 @@
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
|
||||
pkgs.mkShell {
|
||||
# The Nix packages provided in the environment
|
||||
packages = [
|
||||
pkgs.python312
|
||||
pkgs.python3Packages.pip
|
||||
# Whatever other packages are required
|
||||
];
|
||||
shellHook = ''
|
||||
export TMPDIR=/tmp
|
||||
export VENV_DIR=/tmp/lights
|
||||
mkdir $VENV_DIR
|
||||
python -m venv $VENV_DIR/.venv
|
||||
source $VENV_DIR/.venv/bin/activate
|
||||
pip install homeassistant-api
|
||||
'';
|
||||
}
|
||||
42
hosts/desktop/hyprland/config/waybar/scripts/hass.py
Normal file
42
hosts/desktop/hyprland/config/waybar/scripts/hass.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
import argparse
|
||||
import time
|
||||
from homeassistant_api import Client
|
||||
|
||||
hass_url = 'https://hass.mjallen.dev/api'
|
||||
|
||||
parser = argparse.ArgumentParser(prog='hass python wrapper')
|
||||
parser.add_argument('--toggle_light')
|
||||
args = parser.parse_args()
|
||||
|
||||
def loadKey():
|
||||
token_path = ""
|
||||
for folder in range(1,100):
|
||||
if os.path.exists("/run/secrets.d/" + str(folder) + "/desktop/hass_token"):
|
||||
token_path = "/run/secrets.d/" + str(folder) + "/desktop/hass_token"
|
||||
break
|
||||
with open(token_path, "r") as key_file:
|
||||
key = key_file.readline()
|
||||
return key
|
||||
|
||||
def toggle_light(client, light):
|
||||
lights = client.get_domain("light")
|
||||
lights.toggle(entity_id=light)
|
||||
time.sleep(0.5)
|
||||
light_entity = client.get_entity(entity_id=light)
|
||||
state = light_entity.get_state()
|
||||
if state.state == 'on':
|
||||
return ""
|
||||
else:
|
||||
return ""
|
||||
|
||||
def main():
|
||||
token = loadKey()
|
||||
|
||||
with Client(hass_url, token) as client:
|
||||
if args.toggle_light is not None:
|
||||
status = toggle_light(client=client, light=args.toggle_light)
|
||||
|
||||
print("{ text: \"" + status + "\" }")
|
||||
|
||||
main()
|
||||
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i python3 --pure
|
||||
#! nix-shell -p python3
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i python3 --pure
|
||||
#! nix-shell -p python3 python3Packages.requests
|
||||
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
let
|
||||
|
||||
waybarWeatherScript = pkgs.writeScriptBin "waybar-weather" ''
|
||||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i bash --packages python3 python3Packages.requests
|
||||
python /home/matt/.config/waybar/scripts/waybar-wttr.py
|
||||
/home/matt/.config/waybar/scripts/waybar-wttr.py
|
||||
'';
|
||||
|
||||
waybarUpdatesScript = pkgs.writeScriptBin "waybar-updates" ''
|
||||
|
||||
@@ -6,5 +6,8 @@
|
||||
sops.secrets."desktop/matt_password" = { };
|
||||
sops.secrets."desktop/matt_password".neededForUsers = true;
|
||||
|
||||
sops.secrets."desktop/hass_token" = { };
|
||||
sops.secrets."desktop/hass_token".mode = "0777";
|
||||
|
||||
sops.secrets."wifi" = { };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user