2020-04-15 23:55:21 +02:00
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
|
|
|
|
# https://www.zigbee2mqtt.io/devices/WSDCGQ11LM.html
|
|
|
|
allDevices = {
|
|
|
|
"temperature_sensor_1" = {
|
|
|
|
id = "0x00158d0002d79220";
|
2020-04-16 00:22:29 +02:00
|
|
|
groups = [ "living_room" ];
|
2020-04-15 23:55:21 +02:00
|
|
|
};
|
|
|
|
"temperature_sensor_2" = {
|
|
|
|
id = "0x00158d0002d7913d";
|
2020-04-16 00:22:29 +02:00
|
|
|
groups = [ "living_room" ];
|
2020-04-15 23:55:21 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
in
|
|
|
|
{
|
2020-04-15 23:55:21 +02:00
|
|
|
|
2021-11-01 09:20:42 +01:00
|
|
|
services.zigbee2mqttConfiguration = lib.mapAttrs'
|
|
|
|
(name:
|
|
|
|
{ id, ... }: {
|
|
|
|
name = id;
|
|
|
|
value = {
|
|
|
|
retain = false;
|
|
|
|
friendly_name = name;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
allDevices;
|
2020-04-15 23:55:21 +02:00
|
|
|
|
|
|
|
services.homeAssistantConfig = {
|
|
|
|
|
|
|
|
# define meta information sensors
|
2021-11-01 09:20:42 +01:00
|
|
|
sensor = lib.flatten (lib.mapAttrsToList
|
|
|
|
(name:
|
|
|
|
{ ... }: [
|
|
|
|
{
|
|
|
|
platform = "mqtt";
|
|
|
|
name = name;
|
|
|
|
state_topic = "zigbee2mqtt/${name}";
|
|
|
|
availability_topic = "zigbee2mqtt/bridge/state";
|
|
|
|
unit_of_measurement = "°C";
|
|
|
|
device_class = "temperature";
|
|
|
|
value_template = "{{ value_json.temperature }}";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
platform = "mqtt";
|
|
|
|
name = "humidity_${name}";
|
|
|
|
state_topic = "zigbee2mqtt/${name}";
|
|
|
|
availability_topic = "zigbee2mqtt/bridge/state";
|
|
|
|
unit_of_measurement = "%";
|
|
|
|
device_class = "humidity";
|
|
|
|
value_template = "{{ value_json.humidity }}";
|
|
|
|
}
|
|
|
|
#{
|
|
|
|
# platform = "mqtt";
|
|
|
|
# name = "pressure_${name}";
|
|
|
|
# state_topic = "zigbee2mqtt/${name}";
|
|
|
|
# availability_topic = "zigbee2mqtt/bridge/state";
|
|
|
|
# unit_of_measurement = "hPa";
|
|
|
|
# device_class = "pressure";
|
|
|
|
# value_template = "{{ value_json.pressure }}";
|
|
|
|
#}
|
|
|
|
{
|
|
|
|
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-04-15 23:55:21 +02:00
|
|
|
|
|
|
|
# create groups
|
|
|
|
# -------------
|
2020-10-30 23:39:40 +01:00
|
|
|
#group = let
|
|
|
|
# # to have nice panels for every device
|
|
|
|
# sensorGroups = lib.mapAttrs (name:
|
|
|
|
# { ... }: {
|
|
|
|
# entities = [
|
|
|
|
# "sensor.${name}"
|
|
|
|
# "sensor.humidity_${name}"
|
|
|
|
# #"sensor.pressure_${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}" = "sensor.${name}"; }) groups)
|
|
|
|
# allDevices));
|
|
|
|
# in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
|
|
|
|
#in sortedInGroups // sensorGroups // {
|
|
|
|
# all_sensors.entities =
|
|
|
|
# lib.mapAttrsToList (name: { ... }: "sensor.${name}") allDevices;
|
|
|
|
#};
|
2020-04-15 23:55:21 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|