nixos-config/nixos/machines/pepe/home-assistant/zigbee2mqtt/motion.nix

77 lines
2.2 KiB
Nix
Raw Normal View History

2020-04-15 21:47:21 +02:00
{ pkgs, lib, ... }:
let
# https://www.zigbee2mqtt.io/devices/RTCGQ01LM.html
allDevices = {
2020-11-08 21:41:34 +01:00
"motion_sensor_1" = { id = "0x00158d0002fbd451"; };
"motion_sensor_2" = { id = "0x00158d0002f9a6b8"; };
"motion_sensor_3" = { id = "0x00158d0002f04522"; };
"motion_sensor_4" = { id = "0x00158d0002f9a558"; };
"motion_sensor_5" = { id = "0x00158d0002f9a56f"; };
"motion_sensor_6" = { id = "0x00158d0002f9a5cb"; };
"motion_sensor_7" = { id = "0x00158d0002f9a6aa"; };
"motion_sensor_8" = { id = "0x00158d0002f04637"; };
2020-04-15 21:47:21 +02:00
};
2021-11-01 09:20:42 +01:00
in
{
2020-04-15 21:47:21 +02:00
2021-11-01 09:20:42 +01:00
services.zigbee2mqttConfiguration = 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;
2020-04-15 21:47:21 +02:00
2020-10-30 23:39:40 +01:00
services.homeAssistantConfig = {
2020-11-08 21:41:34 +01:00
# define meta information sensors
2021-11-01 09:20:42 +01:00
binary_sensor = lib.flatten (lib.mapAttrsToList
(name:
{ ... }: [{
name = "${name}";
2020-10-30 23:39:40 +01:00
platform = "mqtt";
state_topic = "zigbee2mqtt/${name}";
availability_topic = "zigbee2mqtt/bridge/state";
2021-11-01 09:20:42 +01:00
value_template = "{{ value_json.occupancy }}";
#icon = "mdi:battery-10";
payload_on = true;
payload_off = false;
device_class = "motion";
}])
allDevices);
# 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);
2020-10-30 23:39:40 +01:00
};
2020-04-15 21:47:21 +02:00
}