summaryrefslogtreecommitdiffstats
path: root/lass/2configs/hass
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2023-09-09 19:42:08 +0200
committermakefu <github@syntax-fehler.de>2023-09-09 19:42:08 +0200
commit29d72c898d674d2c18fc0f4a76b5e623de0c3dfe (patch)
treefc4b0695c986a1cda6f1fbbbcbe716e203c54fa3 /lass/2configs/hass
parente157ffa72856e4378aa23b096b2efff233f3cb3d (diff)
parent083229d0211096daec08673f743ccc45b1d8a0ac (diff)
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lass/2configs/hass')
-rw-r--r--lass/2configs/hass/default.nix125
-rw-r--r--lass/2configs/hass/lib.nix256
-rw-r--r--lass/2configs/hass/pyscript/.gitignore1
-rw-r--r--lass/2configs/hass/pyscript/default.nix26
-rw-r--r--lass/2configs/hass/pyscript/shell.nix51
-rw-r--r--lass/2configs/hass/rooms/bett.nix39
-rw-r--r--lass/2configs/hass/rooms/essen.nix9
-rw-r--r--lass/2configs/hass/rooms/nass.nix10
-rw-r--r--lass/2configs/hass/zigbee.nix76
9 files changed, 0 insertions, 593 deletions
diff --git a/lass/2configs/hass/default.nix b/lass/2configs/hass/default.nix
deleted file mode 100644
index 1745bbfe5..000000000
--- a/lass/2configs/hass/default.nix
+++ /dev/null
@@ -1,125 +0,0 @@
-{ config, lib, pkgs, ... }:
-with import ./lib.nix { inherit lib; };
-let
- dwdwfsapi = pkgs.python3Packages.buildPythonPackage rec {
- pname = "dwdwfsapi";
- version = "1.0.3";
-
- src = pkgs.python3Packages.fetchPypi {
- inherit pname version;
- sha256 = "0fcv79xiq0qr4kivhd68iqpgrsjc7djxqs2h543pyr0sdgb5nz9x";
- };
-
- buildInputs = with pkgs.python3Packages; [
- requests ciso8601
- ];
-
- # LC_ALL = "en_US.UTF-8";
- };
-
-in {
- imports = [
- ./pyscript
- ./zigbee.nix
- ./rooms/bett.nix
- ./rooms/essen.nix
- ./rooms/nass.nix
- ];
-
- krebs.iptables.tables.filter.INPUT.rules = [
- { predicate = "-i int0 -p tcp --dport 1883"; target = "ACCEPT"; } # mosquitto
- { predicate = "-i docker0 -p tcp --dport 1883"; target = "ACCEPT"; } # mosquitto
- { predicate = "-i int0 -p tcp --dport 8123"; target = "ACCEPT"; } # hass
- { predicate = "-i int0 -p tcp --dport 1337"; target = "ACCEPT"; } # zigbee2mqtt frontend
- { predicate = "-i retiolum -p tcp --dport 8123"; target = "ACCEPT"; } # hass
- { predicate = "-i retiolum -p tcp --dport 1337"; target = "ACCEPT"; } # zigbee2mqtt frontend
- { predicate = "-i wiregrill -p tcp --dport 8123"; target = "ACCEPT"; } # hass
- ];
-
- services.home-assistant = {
- enable = true;
- configWritable = true;
- lovelaceConfigWritable = true;
- config = let
- tasmota = name: topic: {
- inherit name;
- state_topic = "stat/${topic}/POWER";
- command_topic = "cmnd/${topic}/POWER";
- payload_on = "ON";
- payload_off = "OFF";
- };
- in {
- homeassistant = {
- name = "Home";
- time_zone = "Europe/Berlin";
- latitude = "52.46187";
- longitude = "13.41489";
- elevation = 90;
- unit_system = "metric";
- # customize = friendly_names;
- };
- config = {};
- sun.elevation = 66;
- shopping_list = {};
- discovery = {};
- frontend = {};
- http = {};
- # mqtt = {
- # broker = "localhost";
- # port = 1883;
- # client_id = "home-assistant";
- # username = "gg23";
- # password = "gg23-mqtt";
- # keepalive = 60;
- # protocol = 3.1;
-
- # discovery = true;
- # birth_message = {
- # topic = "/hass/status";
- # payload = "online";
- # };
- # will_message = {
- # topic = "/hass/status";
- # payload = "offline";
- # };
- # };
- sensor = [
- {
- platform = "dwd_weather_warnings";
- region_name = "Berlin";
- }
- ];
- mqtt.switch = [
- (tasmota "TV" "tv")
- (tasmota "Drucker Strom" "drucker")
- (tasmota "Waschmaschine" "wasch")
- (tasmota "Stereo Anlage" "stereo")
- (tasmota "Wohnzimmer Lampe" "wohn_lampe")
- ];
- mobile_app = {};
- weather = [
- {
- platform = "openweathermap";
- api_key = "xxx"; # TODO put into secrets
- }
- ];
- system_health = {};
- history = {};
- shopping_list = {};
- media_player = {
- platform = "snapcast";
- host = "127.0.0.1";
- };
- };
- };
-
- services.mosquitto = {
- enable = true;
- listeners = [{
- acl = [ ];
- users.gg23 = { acl = [ "readwrite #" ]; password = "gg23-mqtt"; };
- }];
- };
-
- environment.systemPackages = [ pkgs.mosquitto ];
-}
diff --git a/lass/2configs/hass/lib.nix b/lass/2configs/hass/lib.nix
deleted file mode 100644
index 72ff2966f..000000000
--- a/lass/2configs/hass/lib.nix
+++ /dev/null
@@ -1,256 +0,0 @@
-{ lib, ... }:
-rec {
- lights = {
- bett = "l_bett";
- essen = "l_essen";
- arbeit = "l_arbeit";
- nass = "l_nass";
- };
-
- switches = {
- dimmer = {
- bett = "i_bett";
- essen = "i_essen";
- nass = "i_nass";
- };
- };
-
- sensors = {
- movement = {
- essen = "s_essen";
- nass = "s_nass";
- };
- };
-
- friendly_names =
- lib.mapAttrs' (n: v: lib.nameValuePair "light.${v}" { friendly_name = "l.${n}"; }) lights //
- lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_update_available" { friendly_name = "s.${n}_up"; }) switches.dimmer //
- lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_update_available" { friendly_name = "i.${n}_up"; }) sensors.movement //
- lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_update_available" { friendly_name = "l.${n}_up"; }) lights //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_linkquality" { friendly_name = "s.${n}_link"; }) switches.dimmer //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_linkquality" { friendly_name = "i.${n}_link"; }) sensors.movement //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_linkquality" { friendly_name = "l.${n}_link"; }) lights //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_battery" { friendly_name = "s.${n}_bat"; }) switches.dimmer //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_battery" { friendly_name = "i.${n}_bat"; }) sensors.movement //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_action" { friendly_name = "s.${n}_act"; }) switches.dimmer //
- lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_occupancy" { friendly_name = "i.${n}_move"; }) sensors.movement //
- lib.mapAttrs' (n: v: lib.nameValuePair "binary_sensor.${v}_occupancy" { friendly_name = "i.${n}_move"; }) sensors.movement //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_temperature" { friendly_name = "i.${n}_heat"; }) sensors.movement //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_temperature" { friendly_name = "i.${n}_heat"; }) sensors.movement //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_illuminance" { friendly_name = "i.${n}_lux"; }) sensors.movement //
- lib.mapAttrs' (n: v: lib.nameValuePair "sensor.${v}_illuminance" { friendly_name = "i.${n}_lux"; }) sensors.movement //
- {};
-
- detect_movement = name: sensor: light: delay:
- let
- id = name;
- sensor_ = "binary_sensor.${sensor}_occupancy";
- light_ = "light.${light}";
- in {
- input_boolean."${id}" = {
- };
- timer."${id}" = {
- duration = delay;
- };
- automation = [
- # {
- # alias = "debug detect_movement";
- # trigger = {
- # platform = "state";
- # entity_id = sensor_;
- # };
- # action = [
- # {
- # service = "system_log.write";
- # data_template = {
- # message = "XXXXXXXXXXXXXXXXXXXXXX {{ states('input_boolean.${sensor}_${light}_triggered') == 'on' }}";
- # #message = "XXXXXXXXXXXXXXXXXXXXXX {{ state_attr('trigger.to_state.state', 'illuminance') }}";
- # };
- # }
- # ];
- # }
- {
- alias = "movement reset timer ${id}";
- trigger = {
- platform = "state";
- entity_id = sensor_;
- from = "off";
- to = "on";
- };
- action = [
- {
- service = "timer.cancel";
- data_template.entity_id = "timer.${id}";
- }
- ];
- }
- {
- alias = "movement on ${id}";
- trigger = {
- platform = "state";
- entity_id = "binary_sensor.${sensor}_occupancy";
- from = "off";
- to = "on";
- };
- condition = {
- condition = "and";
- conditions = [
- {
- condition = "template";
- value_template = "{{ trigger.to_state.attributes.illuminance < 7500 }}";
- }
- {
- condition = "template";
- value_template = "{{ states('${light_}') == 'off' }}";
- }
- ];
- };
- action = [
- {
- service = "light.turn_on";
- data_template = {
- entity_id = light_;
- brightness = "100";
- };
- }
- { delay = "0:00:02"; }
- {
- service = "input_boolean.turn_on";
- data_template.entity_id = "input_boolean.${id}";
- }
- ];
- }
- {
- alias = "movement off ${id}";
- trigger = {
- platform = "state";
- entity_id = sensor_;
- from = "on";
- to = "off";
- };
- condition = {
- condition = "template";
- value_template = "{{ states('input_boolean.${id}') == 'on' }}";
- };
- action = [
- {
- service = "timer.start";
- entity_id = "timer.${id}";
- }
- ];
- }
- {
- alias = "movement override ${id}";
- trigger = {
- platform = "state";
- entity_id = light_;
- };
- action = [
- {
- service = "input_boolean.turn_off";
- data_template.entity_id = "input_boolean.${id}";
- }
- {
- service = "system_log.write";
- data_template = {
- message = "XXXXXXXXXXXXXXXXXXXXXX {{ trigger }}";
- };
- }
- ];
- }
- {
- alias = "movement expired ${id}";
- trigger = {
- platform = "event";
- event_type = "timer.finished";
- event_data.entity_id = "timer.${id}";
- };
- action = [
- {
- service = "light.turn_off";
- data_template = {
- entity_id = light_;
- };
- }
- {
- service = "input_boolean.turn_off";
- data_template.entity_id = "input_boolean.${id}";
- }
- ];
- }
- ];
- };
-
- lightswitch = name: switch: light: {
- automation = [
- {
- alias = "lightswitch ${name} turn on";
- trigger = {
- platform = "mqtt";
- topic = "zigbee/${switch}";
- };
- condition = {
- condition = "or";
- conditions = [
- {
- condition = "template";
- value_template = "{{ trigger.payload_json.action == 'on-press' }}";
- }
- {
- condition = "template";
- value_template = "{{ trigger.payload_json.action == 'up-press' }}";
- }
- {
- condition = "and";
- conditions = [
- {
- condition = "template";
- value_template = "{{ trigger.payload_json.action == 'down-press' }}";
- }
- {
- condition = "template";
- value_template = "{{ trigger.payload_json.brightness > 30 }}";
- }
- ];
- }
- ];
- };
- action = [
- {
- service = "light.turn_on";
- data_template = {
- entity_id = "light.${light}";
- brightness = "{{ trigger.payload_json.brightness }}";
- };
- }
- ];
- }
- {
- alias = "lightswitch ${name} turn off";
- trigger = {
- platform = "mqtt";
- topic = "zigbee/${switch}";
- };
- condition = {
- condition = "or";
- conditions = [
- {
- condition = "template";
- value_template = "{{ trigger.payload_json.action == 'off-press' }}";
- }
- {
- condition = "template";
- value_template = "{{ trigger.payload_json.brightness < 30 }}";
- }
- ];
- };
- action = {
- service = "light.turn_off";
- data_template = {
- entity_id = "light.${light}";
- };
- };
- }
- ];
- };
-}
diff --git a/lass/2configs/hass/pyscript/.gitignore b/lass/2configs/hass/pyscript/.gitignore
deleted file mode 100644
index 282debf56..000000000
--- a/lass/2configs/hass/pyscript/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-hass_token
diff --git a/lass/2configs/hass/pyscript/default.nix b/lass/2configs/hass/pyscript/default.nix
deleted file mode 100644
index c56967e4b..000000000
--- a/lass/2configs/hass/pyscript/default.nix
+++ /dev/null
@@ -1,26 +0,0 @@
-{ config, lib, pkgs, ... }:
-{
- systemd.tmpfiles.rules = [
- "L+ /var/lib/hass/custom_components/pyscript - - - - ${pkgs.fetchzip {
- url = "https://github.com/custom-components/pyscript/releases/download/1.3.2/hass-custom-pyscript.zip";
- sha256 = "0cqdjj46s5xp4mqxb0ic790jm1xp3z0zr2n9f7bsfl5zpvdshl8z";
- stripRoot = false;
- }}"
- ];
-
- services.home-assistant = {
- package = (pkgs.home-assistant.overrideAttrs (old: {
- doInstallCheck = false;
- })).override {
- extraPackages = pp: [ pp.croniter ];
- };
- config.pyscript = {
- allow_all_imports = true;
- hass_is_global = true;
- };
- };
-
- networking.firewall.interfaces.retiolum.allowedTCPPortRanges = [
- { from = 50321; to = 50341; } # for ipython interactive debugging
- ];
-}
diff --git a/lass/2configs/hass/pyscript/shell.nix b/lass/2configs/hass/pyscript/shell.nix
deleted file mode 100644
index 3cfac0275..000000000
--- a/lass/2configs/hass/pyscript/shell.nix
+++ /dev/null
@@ -1,51 +0,0 @@
-{ pkgs ? import <nixpkgs> {} }: let
-
- hass_host = "styx.r";
- hass_token = builtins.readFile ./hass_token;
-
- mach-nix = import (builtins.fetchGit {
- url = "https://github.com/DavHau/mach-nix/";
- ref = "refs/tags/3.4.0";
- }) {
- pkgs = pkgs;
- };
- pyenv = mach-nix.mkPython {
- requirements = ''
- hass_pyscript_kernel
- '';
- };
- jupyter = import (builtins.fetchGit {
- url = https://github.com/tweag/jupyterWith;
- ref = "master";
- }) {};
-
- pyscriptKernel = {
- spec = pkgs.runCommand "pyscript" {} ''
- mkdir -p $out/kernels/pyscript
- cp ${kernel_json} $out/kernels/pyscript/kernel.json
- cp ${pyscript_conf} $out/kernels/pyscript/pyscript.conf
- '';
- runtimePackages = [ pyenv ];
- };
-
- kernel_json = pkgs.writeText "kernel.json" (builtins.toJSON {
- argv = [
- "${pyenv}/bin/python3" "-m" "hass_pyscript_kernel"
- "-f" "{connection_file}"
- ];
- display_name = "hass_pyscript";
- language = "python";
- });
-
- pyscript_conf = pkgs.writeText "pyscript.conf" ''
- [homeassistant]
- hass_host = ${hass_host}
- hass_url = http://''${hass_host}:8123
- hass_token = ${hass_token}
- '';
-
- jupyterEnvironment = jupyter.jupyterlabWith {
- kernels = [ pyscriptKernel ];
- };
-
-in jupyterEnvironment.env
diff --git a/lass/2configs/hass/rooms/bett.nix b/lass/2configs/hass/rooms/bett.nix
deleted file mode 100644
index 026c5722c..000000000
--- a/lass/2configs/hass/rooms/bett.nix
+++ /dev/null
@@ -1,39 +0,0 @@
-{ lib, ... }:
-with import ../lib.nix { inherit lib; };
-
-{
- services.home-assistant.config = lib.mkMerge [
- (lightswitch "bett" switches.dimmer.bett lights.bett)
- ];
-
- # lass.hass.love = {
- # resources = [{
- # url = "https://raw.githubusercontent.com/ljmerza/light-entity-card/master/dist/light-entity-card.js.map";
- # type = "js";
- # }];
- # views = [{
- # title = "bett";
- # cards = [
- # {
- # type = "markdown";
- # title = "hello world";
- # content = "This is just a test";
- # }
- # {
- # type = "light";
- # entity = "light.${lights.bett}";
- # }
- # {
- # type = "custom:light-entity-card";
- # entity = "light.${lights.bett}";
- # }
- # {
- # type = "history-graph";
- # entities = [
- # "light.${lights.bett}"
- # ];
- # }
- # ];
- # }];
- # };
-}
diff --git a/lass/2configs/hass/rooms/essen.nix b/lass/2configs/hass/rooms/essen.nix
deleted file mode 100644
index 293935f65..000000000
--- a/lass/2configs/hass/rooms/essen.nix
+++ /dev/null
@@ -1,9 +0,0 @@
-{ lib, ... }:
-with import ../lib.nix { inherit lib; };
-
-{
- services.home-assistant.config = lib.mkMerge [
- (detect_movement "essen" sensors.movement.essen lights.essen 70)
- (lightswitch "essen" switches.dimmer.essen lights.essen)
- ];
-}
diff --git a/lass/2configs/hass/rooms/nass.nix b/lass/2configs/hass/rooms/nass.nix
deleted file mode 100644
index b23ba86cd..000000000
--- a/lass/2configs/hass/rooms/nass.nix
+++ /dev/null
@@ -1,10 +0,0 @@
-{ lib, ... }:
-with import ../lib.nix { inherit lib; };
-
-{
- services.home-assistant.config = lib.mkMerge [
- (detect_movement "nass" sensors.movement.nass lights.nass 100)
- (lightswitch "nass" switches.dimmer.nass lights.nass)
- ];
-}
-
diff --git a/lass/2configs/hass/zigbee.nix b/lass/2configs/hass/zigbee.nix
deleted file mode 100644
index 210c761b5..000000000
--- a/lass/2configs/hass/zigbee.nix
+++ /dev/null
@@ -1,76 +0,0 @@
-{config, pkgs, lib, ...}: let
-
- unstable-pkgs = import <nixpkgs-unstable> {};
-
-in {
- # symlink the zigbee controller
- services.udev.extraRules = ''
- SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="cc2531", MODE="0660", GROUP="dialout"
- SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="cc2652", MODE="0660", GROUP="dialout"
- '';
-
- # needed to use unstable package
- systemd.services.zigbee2mqtt.environment.ZIGBEE2MQTT_DATA = "/var/lib/zigbee2mqtt";
-
- services.zigbee2mqtt = {
- enable = true;
- package = unstable-pkgs.zigbee2mqtt;
- settings = {
- homeassistant = true;
- frontend.port = 1337;
- experimental.new_api = true;
- permit_join = false;
- mqtt = {
- discovery = true;
- base_topic = "zigbee";
- server = "mqtt://10.42.0.1";
- user = "gg23";
- password = "gg23-mqtt";
- };
- serial = {
- port = "/dev/cc2652";
- # disable_led = true;
- };
- advanced = {
- pan_id = 4222;
- };
- devices = let
- set_device = id: name:
- lib.nameValuePair id {
- };
- in {
- # lights https://www.zigbee2mqtt.io/devices/9290022166.html#philips-9290022166
- "0x0017880106ed3bd8".friendly_name = "l_bett";
- "0x0017880108327622".friendly_name = "l_essen";
- "0x0017880106ee2865".friendly_name = "l_arbeit";
- "0x00178801082e9f2f".friendly_name = "l_nass";
-
- # switches https://www.zigbee2mqtt.io/devices/324131092621.html#philips-324131092621
- "0x00178801086ac38c".friendly_name = "i_bett";
- "0x00178801086ad1fb".friendly_name = "i_essen";
- "0x00178801086ac373".friendly_name = "i_nass";
-
- # sensors https://www.zigbee2mqtt.io/devices/9290012607.html#philips-9290012607
- "0x0017880106f772f2".friendly_name = "s_essen";
- "0x0017880106f77f30".friendly_name = "s_nass";
-
- # heat https://www.zigbee2mqtt.io/devices/701721.html#popp-701721
- "0x842e14fffe27109a".friendly_name = "t_bett";
- "0x842e14fffe269a73".friendly_name = "t_nass";
- "0x842e14fffe269a56".friendly_name = "t_arbeit";
-
- # rotation https://www.zigbee2mqtt.io/devices/E1744.html
- "0x8cf681fffe065493" = {
- friendly_name = "r_test";
- device_id = "r_test";
- simulated_brightness = {
- delta = 2;
- interval = 100;
- };
- };
-
- };
- };
- };
-}
-