From c8fce8af5101064ea3dcfcb9d2bc39f1b9b83755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 14 Dec 2022 15:20:26 +0100 Subject: Add Home Assistant Now running on Errol as the cross compilation for python cryptography does not work correctly. --- flake.lock | 33 ++++++++++++++---------------- nixos/machine/errol.nix | 28 +++++++++++++++++++++++++ nixos/machine/hass/light.nix | 13 ++++++++++++ nixos/machine/hass/sensors.nix | 19 +++++++++++++++++ nixos/machine/spt-mox.nix | 46 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 nixos/machine/hass/light.nix create mode 100644 nixos/machine/hass/sensors.nix diff --git a/flake.lock b/flake.lock index eb2ae78..9eefb19 100644 --- a/flake.lock +++ b/flake.lock @@ -93,11 +93,11 @@ "nixpkgs-regression": "nixpkgs-regression" }, "locked": { - "lastModified": 1670834436, - "narHash": "sha256-12OrD100TWu+OIANEEfoDBQxuN263OmuzxKOg+/Tb3A=", + "lastModified": 1671015402, + "narHash": "sha256-dxslgojapR/YTbKqo71rZ4clTe10f2yyO7+M4nJnWoE=", "owner": "NixOS", "repo": "nix", - "rev": "c00fb26bed74531882c8f059094bf9e74a715c08", + "rev": "5d77c08858096a3d8f95735ec2227c544f5cdb9c", "type": "github" }, "original": { @@ -126,11 +126,11 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1670174919, - "narHash": "sha256-XdQr3BUnrvVLRFunLWrZORhwYHDG0+9jUUe0Jv1pths=", + "lastModified": 1670959777, + "narHash": "sha256-9nQJWL7S77YZERxairPLFO6TUuF1RgQmdZO6dKRCHz4=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "9d87bc030a0bf3f00e953dbf095a7d8e852dab6b", + "rev": "0fbf27af51a7c9bc68a168fdcd63513c4f100b15", "type": "github" }, "original": { @@ -186,11 +186,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1670807610, - "narHash": "sha256-YdA0bdzjBVJ1e0MjnQh5VjMj7Up/4g/wKwgJQvop1h0=", + "lastModified": 1671005503, + "narHash": "sha256-L5pMUoEAxmqwyAivNKvTcNhxL3xY58Zjh3XYtVO2LaQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3cf892d8ba2940a6bfa37ac6e46c28f90e62ae37", + "rev": "f9b0bd5202a0df10856c9fe4cba0074aa0968047", "type": "github" }, "original": { @@ -267,16 +267,13 @@ "personal-secret": { "locked": { "lastModified": 1670757977, - "narHash": "sha256-CZ6XJb3Ap5RLgaSaCLILrdsEdBuVgVMdrsy/dhDPQF8=", - "ref": "refs/heads/master", - "rev": "0497b71bb7afc1ecf5bf8ea8b655ec44f1bad736", - "revCount": 50, + "narHash": "sha256-113ENvU6bc7uz5i2a5mZhEIfhS58WogqusLCE1e90MM=", "type": "git", - "url": "ssh://git@cynerd.cz/nixos-personal-secret" + "url": "file:///home/cynerd/projects/admin/nixos-personal-secrets" }, "original": { "type": "git", - "url": "ssh://git@cynerd.cz/nixos-personal-secret" + "url": "file:///home/cynerd/projects/admin/nixos-personal-secrets" } }, "root": { @@ -353,11 +350,11 @@ }, "vpsadminos": { "locked": { - "lastModified": 1670691572, - "narHash": "sha256-IVA5SZnzf+yAxJXFklvXM+3NiHJSvO4c0LvdLNTuOl8=", + "lastModified": 1671009350, + "narHash": "sha256-cNKmQdpZsLJmyGhvfAhtDcZf6vb+C50KrFRTH93LT4I=", "owner": "vpsfreecz", "repo": "vpsadminos", - "rev": "6a233ad3d86a06926307510d14096f7d5a6e6d1d", + "rev": "9369766af8e8bc32bcadec29ed12dc671c6e6737", "type": "github" }, "original": { diff --git a/nixos/machine/errol.nix b/nixos/machine/errol.nix index 06e2446..835999a 100644 --- a/nixos/machine/errol.nix +++ b/nixos/machine/errol.nix @@ -60,6 +60,34 @@ with lib; configDir = "/home/cynerd/.config/syncthing"; }; + services.home-assistant = { + enable = true; + openFirewall = true; + configDir = "/var/lib/hass"; + config = { + homeassistant = { + name = "SPT"; + latitude = "!secret latitude"; + longitude = "!secret longitude"; + elevation = "!secret elevation"; + time_zone = "Europe/Prague"; + country = "CZ"; + }; + http.server_port = 8808; + mqtt = { + broker = config.cynerd.hosts.spt.mox; + port = 1883; + username = "homeassistant"; + password = "!secret mqtt_password"; + sensor = import ./hass/sensors.nix; + light = import ./hass/light.nix; + }; + met = {}; + default_config = {}; + }; + extraComponents = []; + }; + }; } diff --git a/nixos/machine/hass/light.nix b/nixos/machine/hass/light.nix new file mode 100644 index 0000000..a9d158b --- /dev/null +++ b/nixos/machine/hass/light.nix @@ -0,0 +1,13 @@ +[ + { + name = "RGB Osvětlení"; + command_topic = "homeassistant/led-strip"; + brightness_scale = 100; + brightness_command_topic = "bigclown/node/power-controller:0/led-strip/-/brightness/set"; + #brightness_state_topic = "bigclown/node/power-controller:0/led-strip/-/brightness/set"; + rgb_command_template = ''"#{{"%02x" % red}}{{"%02x" % green}}{{"%02x" % blue}}"''; + rgb_command_topic = "bigclown/node/power-controller:0/led-strip/-/color/set"; + #rgb_value_template = ''{{int(value[2:4],16)}},{{int(value[5:7],16)}},{{int(value[8:10],16)}}''; + #rgb_state_topic = "bigclown/node/power-controller:0/led-strip/-/color/set"; + } +] diff --git a/nixos/machine/hass/sensors.nix b/nixos/machine/hass/sensors.nix new file mode 100644 index 0000000..fadd4eb --- /dev/null +++ b/nixos/machine/hass/sensors.nix @@ -0,0 +1,19 @@ +[ + { + name = "Teplota"; + state_class = "measurement"; + state_topic = "bigclown/node/climate-monitor:0/thermometer/0:0/temperature"; + unit_of_measurement = "°C"; + } + { + name = "Vlhkost"; + state_class = "measurement"; + state_topic = "bigclown/node/climate-monitor:0/hygrometer/0:4/relative-humidity"; + unit_of_measurement = "%"; + } + { + name = "Osvětlení"; + state_class = "measurement"; + state_topic = "bigclown/node/climate-monitor:0/lux-meter/0:0/illuminance"; + } +] diff --git a/nixos/machine/spt-mox.nix b/nixos/machine/spt-mox.nix index b01c48a..acca74c 100644 --- a/nixos/machine/spt-mox.nix +++ b/nixos/machine/spt-mox.nix @@ -75,6 +75,13 @@ with lib; acl = ["readwrite bigclown/#"]; passwordFile = "/run/secrets/mosquitto.bigclown.pass"; }; + homeassistant = { + acl = [ + "readwrite bigclown/#" + "readwrite homeassistant/#" + ]; + passwordFile = "/run/secrets/mosquitto.homeassistant.pass"; + }; }; } ]; @@ -170,6 +177,45 @@ with lib; serviceConfig.ExecStart = "${pkgs.bigclown-leds}/bin/bigclown-leds /run/secrets/bigclown-leds.ini"; }; + services.home-assistant = { + enable = false; + openFirewall = true; + configDir = "/var/lib/hass"; + config = { + homeassistant = { + name = "SPT"; + latitude = "!secret latitude"; + longitude = "!secret longitude"; + elevation = "!secret elevation"; + time_zone = "Europe/Prague"; + country = "CZ"; + }; + http.server_port = 8808; + mqtt = { + broker = config.cynerd.hosts.spt.mox; + port = 1883; + username = "homeassistant"; + password = "!secret mqtt_password"; + sensor = import ./hass/sensors.nix; + light = import ./hass/light.nix; + }; + met = {}; + default_config = {}; + }; + extraComponents = []; + package = pkgs.home-assistant.override { + packageOverrides = (self: super: { + scapy = super.scapy.override { + withPlottingSupport = false; + }; + s3transfer = super.s3transfer.overridePythonAttrs (oldAttrs: { + dontUsePytestCheck = true; + dontUseSetuptoolsCheck = true; + }); + }); + }; + }; + }; } -- cgit v1.2.3