From 7a371654de115aa8ea74554ee7105e493cb03f07 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Sun, 15 Jan 2023 10:43:10 +0100 Subject: [PATCH] wip --- flake.lock | 8 +- nixos/machines/pepe/configuration.nix | 1 + nixos/machines/pepe/hass.nix | 20 ++++ nixos/machines/pepe/home-assistant.nix | 18 +-- nixos/machines/pepe/home-assistant/mqtt.nix | 49 ++++---- .../pepe/home-assistant/zigbee2mqtt.nix | 64 +++++------ .../zigbee2mqtt/configurationHelper.nix | 2 +- .../home-assistant/zigbee2mqtt/temperatur.nix | 106 +++++++++--------- 8 files changed, 141 insertions(+), 127 deletions(-) create mode 100644 nixos/machines/pepe/hass.nix diff --git a/flake.lock b/flake.lock index 3d7ece6..15a228e 100644 --- a/flake.lock +++ b/flake.lock @@ -816,11 +816,11 @@ "private_assets": { "flake": false, "locked": { - "lastModified": 1666443661, - "narHash": "sha256-8cAQush+8XSIa4UZi3MtJljaUjg/tUUBypny/CHvGBQ=", + "lastModified": 1673774076, + "narHash": "sha256-lKzJ0lpLPR/zm7JvnMeISAGk3Au1RKxKXO6t6cn5gW8=", "ref": "main", - "rev": "ff82fc815f2699a29ed549337e77d77971ad6cfe", - "revCount": 3, + "rev": "f51b139fd76988e9c31792e39bfd88085477654a", + "revCount": 4, "type": "git", "url": "ssh://gitea@git.ingolf-wagner.de/palo/nixos-private-assets.git" }, diff --git a/nixos/machines/pepe/configuration.nix b/nixos/machines/pepe/configuration.nix index 8ff221c..8d2d783 100644 --- a/nixos/machines/pepe/configuration.nix +++ b/nixos/machines/pepe/configuration.nix @@ -7,6 +7,7 @@ ./mail-fetcher.nix ./packages.nix + ./hass.nix #./home-assistant.nix #./kodi.nix ./syncthing.nix diff --git a/nixos/machines/pepe/hass.nix b/nixos/machines/pepe/hass.nix new file mode 100644 index 0000000..de39823 --- /dev/null +++ b/nixos/machines/pepe/hass.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: +{ + + imports = [ + ./home-assistant/zigbee2mqtt.nix + ]; + + virtualisation.oci-containers = { + backend = "podman"; + containers.homeassistant = { + volumes = [ "home-assistant:/config" ]; + environment.TZ = "Europe/Berlin"; + image = "ghcr.io/home-assistant/home-assistant:stable"; # Warning: if the tag does not change, the image will not be updated + extraOptions = [ + "--network=host" + ]; + }; + }; + +} diff --git a/nixos/machines/pepe/home-assistant.nix b/nixos/machines/pepe/home-assistant.nix index 9c4e5ea..b91c6e8 100644 --- a/nixos/machines/pepe/home-assistant.nix +++ b/nixos/machines/pepe/home-assistant.nix @@ -3,15 +3,15 @@ imports = [ #./home-assistant/mpd.nix #./home-assistant/timer.nix - ./home-assistant/light-control.nix - ./home-assistant/iot-control.nix - ./home-assistant/chaospott.nix - ./home-assistant/kodi.nix - ./home-assistant/mqtt.nix - ./home-assistant/sonoff.nix - ./home-assistant/stocks.nix - ./home-assistant/weather.nix - ./home-assistant/workday.nix + #./home-assistant/light-control.nix + #./home-assistant/iot-control.nix + #./home-assistant/chaospott.nix + #./home-assistant/kodi.nix + #./home-assistant/mqtt.nix + #./home-assistant/sonoff.nix + #./home-assistant/stocks.nix + #./home-assistant/weather.nix + #./home-assistant/workday.nix ./home-assistant/zigbee2mqtt.nix ]; diff --git a/nixos/machines/pepe/home-assistant/mqtt.nix b/nixos/machines/pepe/home-assistant/mqtt.nix index f82584b..caf30f1 100644 --- a/nixos/machines/pepe/home-assistant/mqtt.nix +++ b/nixos/machines/pepe/home-assistant/mqtt.nix @@ -1,31 +1,32 @@ { lib, ... }: { - services.homeAssistantConfig.mqtt = { - # discovery = false; - # for mosquitto - broker = "127.0.0.1"; - username = lib.fileContents ; - password = lib.fileContents ; + # services.mosquitto = { + # enable = true; + # host = "0.0.0.0"; + # users = { + # homeassistant = { + # password = lib.fileContents ; + # acl = [ "topic readwrite #" ]; + # }; + # zigbee = { + # password = lib.fileContents ; + # acl = [ "topic readwrite #" ]; + # }; + # #lightcontrol = { + # # password = "password"; + # # acl = [ "topic readwrite #" ]; + # #}; + # }; + # }; - }; services.mosquitto = { - enable = true; - host = "0.0.0.0"; - users = { - homeassistant = { - password = lib.fileContents ; - acl = [ "topic readwrite #" ]; - }; - zigbee = { - password = lib.fileContents ; - acl = [ "topic readwrite #" ]; - }; - lightcontrol = { - password = "password"; - acl = [ "topic readwrite #" ]; - }; - }; - }; + enable = true; + listeners = [ { + acl = [ "pattern readwrite #" ]; + omitPasswordAuth = true; + settings.allow_anonymous = true; + } ]; +}; } diff --git a/nixos/machines/pepe/home-assistant/zigbee2mqtt.nix b/nixos/machines/pepe/home-assistant/zigbee2mqtt.nix index 019093e..543507a 100644 --- a/nixos/machines/pepe/home-assistant/zigbee2mqtt.nix +++ b/nixos/machines/pepe/home-assistant/zigbee2mqtt.nix @@ -1,43 +1,41 @@ -{ pkgs, lib, config, ... }: -# no need to set ZIGBEE2MQTT_DATA anymore -assert lib.versionOlder lib.version "21.03"; +{ pkgs, lib, config, private_assets, ... }: { imports = [ ./mqtt.nix - ./zigbee2mqtt/service.nix - ./zigbee2mqtt/buttons.nix - ./zigbee2mqtt/configurationHelper.nix - ./zigbee2mqtt/doors.nix - ./zigbee2mqtt/fyrtur.nix - ./zigbee2mqtt/heater.nix - ./zigbee2mqtt/leds.nix - ./zigbee2mqtt/lights.nix - ./zigbee2mqtt/motion.nix - ./zigbee2mqtt/repeater.nix - ./zigbee2mqtt/temperatur.nix + #./zigbee2mqtt/service.nix + #./zigbee2mqtt/buttons.nix + #./zigbee2mqtt/configurationHelper.nix + #./zigbee2mqtt/doors.nix + #./zigbee2mqtt/fyrtur.nix + #./zigbee2mqtt/heater.nix + #./zigbee2mqtt/leds.nix + #./zigbee2mqtt/lights.nix + #./zigbee2mqtt/motion.nix + #./zigbee2mqtt/repeater.nix + #./zigbee2mqtt/temperatur.nix ]; - custom.services.zigbee2mqtt = { + services.zigbee2mqtt = { enable = true; #package = pkgs.own_zigbee2mqtt; #package = unstable.zigbee2mqtt; - package = pkgs.unstable.zigbee2mqtt.overrideAttrs (old: rec { - version = "1.18.1"; - src = pkgs.fetchFromGitHub { - owner = "Koenkk"; - repo = "zigbee2mqtt"; - rev = version; - sha256 = "1x73k346ayik5hv5axa3nvmd82mgwyrpxqv3dxnffi8aa1r8pf8x"; - }; - }); - config = { + #package = pkgs.unstable.zigbee2mqtt.overrideAttrs (old: rec { + # version = "1.18.1"; + # src = pkgs.fetchFromGitHub { + # owner = "Koenkk"; + # repo = "zigbee2mqtt"; + # rev = version; + # sha256 = "1x73k346ayik5hv5axa3nvmd82mgwyrpxqv3dxnffi8aa1r8pf8x"; + # }; + #}); + settings = { # Home Assistant integration (MQTT discovery) - homeassistant = false; + homeassistant = true; # allow new devices to join - permit_join = false; + permit_join = true; # MQTT settings mqtt = { @@ -47,7 +45,7 @@ assert lib.versionOlder lib.version "21.03"; server = "mqtt://127.0.0.1:1883"; # MQTT server authentication, uncomment if required: user = "zigbee"; - password = lib.fileContents ; + password = lib.fileContents "${private_assets}/zigbee/home-assistant-password"; }; # Serial settings @@ -61,11 +59,9 @@ assert lib.versionOlder lib.version "21.03"; # you own network key, # 16 numbers between 0 and 255 # see https://www.zigbee2mqtt.io/how_tos/how_to_secure_network.html - advanced.network_key = import ; + advanced.network_key = import "${private_assets}/zigbee/networkKey.nix"; advanced.log_output = [ "console" ]; - advanced.pan_id = 1337; - # add last seen information advanced.last_seen = "ISO_8601_local"; @@ -77,10 +73,6 @@ assert lib.versionOlder lib.version "21.03"; }; }; - #systemd.services.zigbee2mqtt.environment = { - # ZIGBEE2MQTT_DATA = "/var/lib/zigbee2mqtt"; - #}; - services.nginx = { enable = true; recommendedProxySettings = true; @@ -89,7 +81,7 @@ assert lib.versionOlder lib.version "21.03"; serverAliases = [ "zigbee.pepe.private" ]; locations."/" = { proxyPass = "http://localhost:${ - toString config.custom.services.zigbee2mqtt.config.frontend.port + toString config.services.zigbee2mqtt.settings.frontend.port }"; proxyWebsockets = true; }; diff --git a/nixos/machines/pepe/home-assistant/zigbee2mqtt/configurationHelper.nix b/nixos/machines/pepe/home-assistant/zigbee2mqtt/configurationHelper.nix index 7d10025..1f5ba5b 100644 --- a/nixos/machines/pepe/home-assistant/zigbee2mqtt/configurationHelper.nix +++ b/nixos/machines/pepe/home-assistant/zigbee2mqtt/configurationHelper.nix @@ -8,5 +8,5 @@ in { device definitions ''; }; - config = { services.zigbee2mqtt.config.devices = cfg; }; + config = { services.zigbee2mqtt.settings.devices = cfg; }; } diff --git a/nixos/machines/pepe/home-assistant/zigbee2mqtt/temperatur.nix b/nixos/machines/pepe/home-assistant/zigbee2mqtt/temperatur.nix index e3f5e3e..5ed7647 100644 --- a/nixos/machines/pepe/home-assistant/zigbee2mqtt/temperatur.nix +++ b/nixos/machines/pepe/home-assistant/zigbee2mqtt/temperatur.nix @@ -16,7 +16,7 @@ let in { - services.zigbee2mqttConfiguration = lib.mapAttrs' + services.zigbee2mqtt.settings = lib.mapAttrs' (name: { id, ... }: { name = id; @@ -27,59 +27,59 @@ in }) allDevices; - services.homeAssistantConfig = { + #services.homeAssistantConfig = { + # # define meta information sensors + # sensor = lib.flatten (lib.mapAttrsToList + # (name: + # { ... }: [ + # { + # platform = "mqtt"; + # name = name; + # state_topic = "zigbee2mqtt/${name}"; + # availability_topic = "zigbee2mqtt/bridge/state"; + # unit_of_measurement = "°C"; + # device_class = "temperature"; + # value_template = "{{ value_json.temperature }}"; + # } + # { + # platform = "mqtt"; + # name = "humidity_${name}"; + # state_topic = "zigbee2mqtt/${name}"; + # availability_topic = "zigbee2mqtt/bridge/state"; + # unit_of_measurement = "%"; + # device_class = "humidity"; + # value_template = "{{ value_json.humidity }}"; + # } + # #{ + # # platform = "mqtt"; + # # name = "pressure_${name}"; + # # state_topic = "zigbee2mqtt/${name}"; + # # availability_topic = "zigbee2mqtt/bridge/state"; + # # unit_of_measurement = "hPa"; + # # device_class = "pressure"; + # # value_template = "{{ value_json.pressure }}"; + # #} + # { + # name = "battery_${name}"; + # platform = "mqtt"; + # state_topic = "zigbee2mqtt/${name}"; + # availability_topic = "zigbee2mqtt/bridge/state"; + # unit_of_measurement = "%"; + # icon = "mdi:battery-10"; + # value_template = "{{ value_json.battery }}"; + # } + # { + # name = "link_${name}"; + # platform = "mqtt"; + # state_topic = "zigbee2mqtt/${name}"; + # availability_topic = "zigbee2mqtt/bridge/state"; + # icon = "mdi:signal"; + # unit_of_measurement = "lqi"; + # value_template = "{{ value_json.linkquality }}"; + # } + # ]) + # allDevices); - # define meta information sensors - sensor = lib.flatten (lib.mapAttrsToList - (name: - { ... }: [ - { - platform = "mqtt"; - name = name; - state_topic = "zigbee2mqtt/${name}"; - availability_topic = "zigbee2mqtt/bridge/state"; - unit_of_measurement = "°C"; - device_class = "temperature"; - value_template = "{{ value_json.temperature }}"; - } - { - platform = "mqtt"; - name = "humidity_${name}"; - state_topic = "zigbee2mqtt/${name}"; - availability_topic = "zigbee2mqtt/bridge/state"; - unit_of_measurement = "%"; - device_class = "humidity"; - value_template = "{{ value_json.humidity }}"; - } - #{ - # platform = "mqtt"; - # name = "pressure_${name}"; - # state_topic = "zigbee2mqtt/${name}"; - # availability_topic = "zigbee2mqtt/bridge/state"; - # unit_of_measurement = "hPa"; - # device_class = "pressure"; - # value_template = "{{ value_json.pressure }}"; - #} - { - name = "battery_${name}"; - platform = "mqtt"; - state_topic = "zigbee2mqtt/${name}"; - availability_topic = "zigbee2mqtt/bridge/state"; - unit_of_measurement = "%"; - icon = "mdi:battery-10"; - value_template = "{{ value_json.battery }}"; - } - { - name = "link_${name}"; - platform = "mqtt"; - state_topic = "zigbee2mqtt/${name}"; - availability_topic = "zigbee2mqtt/bridge/state"; - icon = "mdi:signal"; - unit_of_measurement = "lqi"; - value_template = "{{ value_json.linkquality }}"; - } - ]) - allDevices); # create groups # -------------