{ pkgs, lib, ... }: let # https://www.zigbee2mqtt.io/devices/E1757.html allDevices = { "fyrtur1" = { id = "0x680ae2fffe64fa40"; }; # office "fyrtur2" = { id = "0x680ae2fffe6e9f41"; }; # sleeping room }; # -t "zigbee2mqtt/fyrtur1/set" -m '{"position":100}' # -t "zigbee2mqtt/fyrtur1/set" -m '{"position":15}' in { services.zigbee2mqtt.devices = lib.mapAttrs' (name: { id, ... }: { name = id; value = { retain = false; friendly_name = name; transition = 1; }; }) allDevices; services.homeAssistantConfig = { #light = lib.flatten (lib.mapAttrsToList (name: # { ... }: [ # { # name = "rgb_${name}"; # platform = "mqtt"; # state_topic = "zigbee2mqtt/${name}"; # availability_topic = "zigbee2mqtt/bridge/state"; # brightness = true; # color_temp = true; # xy = true; # schema = "json"; # command_topic = "zigbee2mqtt/${name}/rgb/set"; # brightness_scale = 254; # state_topic_postfix = "rgb"; # } # { # name = "white_${name}"; # platform = "mqtt"; # state_topic = "zigbee2mqtt/${name}"; # availability_topic = "zigbee2mqtt/bridge/state"; # brightness = true; # schema = "json"; # command_topic = "zigbee2mqtt/${name}/white/set"; # brightness_scale = 254; # state_topic_postfix = "white"; # } # ]) allDevices); #sensor = with lib; # mapAttrsToList (name: # { ... }: { # 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 = "update_${name}"; # platform = "mqtt"; # state_topic = "zigbee2mqtt/${name}"; # availability_topic = "zigbee2mqtt/bridge/state"; # payload_on = true; # payload_off = false; # value_template = "{{ value_json.update_available }}"; # }) allDevices; # # create groups # # ------------- # group = let # # to have nice panels for every device # lightGroups = lib.mapAttrs (name: # { ... }: { # entities = [ # "light.${name}" # "sensor.link_${name}" # "binary_sensor.update_${name}" # ]; # }) allDevices; # # sort lights into given groups. # sortedInGroups = let # groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList (name: # { groups ? [ ], ... }: # map (groupName: { "${groupName}" = "light.${name}"; }) groups) # allDevices)); # in lib.mapAttrs (name: entities: { inherit entities; }) groupEntries; # in sortedInGroups // lightGroups // { # all_lights.entities = # lib.mapAttrsToList (name: { ... }: "light.${name}") allDevices; # }; }; }