78 lines
2.1 KiB
Nix
78 lines
2.1 KiB
Nix
{ pkgs, lib, ... }:
|
|
let
|
|
|
|
# https://www.zigbee2mqtt.io/devices/RTCGQ01LM.html
|
|
allDevices = {
|
|
|
|
"motion_sensor_1" = {
|
|
id = "0x00158d0002fbd451";
|
|
groups = [ "kitchen_room" "kitchen_room_present" ];
|
|
};
|
|
"motion_sensor_2" = {
|
|
id = "0x00158d0002f9a6b8";
|
|
groups = [ "bed_room" "bed_room_present" ];
|
|
};
|
|
"motion_sensor_3" = {
|
|
id = "0x00158d0002f04522";
|
|
groups = [ "living_room" "living_room_present" ];
|
|
};
|
|
"motion_sensor_4" = {
|
|
id = "0x00158d0002f9a558";
|
|
groups = [ "living_room" "living_room_present" ];
|
|
};
|
|
"motion_sensor_5" = {
|
|
id = "0x00158d0002f9a56f";
|
|
groups = [ "bath_room" "bath_room_present" ];
|
|
};
|
|
"motion_sensor_6" = {
|
|
id = "0x00158d0002f9a5cb";
|
|
groups = [ ];
|
|
};
|
|
"motion_sensor_7" = {
|
|
id = "0x00158d0002f9a6aa";
|
|
groups = [ "bed_room" "bed_room_present" ];
|
|
};
|
|
"motion_sensor_8" = {
|
|
id = "0x00158d0002f04637";
|
|
groups = [ "bath_room" "bath_room_present" ];
|
|
};
|
|
};
|
|
|
|
in {
|
|
|
|
services.zigbee2mqtt.devices = lib.mapAttrs' (name:
|
|
{ id, timeout ? 65, ... }: {
|
|
name = id;
|
|
value = {
|
|
retain = false;
|
|
friendly_name = name;
|
|
# should not be set below 60 seconds
|
|
occupancy_timeout = timeout;
|
|
};
|
|
}) 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);
|
|
};
|
|
}
|