2020-04-15 23:55:21 +02:00
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
|
|
|
|
# https://www.zigbee2mqtt.io/devices/MCCGQ11LM.html
|
|
|
|
allDevices = {
|
2020-04-19 23:28:17 +02:00
|
|
|
"window_sensor_1" = {
|
2020-04-17 20:59:12 +02:00
|
|
|
id = "0x00158d000312dc52";
|
|
|
|
groups = [ "living_room" ];
|
|
|
|
};
|
2020-04-15 23:55:21 +02:00
|
|
|
"door_sensor_2" = {
|
|
|
|
id = "0x00158d000316d5bf";
|
2020-06-01 23:20:15 +02:00
|
|
|
groups = [ "floor_room" ];
|
2020-04-15 23:55:21 +02:00
|
|
|
};
|
2020-04-19 23:28:17 +02:00
|
|
|
"window_sensor_3" = {
|
2020-04-17 20:59:12 +02:00
|
|
|
id = "0x00158d0002f9516f";
|
|
|
|
groups = [ "kitchen_room" ];
|
|
|
|
};
|
2020-04-15 23:55:21 +02:00
|
|
|
"door_sensor_4" = {
|
|
|
|
id = "0x00158d00031383b9";
|
2020-06-01 23:20:15 +02:00
|
|
|
groups = [ "floor_room" ];
|
2020-04-15 23:55:21 +02:00
|
|
|
};
|
2020-04-19 23:28:17 +02:00
|
|
|
"window_sensor_5" = {
|
2020-04-17 20:59:12 +02:00
|
|
|
id = "0x00158d0003120d3e";
|
|
|
|
groups = [ "bath_room" ];
|
|
|
|
};
|
2020-04-15 23:55:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
services.zigbee2mqtt.devices = lib.mapAttrs' (name:
|
|
|
|
{ id, ... }: {
|
|
|
|
name = id;
|
|
|
|
value = {
|
|
|
|
retain = false;
|
|
|
|
friendly_name = name;
|
|
|
|
};
|
|
|
|
}) allDevices;
|
|
|
|
|
|
|
|
services.homeAssistantConfig = {
|
|
|
|
|
|
|
|
# define meta information sensors
|
|
|
|
sensor = lib.flatten (lib.mapAttrsToList (name:
|
|
|
|
{ ... }: [
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
binary_sensor = lib.mapAttrsToList (name:
|
|
|
|
{ ... }: {
|
|
|
|
name = name;
|
|
|
|
platform = "mqtt";
|
|
|
|
device_class = "door";
|
|
|
|
state_topic = "zigbee2mqtt/${name}";
|
|
|
|
availability_topic = "zigbee2mqtt/bridge/state";
|
|
|
|
payload_on = false;
|
|
|
|
payload_off = true;
|
|
|
|
value_template = "{{ value_json.contact}}";
|
|
|
|
}) allDevices;
|
|
|
|
|
|
|
|
# create groups
|
|
|
|
# -------------
|
|
|
|
group = let
|
|
|
|
# to have nice panels for every device
|
|
|
|
sensorGroups = lib.mapAttrs (name:
|
|
|
|
{ ... }: {
|
|
|
|
entities = [
|
|
|
|
"binary_sensor.${name}"
|
|
|
|
"sensor.battery_${name}"
|
|
|
|
"sensor.link_${name}"
|
|
|
|
];
|
|
|
|
}) allDevices;
|
|
|
|
# sort lights into given groups.
|
|
|
|
sortedInGroups = let
|
|
|
|
groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name:
|
|
|
|
{ groups ? [ ], ... }:
|
|
|
|
map (groupName: { "${groupName}" = "binary_sensor.${name}"; }) groups)
|
|
|
|
allDevices));
|
|
|
|
in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
|
|
|
|
in sortedInGroups // sensorGroups // {
|
|
|
|
all_sensors.entities =
|
|
|
|
lib.mapAttrsToList (name: { ... }: "binary_sensor.${name}") allDevices;
|
|
|
|
};
|
2020-06-01 23:20:15 +02:00
|
|
|
|
2020-04-15 23:55:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|