From be12face6349f883eb684906df624956c462342a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 3 Mar 2023 20:36:00 +0100 Subject: errol: add zigbee2mqtt --- flake.lock | 26 +++++++++++++------------- nixos/machine/errol.nix | 28 ++++++++++++++++++++++++++++ nixos/modules/home-assistant.nix | 19 ++++++++++++++----- tools/common.sh | 3 ++- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/flake.lock b/flake.lock index 80abbdb..8d87346 100644 --- a/flake.lock +++ b/flake.lock @@ -93,11 +93,11 @@ "nixpkgs-regression": "nixpkgs-regression" }, "locked": { - "lastModified": 1677226426, - "narHash": "sha256-eLBKTZegg9qSyylUbNQQDSwdkz6PT9r/wPqnxcEa2uU=", + "lastModified": 1677847796, + "narHash": "sha256-nuJpPPzJyZvar/aQxTz28pYpdUEmNbuM3grI9YTPMik=", "owner": "NixOS", "repo": "nix", - "rev": "92611e6e4c1c5c712ca7d5f9a258640662d006df", + "rev": "0507462c0626d19b59b78e490b7b203df29e7bb0", "type": "github" }, "original": { @@ -126,11 +126,11 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1677232326, - "narHash": "sha256-rAk2/80kLvA3yIMmSV86T1B4kNvwCFMSQ1FxXndaUB0=", + "lastModified": 1677591639, + "narHash": "sha256-DMlAyge+u3K+JOFLA5YfdjqagdAYJf29YGBWpy5izg4=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "2d44015779cced4eec9df5b8dab238b9f6312cb2", + "rev": "77de4cd09db4dbee9551ed2853cfcf113d7dc5ce", "type": "github" }, "original": { @@ -186,11 +186,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1677098068, - "narHash": "sha256-ZvxvGkPxp0fg/YKqqrW8sapr/1GJ2CmA+IBAFS+NuMs=", + "lastModified": 1677845674, + "narHash": "sha256-9wy/QFibdJUp7WQUe50U5bZKocg3OOHBpJhpl5ddfbE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3d566e183b71fec07b6d466375190f9e79b1e735", + "rev": "dcc47fef8bd1e91baeab8fb34a35337ab8f3a3fd", "type": "github" }, "original": { @@ -266,11 +266,11 @@ }, "personal-secret": { "locked": { - "lastModified": 1676992796, - "narHash": "sha256-Bweyzl164Ce0Vmmg3NVVL8Quj8G+X3/o/gTKgPSMVHU=", + "lastModified": 1677870303, + "narHash": "sha256-w1WHQGNLT7BRKOhe1ryZKRbrC2DH5nc0a5EpqhU+bg0=", "ref": "refs/heads/master", - "rev": "78cb722bb5a2dbfd678c85806252fbdd1c22f5d8", - "revCount": 67, + "rev": "0784e1aefb1352ce15bfce309f11eeac8356b841", + "revCount": 69, "type": "git", "url": "ssh://git@cynerd.cz/nixos-personal-secret" }, diff --git a/nixos/machine/errol.nix b/nixos/machine/errol.nix index 8609956..74901f9 100644 --- a/nixos/machine/errol.nix +++ b/nixos/machine/errol.nix @@ -86,6 +86,7 @@ with lib; { }; met = {}; default_config = {}; + automation = "!include automations.yaml"; }; extraComponents = []; package = pkgs.home-assistant.override { @@ -95,5 +96,32 @@ with lib; { ]; }; }; + + services.zigbee2mqtt = { + enable = true; + settings = { + serial.port = "/dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20220812153849-if00"; + mqtt = { + server = "mqtt://${config.cynerd.hosts.spt.mox}:1883"; + user = "zigbee2mqtt"; + password = "!secret.yaml mqtt_password"; + }; + advanced = { + network_key = "!secret.yaml network_key"; + homeassistant_legacy_entity_attributes = false; + legacy_api = false; + legacy_availability_payload = false; + last_seen = "epoch"; + }; + frontend = true; + availability = true; + homeassistant = { + legacy_triggers = false; + }; + device_options.legacy = false; + permit_join = false; + devices = config.secrets.zigbee2mqttDevices; + }; + }; }; } diff --git a/nixos/modules/home-assistant.nix b/nixos/modules/home-assistant.nix index 0aac9be..545cec8 100644 --- a/nixos/modules/home-assistant.nix +++ b/nixos/modules/home-assistant.nix @@ -21,21 +21,29 @@ in { acl = ["readwrite #"]; passwordFile = "/run/secrets/mosquitto.cynerd.pass"; }; - bigclown = { - acl = ["readwrite bigclown/#"]; - passwordFile = "/run/secrets/mosquitto.bigclown.pass"; - }; telegraf = { acl = ["read bigclown/node/#"]; passwordFile = "/run/secrets/mosquitto.telegraf.pass"; }; homeassistant = { acl = [ - "readwrite bigclown/#" "readwrite homeassistant/#" + "readwrite bigclown/#" + "readwrite zigbee2mqtt/#" ]; passwordFile = "/run/secrets/mosquitto.homeassistant.pass"; }; + bigclown = { + acl = ["readwrite bigclown/#"]; + passwordFile = "/run/secrets/mosquitto.bigclown.pass"; + }; + zigbee2mqtt = { + acl = [ + "readwrite homeassistant/#" + "readwrite zigbee2mqtt/#" + ]; + passwordFile = "/run/secrets/mosquitto.zigbee2mqtt.pass"; + }; }; } ]; @@ -137,6 +145,7 @@ in { }; met = {}; default_config = {}; + automation = "!include automations.yaml"; }; extraComponents = []; package = pkgs.home-assistant.override { diff --git a/tools/common.sh b/tools/common.sh index a6b41fc..3f99479 100644 --- a/tools/common.sh +++ b/tools/common.sh @@ -125,7 +125,8 @@ copy() { store="$(readlink -f "$(result "$device")")" local freespace required; - freespace="$(_ssh "$device" df -B 1 /nix | awk 'NR == 2 { print $4 }')" + freespace_raw="$(_ssh "$device" df -B 1 --output=avail /nix)" + freespace="$(echo "$freespace_raw" | tail -1)" required="$(nix path-info -S "$store" | awk '{ print $2 }')" info "Free space on device: $(numfmt --to=iec "$freespace")" info "Required space: $(numfmt --to=iec "$required")" -- cgit v1.2.3