1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 18:21:07 +01:00

feat: rofi-hass

This commit is contained in:
2022-03-13 10:30:42 +01:00
parent 6f1f1887b9
commit 730070bc9d
2 changed files with 15 additions and 0 deletions

View File

@@ -265,6 +265,7 @@ in {
(pkgs.writers.writeDashBin "hass-cli" ''
HASS_SERVER=http://zaatar.r:8123 HASS_TOKEN=${lib.strings.fileContents <secrets/hass/token>} exec ${pkgs.home-assistant-cli}/bin/hass-cli "$@"
'')
scripts.rofi-hass
];
home-manager.users.me.xdg.configFile."pycodestyle".text = ''

View File

@@ -447,6 +447,20 @@ in
${pkgs.wget}/bin/wget -q -N https://github.com/Mic92/nix-index-database/releases/latest/download/$filename
ln -f $filename files
'';
rofi-hass = pkgs.writers.writeBashBin "rofi-hass" ''
export PATH=${lib.makeBinPath [pkgs.home-assistant-cli pkgs.jq pkgs.util-linux pkgs.rofi pkgs.gnused pkgs.libnotify]}
json=$(hass-cli -o json state list 2>/dev/null)
idx=$(jq -r '.[] | [.entity_id, .state] | join(" ")' <<< "$json" | column -t | rofi -dmenu -i -markup-rows -format d)
item=$(jq -r '.[].entity_id' <<< "$json" | sed "''${idx}q;d")
itype=$(sed -r 's/\..+$//' <<< "$item")
case "$itype" in
light) hass-cli state toggle "$item" &>/dev/null ;;
scene) hass-cli service call --arguments entity_id="$item" scene.turn_on &>/dev/null ;;
*) notify-send "Error" "Event type '$itype' not implemented yet. Do you have time to file an issue or write a PR?" ;;
esac
'';
}
// {
devour = pkgs.callPackage <niveum/packages/devour.nix> {};