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" = { };
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ jallen-nas:
|
||||
secretkeybase: ENC[AES256_GCM,data:b+fgTrtnZcp34DOQ0dtKc6bX6/dm9j0o3QJr,iv:e4hOwgTFCXVokGqhwKsYHt5IQgtaKcMmEqvDoMly5aI=,tag:E8gFiOuozA4T1mmcgXfbDg==,type:str]
|
||||
desktop:
|
||||
matt_password: ENC[AES256_GCM,data:z/Jjzr+/PREpNEQsAVl4soeKAwW3sdteIqjhZT2txQDiR0FvGvEBoE/aYCM9NS7XSCgTeTuOqgBGfq4xDLc5/ZBAl7KoGHmKIQ==,iv:qVONkw8PDI2ydqybqGIU2XFq4+qC1BeXnfwxbxbWBww=,tag:eYOD2EoBn9XMiYOaBDFlRw==,type:str]
|
||||
hass_token: ENC[AES256_GCM,data:un4uyUPcr6g8IIWlXvTCpQ5hXms9FZxaVQz+fk1HMNRdfToTI7OLv8XyYOZ4NOZk5OJcLUUcu2S6zDKL0nc6PUqKD/8X8Rc4wVxEPoAZHiH3EBwuj3LSQac9m2Qlgs17vdfRGkpCt52h5ayPwItop1eb222MXHnQWPsslWT7RIN+kuzQ8prj7MU3ag6lqH8dDZjYQutskF1VkXWolQZkAG8gGZPK+C0BXB5Kxlpx4nYD/pQs2eKr,iv:qR5Jn4QcDISEcLzwmPa7hj9+u5JcQuzdB0qLxlYeK8s=,tag:tSN0CaQz6WsFSw+0fVrDYA==,type:str]
|
||||
sops:
|
||||
kms: []
|
||||
gcp_kms: []
|
||||
@@ -49,8 +50,8 @@ sops:
|
||||
UGhsN2N0Mjl3UEJvUVlGRlJiN05WaUkKW37lU4G4CLTo6JoHC2OyhKsG/FuO+BiN
|
||||
pzlVJwzRnmAqwklRbc6RMbQLl2EQrp6KQcgYsUxCMH9OQ/9WJ98dxQ==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
lastmodified: "2024-08-26T14:10:01Z"
|
||||
mac: ENC[AES256_GCM,data:vmu42Qg97HenH7qP3WfwvQGb0yPf4/ViIlFQDig1t1LRenIveY4ZI6WutdM7QQ32FEcqBjuBa0m+K3YYYOmvRqxjWrqgD4Zx9vKKhoAFgYNlLUDahzyuA/o6PTM0MxFA1LWAO7Qu37/DxWuKJ41blhCsiYITlpjrQAzRWagp9r8=,iv:XTxCuBhOY8q5ZiXDL2Qf8149K5xJGs5qFDxBvA6057o=,tag:FNeQfNrHKh45b+K16SFrxw==,type:str]
|
||||
lastmodified: "2024-09-04T16:52:28Z"
|
||||
mac: ENC[AES256_GCM,data:cyM8+Y6p83pd/S3t+/EhA7LZPeMtzCjnD8NUL5wXLnu1AVWraAg8Sx+P3wKj/iy0pTkKZ5d54xUrZeN7mevOvU4LZ9xJXDRIFf0jVUic/XSS5r56w9mG1Z2pCMDdR2wCq36Vx7w4lgMHUcjLc7ca8w256Ky42jLnBY6s1pr38Vs=,iv:4oj8PQA/0wSXmWqTrru+GHF2W6UUfHXHib7Zo/7xNCw=,tag:y7V30iBNuhjEj2jURdCHIg==,type:str]
|
||||
pgp: []
|
||||
unencrypted_suffix: _unencrypted
|
||||
version: 3.9.0
|
||||
|
||||
Reference in New Issue
Block a user