From 8ff56542bcec27663ab4d8e81ca26f7b33d86902 Mon Sep 17 00:00:00 2001 From: makefu Date: Sun, 14 Jun 2020 11:51:07 +0200 Subject: ma telegraf: add zigbee nodes --- makefu/2configs/stats/telegraf/default.nix | 19 +++++---- makefu/2configs/stats/telegraf/hamstats.nix | 60 ++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/makefu/2configs/stats/telegraf/default.nix b/makefu/2configs/stats/telegraf/default.nix index c60539c71..5a81e2749 100644 --- a/makefu/2configs/stats/telegraf/default.nix +++ b/makefu/2configs/stats/telegraf/default.nix @@ -12,13 +12,18 @@ in { urls = [ url ]; database = "telegraf"; }]; - mqtt = [{ - servers = [ mqtt_server ]; - topic_prefix = "/telegraf"; - data_format = "json"; - qos = 0; - batch = false; - }]; + #file = [{ # debugging + # files = [ "stdout" ]; + # data_format = "influx"; + #}]; + + #mqtt = [{ + # servers = [ mqtt_server ]; + # topic_prefix = "/telegraf"; + # data_format = "json"; + # qos = 0; + # batch = false; + #}]; }; }; }; diff --git a/makefu/2configs/stats/telegraf/hamstats.nix b/makefu/2configs/stats/telegraf/hamstats.nix index 88c1b6d5d..0b1723062 100644 --- a/makefu/2configs/stats/telegraf/hamstats.nix +++ b/makefu/2configs/stats/telegraf/hamstats.nix @@ -1,28 +1,60 @@ -{ pkgs, ...}: +{ pkgs, lib, ...}: let - genTopic = name: topic: tags: { + genTopic_zigbee = name: tags: { servers = [ "tcp://localhost:1883" ]; username = "stats"; - password = builtins.readFile ; + password = lib.removeSuffix "\n" (builtins.readFile ); qos = 0; connection_timeout = "30s"; - topics = [ topic ]; - tags = tags; + topics = [ "/ham/zigbee/${name}" ]; + inherit tags; persistent_session = false; - name_override = name; + name_override = "zigbee ${tags.room} ${name}"; data_format = "json"; + json_string_fields = [ "linkquality" "temperature" "humidity" "pressure" "battery" "contact" ]; + # json_name_key = + + }; + genTopic_plain = name: topic: tags: { + servers = [ "tcp://localhost:1883" ]; + username = "stats"; + password = lib.removeSuffix "\n" (builtins.readFile ); + qos = 0; + connection_timeout = "30s"; + topics = [ topic ]; + inherit tags; + persistent_session = false; + name_override = tags.sensor; + data_type = "float"; + data_format = "value"; # json_query = tags.sensor; #TODO? }; - hamStat = host: - sensor: - (genTopic sensor - "/ham/${host}/${sensor}/tele/SENSOR" - {"host" = host; + esensor = room: name: sensor: + (genTopic_plain sensor ''/ham/${room}/${name}/sensor/${sensor}/state'' + { inherit room sensor name; + "scope" = "ham"; + } ); + zsensor = room: name: + (genTopic_zigbee name + { inherit room name; "scope" = "ham"; - "sensor" = sensor; } ); - bme = host: [(hamStat host "BME280")]; + zigbee_temphum = room: name: [ + (zsensor room name) + ]; + esphome_temphum = room: name: [ + (esensor room name ''${room}_${name}_temperature'') + (esensor room name ''${room}_${name}_humidity'') + (esensor room name ''${room}_${name}_pressure'') + ]; in { - services.telegraf.extraConfig.inputs.mqtt_consumer = (bme "schlafzimmer"); + services.telegraf.extraConfig.inputs.mqtt_consumer = + (zigbee_temphum "Wohnzimmer" "temp1") + ++ (zigbee_temphum "Badezimmer" "temp2") + ++ (zigbee_temphum "Kinderzimmer" "temp3") + ++ (esphome_temphum "arbeitszimmer" "box") + ++ (esphome_temphum "schlafzimmer" "plug") + ++ (esphome_temphum "wohnzimmer" "plug") + ++ (esphome_temphum "terrasse" "plug"); } -- cgit v1.2.3