commit c11294c03fdd7e1c69a38caed16079a2e00a69ab
parent c6f28e2d1d2511fe32c0a474a5cadbc1daf0288d
Author: Leah (ctucx) <git@ctu.cx>
Date: Mon, 18 Nov 2024 16:22:09 +0100
parent c6f28e2d1d2511fe32c0a474a5cadbc1daf0288d
Author: Leah (ctucx) <git@ctu.cx>
Date: Mon, 18 Nov 2024 16:22:09 +0100
machines/briefkasten/smarthome: cleanup
10 files changed, 2 insertions(+), 328 deletions(-)
M
|
92
-------------------------------------------------------------------------------
M
|
88
-------------------------------------------------------------------------------
diff --git a/machines/briefkasten/smarthome/default.nix b/machines/briefkasten/smarthome/default.nix @@ -4,17 +4,14 @@ imports = [ ./mosquitto.nix -# ./mbusd.nix ./zigbee2mqtt.nix -# ./sdm2mqtt.nix -# ./departures2mqtt.nix ./influxdb2.nix ./telegraf.nix ./mqtt-webui - ./homebridge.nix +# ./homebridge.nix ]; }
diff --git a/machines/briefkasten/smarthome/departures2mqtt.nix b/machines/briefkasten/smarthome/departures2mqtt.nix @@ -1,39 +0,0 @@ -{ inputs, config, pkgs, ... }: - -{ - - systemd.services.departures2mqtt = { - startAt = [ - "*-*-* 00..09:00/5" - "*-*-* 10..19:00/2" - "*-*-* 20..23:00/5" - ]; - - serviceConfig = { - Type = "oneshot"; - ExecStart = "${pkgs.departures2mqtt}/bin/departures2mqtt --mqtt-host=[::1] --mqtt-topic=departures2mqtt --stations=1505,2946,2187"; - - DynamicUser = true; - - NoNewPrivileges = true; - PrivateTmp = true; - - ProtectSystem = "strict"; - ProtectKernelLogs = true; - ProtectKernelModules = true; - ProtectKernelTunables = true; - ProtectControlGroups = true; - ProtectHome = true; - - RestrictAddressFamilies = "AF_INET AF_INET6"; - RestrictNamespaces = true; - RestrictRealtime = true; - - DevicePolicy = "closed"; - LockPersonality = true; - - LimitNPROC = 1; - }; - }; - -}
diff --git a/machines/briefkasten/smarthome/influxdb2.nix b/machines/briefkasten/smarthome/influxdb2.nix @@ -34,96 +34,4 @@ }; }; -# systemd.services.power-history = { -# startAt = "0/2:00:00"; -# path = with pkgs; [ curl jq mosquitto ]; -# -# serviceConfig = { -# NoNewPrivileges = true; -# PrivateTmp = true; -# -# ProtectSystem = "strict"; -# ProtectKernelLogs = true; -# ProtectKernelModules = true; -# ProtectKernelTunables = true; -# ProtectControlGroups = true; -# ProtectHome = true; -# -# RestrictNamespaces = true; -# RestrictRealtime = true; -# -# DevicePolicy = "closed"; -# LockPersonality = true; -# }; -# -# script = '' -# QUERY=$(cat <<-END -# import "timezone" -# import "date" -# import "math" -# -# option location = {zone: "Europe/Berlin", offset: 0h} -# option header = false -# -# date_start = date.truncate(t: date.sub(from: now(), d: 3y), unit: 1d) -# date_stop = date.truncate(t: now(), unit: 1d) -# -# data = -# from(bucket: "mqttData") -# |> range(start: date_start, stop: date_stop) -# |> filter(fn: (r) => r.topic == "sdm2mqtt/leah" and r._field == "import") -# |> drop(columns: ["_field", "_measurement", "topic", "host"]) -# -# //daily aggregation -# data -# // Windows and aggregates the data -# |> range(start: -30d, stop: now()) -# |> aggregateWindow(every: duration(v: 1d), fn: max, createEmpty: false, timeSrc: "_start") -# |> difference() -# |> drop(columns: ["_start", "_stop"]) -# |> map(fn: (r) => ({r with _value: (math.round(x: r._value * 100.0) / 100.0)})) -# |> map(fn: (r) => ({r with _time: string(v: date.year(t: r._time))+"-"+string(v: date.month(t: r._time))+"-"+string(v: date.monthDay(t: r._time))})) -# |> yield(name: "d") -# -# //weekly aggregation -# data -# // Windows and aggregates the data -# |> aggregateWindow(every: duration(v: 1w), fn: max, createEmpty: false, offset: -3d, timeSrc: "_start") -# |> difference() -# |> drop(columns: ["_start", "_stop"]) -# |> map(fn: (r) => ({r with _value: (math.round(x: r._value * 100.0) / 100.0)})) -# |> map(fn: (r) => ({r with _time: string(v: date.year(t: r._time))+"-"+string(v: date.week(t: r._time))})) -# |> yield(name: "w") -# -# //monthly aggregation -# data -# // Windows and aggregates the data -# |> aggregateWindow(every: duration(v: 1mo), fn: max, createEmpty: false, timeSrc: "_start") -# |> difference() -# |> drop(columns: ["_start", "_stop"]) -# |> map(fn: (r) => ({r with _value: (math.round(x: r._value * 100.0) / 100.0)})) -# |> map(fn: (r) => ({r with _time: string(v: date.year(t: r._time))+"-"+string(v: date.month(t: r._time))})) -# |> yield(name: "m") -# -# //yearly aggregation -# data -# // Windows and aggregates the data -# |> aggregateWindow(every: duration(v: 1y), fn: max, createEmpty: false, timeSrc: "_start") -# |> difference() -# |> drop(columns: ["_start", "_stop"]) -# |> map(fn: (r) => ({r with _value: (math.round(x: r._value * 100.0) / 100.0)})) -# |> map(fn: (r) => ({r with _time: string(v: date.year(t: r._time))})) -# |> yield(name: "y") -# -# END -# ) -# -# REQUEST_BODY=`echo '{"dialect": { "header": false}}' | jq --arg q "''${QUERY}" '.query=$q'` -# RESPONSE=`curl -X POST 'https://influx.home.ctu.cx/api/v2/query?org=leah' -sS -H 'Accept:application/csv' -H 'Authorization: Token ZrTCG9n8ow-KC_x_HhwJD3VwWS208051WczuIa-3i2M3qmZETdth_XIi5FUTEVKmMXlQ015ujWLRZLjBNbINxQ==' -H 'Content-type:application/json' -d "''${REQUEST_BODY}"` -# MESSAGE=`echo "''${RESPONSE}" | tr -s '\r' '\n' | jq --slurp --raw-input -c 'split("\n") | map(select(length > 0)) | .[1:] | map(split(",")) | map([.[1],.[3],.[4]])'` -# -# mosquitto_pub -h '::1' -r -t 'sdm2mqtt/leah/history' -m "''${MESSAGE}" -# ''; -# }; - }
diff --git a/machines/briefkasten/smarthome/mbusd.nix b/machines/briefkasten/smarthome/mbusd.nix @@ -1,54 +0,0 @@ -{ pkgs, ... }: - -{ - - services.udev.extraRules = ''SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{serial}=="AQ02VMGV", SYMLINK+="modbus0"''; - - systemd.services.mbusd = { - wantedBy = [ "multi-user.target" ]; - requires = [ "network-online.target" "dev-modbus0.device" ]; - wants = [ "network-online.target" "dev-modbus0.device" ]; - after = [ "network-online.target" "dev-modbus0.device" ]; - onFailure = [ "email-notify@%i.service" ]; - - serviceConfig = { - ExecStart = "${pkgs.mbusd}/bin/mbusd -d -v2 -L - -p /dev/modbus0 -s 9600 -m 8n1 -C 32 -N 3 -R 100 -W 500 -T 60 -A ::1 -P 502"; - - Restart = "on-failure"; - RestartSec = "1"; - - StandardOutput = "journal"; - StandardError = "journal"; - - DynamicUser = true; - SupplementaryGroups = [ "dialout" ]; - - NoNewPrivileges = true; - PrivateTmp = true; - - ProtectSystem = "strict"; - ProtectKernelLogs = true; - ProtectKernelModules = true; - ProtectKernelTunables = true; - ProtectControlGroups = true; - ProtectHome = true; - - IPAddressAllow = "::1/128"; - - RestrictAddressFamilies = "AF_INET6"; - RestrictNamespaces = true; - RestrictRealtime = true; - - DevicePolicy = "closed"; - DeviceAllow = [ "/dev/modbus0" ]; - - AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; - - LockPersonality = true; - - LimitNPROC = 1; - - }; - }; - -}
diff --git a/machines/briefkasten/smarthome/mosquitto.nix b/machines/briefkasten/smarthome/mosquitto.nix @@ -7,11 +7,6 @@ file = ./. + "/../../../secrets/${config.networking.hostName}/mosquitto/passwd-leah.age"; owner = "mosquitto"; }; - - mosquitto-passwd-nrw = { - file = ./. + "/../../../secrets/${config.networking.hostName}/mosquitto/passwd-nrw.age"; - owner = "mosquitto"; - }; }; services = { @@ -38,7 +33,6 @@ port = 9005; users = { leah.passwordFile = config.age.secrets.mosquitto-passwd-leah.path; - nrw.passwordFile = config.age.secrets.mosquitto-passwd-nrw.path; }; settings = { protocol = "websockets";
diff --git a/machines/briefkasten/smarthome/mqtt-webui/config.nix b/machines/briefkasten/smarthome/mqtt-webui/config.nix @@ -108,54 +108,6 @@ in { (ColorSpectrumLamp "RGB Lamp" "zigbee2mqtt/ikea_lamp_rgb") - # { - # title = "Power-Meter"; - # items = [ - # { - # title = "Voltage"; - # type = "text"; - # topic = "sdm2mqtt/leah"; - # icon = "icons/power.png"; - # transform = "return Math.round((message.voltage + Number.EPSILON) * 100) / 100 + ' V'"; - # } - # { - # title = "Power"; - # type = "text"; - # topic = "sdm2mqtt/leah"; - # icon = "icons/power.png"; - # transform = "return Math.round((message.power + Number.EPSILON) * 100) / 100 + ' W'"; - # } - # { - # title = "Frequency"; - # type = "text"; - # topic = "sdm2mqtt/leah"; - # icon = "icons/power.png"; - # transform = "return message.frequency + ' Hz'"; - # } - # { - # title = "cos φ"; - # type = "text"; - # topic = "sdm2mqtt/leah"; - # icon = "icons/power.png"; - # transform = "return Math.round((message.cosphi + Number.EPSILON) * 100) / 100"; - # } - # { - # title = "Total Import"; - # type = "text"; - # topic = "sdm2mqtt/leah"; - # icon = "icons/power.png"; - # transform = "return Math.round((message.import + Number.EPSILON) * 100) / 100 + ' kWh'"; - # } - # { - # title = "Archive"; - # type = "text"; - # icon = "icons/sun.png"; - # link = "#powermeterarchive"; - # } - # ]; - # } - - { title = "Temperature-Sensors"; items = [ @@ -259,46 +211,6 @@ in { ]; } - { - id = "powermeterarchive"; - title = "Archive"; - sections = [ - { - items = [ - { - type = "html"; - topic = "sdm2mqtt/leah/history"; - html = "<div class=\"loader\"></div>"; - transform = '' - let output = ""; - - output += '<table><tr><th>Date</th><th>Import</th></tr>'; - message.forEach((data) => { - if ( data[0] == "w" ) { output += '<tr><td>'+data[1]+'</td><td>'+data[2]+' kWh<td></tr>'; } - }); - output += '</table>'; - - output += '<table><tr><th>Date</th><th>Import</th></tr>'; - message.forEach((data) => { - if ( data[0] == "m" ) { output += '<tr><td>'+data[1]+'</td><td>'+data[2]+' kWh<td></tr>'; } - }); - output += '</table>'; - - output += '<table><tr><th>Date</th><th>Import</th></tr>'; - message.forEach((data) => { - if ( data[0] == "y" ) { output += '<tr><td>'+data[1]+'</td><td>'+data[2]+' kWh<td></tr>'; } - }); - output += '</table>'; - - - return output; - ''; - } - ]; - } - ]; - } - ]; } \ No newline at end of file
diff --git a/machines/briefkasten/smarthome/sdm2mqtt.nix b/machines/briefkasten/smarthome/sdm2mqtt.nix @@ -1,30 +0,0 @@ -{ inputs, config, pkgs, ... }: - -{ - - imports = [ - inputs.sdm2mqtt.nixosModule - ]; - - services.sdm2mqtt = { - enable = true; - config = { - devices."leah" = 50; - modbus.host = "::1"; - modbus.port = 502; - mqtt.host = "::1"; - mqtt.port = 1883; - updateInterval = 5; - }; - }; - - systemd.services.sdm2mqtt = { - requires = [ "network-online.target" "mbusd.service" "mosquitto.service" ]; - after = [ "network-online.target" "mbusd.service" "mosquitto.service" ]; - onFailure = [ "email-notify@%i.service" ]; - - serviceConfig.IPAddressAllow = "::1/128"; - serviceConfig.RestrictAddressFamilies = "AF_INET6"; - }; - -}
diff --git a/machines/briefkasten/smarthome/telegraf.nix b/machines/briefkasten/smarthome/telegraf.nix @@ -15,8 +15,6 @@ mqtt_consumer = { servers = [ "tcp://[::1]:1883" ]; topics = [ - "sdm2mqtt/leah" - "lacrosse2mqtt/+" "zigbee2mqtt/tuya_sensor_fridge" "zigbee2mqtt/tuya_sensor_bathroom" "zigbee2mqtt/tuya_sensor_sleepingroom" @@ -30,7 +28,7 @@ influxdb_v2 = [ { urls = [ "http://${toString config.services.influxdb2.settings.http-bind-address}/" ]; - organization = "leah"; + organization = "smarthome"; bucket = "mqttData"; token = "\${INFLUX_TOKEN_MQTTDATA}"; tagdrop.topic = [ "solax2mqtt" ];
diff --git a/secrets/briefkasten/mosquitto/passwd-nrw.age b/secrets/briefkasten/mosquitto/passwd-nrw.age @@ -1,11 +0,0 @@ ------BEGIN AGE ENCRYPTED FILE----- -YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA4ajhva0lTT3BqMk5DRURR -RzNsRFB5aVNoN1pPSVRBbHo1b3gzcTV5Q1gwCmVpelhCL2Y2cy85YUY4WVl4WUZW -c2FHQmo2bmpINkJwWmhtTklXMGd3MW8KLT4gc3NoLWVkMjU1MTkgNGhLQ013IGpi -WkI4em56L3B0STB3K0R4M2RYbVJxVWI4TEk5NkYrTDVGRjFSSFlYUW8Kb24xd3Rn -aVo5SmtYVXJZQkllVlVraWIwTkFhRVpNRVp0MFlxVENjbWRRYwotPiAwayhpLWdy -ZWFzZSBpYXggU1glMnVbIFckXiBYcWIjawpYOGJsemxFMk1Za2FWZ3l0WSsxUHZj -K0cvdFVmVVM3ZFBMNU5YWmJrSWZHN25KcUFxMlJHRGNqZnVkNjJIY1NSCgotLS0g -bXViYlFhYW5sczkyMXNWNVhhRi91WXRhcXkvaVlreE8ycUVMeVE0K2RzbwqtFCcX -HHLh0YZJVWbICVTilSk4zWAKFSJccvisi7VsZlM7bO9HvDQsYmNA5w== ------END AGE ENCRYPTED FILE-----
diff --git a/secrets/secrets.nix b/secrets/secrets.nix @@ -38,7 +38,6 @@ in { "briefkasten/influx/backup_env.age".publicKeys = [ main-key briefkasten ]; "briefkasten/mosquitto/passwd-leah.age".publicKeys = [ main-key briefkasten ]; - "briefkasten/mosquitto/passwd-nrw.age".publicKeys = [ main-key briefkasten ]; "briefkasten/zigbee2mqtt/secrets.age".publicKeys = [ main-key briefkasten ]; "briefkasten/zigbee2mqtt/htpasswd.age".publicKeys = [ main-key briefkasten ];