2020-06-14 11:51:07 +02:00
|
|
|
{ pkgs, lib, ...}:
|
2018-09-18 12:46:39 +02:00
|
|
|
|
|
|
|
let
|
2020-06-14 11:51:07 +02:00
|
|
|
genTopic_zigbee = name: tags: {
|
2018-09-18 12:46:39 +02:00
|
|
|
servers = [ "tcp://localhost:1883" ];
|
|
|
|
username = "stats";
|
2020-06-14 11:51:07 +02:00
|
|
|
password = lib.removeSuffix "\n" (builtins.readFile <secrets/mqtt/stats>);
|
2018-09-18 12:46:39 +02:00
|
|
|
qos = 0;
|
|
|
|
connection_timeout = "30s";
|
2020-06-14 11:51:07 +02:00
|
|
|
topics = [ "/ham/zigbee/${name}" ];
|
|
|
|
inherit tags;
|
2018-09-18 12:46:39 +02:00
|
|
|
persistent_session = false;
|
2020-06-14 11:51:07 +02:00
|
|
|
name_override = "zigbee ${tags.room} ${name}";
|
2018-09-18 12:46:39 +02:00
|
|
|
data_format = "json";
|
2020-06-14 11:51:07 +02:00
|
|
|
json_string_fields = [ "linkquality" "temperature" "humidity" "pressure" "battery" "contact" ];
|
|
|
|
# json_name_key = <filed which defines the name>
|
|
|
|
|
|
|
|
};
|
|
|
|
genTopic_plain = name: topic: tags: {
|
|
|
|
servers = [ "tcp://localhost:1883" ];
|
|
|
|
username = "stats";
|
|
|
|
password = lib.removeSuffix "\n" (builtins.readFile <secrets/mqtt/stats>);
|
|
|
|
qos = 0;
|
|
|
|
connection_timeout = "30s";
|
|
|
|
topics = [ topic ];
|
|
|
|
inherit tags;
|
|
|
|
persistent_session = false;
|
|
|
|
name_override = tags.sensor;
|
|
|
|
data_type = "float";
|
|
|
|
data_format = "value";
|
2018-09-18 12:46:39 +02:00
|
|
|
# json_query = tags.sensor; #TODO?
|
|
|
|
};
|
2020-07-02 08:36:51 +02:00
|
|
|
flycounter = name:
|
|
|
|
(genTopic_plain name ''/ham/flycounter/${name}''
|
|
|
|
{ inherit name;
|
|
|
|
"sensor" = name;
|
|
|
|
"type" = "gauge";
|
|
|
|
"scope" = "ham";
|
|
|
|
} );
|
2020-06-14 11:51:07 +02:00
|
|
|
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;
|
2018-09-18 12:46:39 +02:00
|
|
|
"scope" = "ham";
|
|
|
|
} );
|
2020-06-14 11:51:07 +02:00
|
|
|
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'')
|
|
|
|
];
|
2018-09-18 12:46:39 +02:00
|
|
|
in {
|
2020-06-14 11:51:07 +02:00
|
|
|
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")
|
2020-07-02 08:36:51 +02:00
|
|
|
++ (esphome_temphum "terrasse" "plug")
|
|
|
|
++ [ (flycounter "misa_fliegen") (flycounter "felix_fliegen") ]
|
|
|
|
;
|
2018-09-18 12:46:39 +02:00
|
|
|
}
|