Repository: zigpy/zha-device-handlers

Issue:
[Device Support Request] 2023 Aqara Light Sensor T1 Brightness Sensor
### Problem description

Hi, purchased a few of these sensors (manufactured April 2023):

2023 Aqara Light Sensor T1 Brightness Sensor on Aqara Global Store on AliExpress:
https://www.aliexpress.com/item/1005005012531138.html
Touted as 2023 with model number is GZCGQ11LM

The device pairs and works correctly (with SkyConnect)

However, a couple of features may be missing:
1. No battery level entity
2. Detection period (as reported by Z2M user that this device can support)

(See screenshot section)


### Solution description

possible update the library driver for create a quirk?


### Screenshots/Video

<details><summary>Screenshots/Video</summary>

ZHA:
![image](https://github.com/zigpy/zha-device-handlers/assets/79593761/3d5b5215-8213-4077-aefb-71e4518e74e0)

Z2M:
![image](https://github.com/zigpy/zha-device-handlers/assets/79593761/5974acd7-4a5c-47cc-9c69-347c888cf16a)

</details>


### Device signature

<details><summary>Device signature</summary>

```json
{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.MainsPowered|AllocateAddress: 132>, manufacturer_code=4718, maximum_buffer_size=127, maximum_incoming_transfer_size=100, server_mask=11264, maximum_outgoing_transfer_size=100, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=True, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0106",
      "input_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0400"
      ],
      "output_clusters": [
        "0x0003"
      ]
    }
  },
  "manufacturer": "LUMI",
  "model": "lumi.sen_ill.agl01"
}
```

</details>


### Diagnostic information

<details><summary>Diagnostic information</summary>

```json
{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2023.7.1",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.11.4",
    "docker": true,
    "arch": "aarch64",
    "timezone": "America/Edmonton",
    "os_name": "Linux",
    "os_version": "6.1.21-v8",
    "supervisor": "2023.07.1",
    "host_os": "Home Assistant OS 10.3",
    "docker_version": "23.0.6",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "nest_protect": {
      "version": "0.3.12",
      "requirements": []
    },
    "spook": {
      "version": "0.14.0",
      "requirements": []
    },
    "hacs": {
      "version": "1.32.1",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "hass_agent": {
      "version": "2022.11.9",
      "requirements": []
    },
    "dyson_local": {
      "version": "0.22.1",
      "requirements": [
        "libdyson-neon==1.0.2"
      ]
    }
  },
  "integration_manifest": {
    "domain": "zha",
    "name": "Zigbee Home Automation",
    "after_dependencies": [
      "onboarding",
      "usb"
    ],
    "codeowners": [
      "@dmulcahey",
      "@adminiuga",
      "@puddly"
    ],
    "config_flow": true,
    "dependencies": [
      "file_upload"
    ],
    "documentation": "https://www.home-assistant.io/integrations/zha",
    "iot_class": "local_polling",
    "loggers": [
      "aiosqlite",
      "bellows",
      "crccheck",
      "pure_pcapy3",
      "zhaquirks",
      "zigpy",
      "zigpy_deconz",
      "zigpy_xbee",
      "zigpy_zigate",
      "zigpy_znp"
    ],
    "requirements": [
      "bellows==0.35.8",
      "pyserial==3.5",
      "pyserial-asyncio==0.6",
      "zha-quirks==0.0.101",
      "zigpy-deconz==0.21.0",
      "zigpy==0.56.1",
      "zigpy-xbee==0.18.1",
      "zigpy-zigate==0.11.0",
      "zigpy-znp==0.11.2"
    ],
    "usb": [
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*2652*",
        "known_devices": [
          "slae.sh cc2652rb stick"
        ]
      },
      {
        "vid": "1A86",
        "pid": "55D4",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus v2"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*zigstar*",
        "known_devices": [
          "ZigStar Coordinators"
        ]
      },
      {
        "vid": "1CF1",
        "pid": "0030",
        "description": "*conbee*",
        "known_devices": [
          "Conbee II"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8A2A",
        "description": "*zigbee*",
        "known_devices": [
          "Nortek HUSBZB-1"
        ]
      },
      {
        "vid": "0403",
        "pid": "6015",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate+"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8B34",
        "description": "*bv 2010/10*",
        "known_devices": [
          "Bitron Video AV2010/10"
        ]
      }
    ],
    "zeroconf": [
      {
        "type": "_esphomelib._tcp.local.",
        "name": "tube*"
      },
      {
        "type": "_zigate-zigbee-gateway._tcp.local.",
        "name": "*zigate*"
      },
      {
        "type": "_zigstar_gw._tcp.local.",
        "name": "*zigstar*"
      },
      {
        "type": "_slzb-06._tcp.local.",
        "name": "slzb-06*"
      }
    ],
    "is_built_in": true
  },
  "data": {
    "ieee": "**REDACTED**",
    "nwk": 4973,
    "manufacturer": "LUMI",
    "model": "lumi.sen_ill.agl01",
    "name": "LUMI lumi.sen_ill.agl01",
    "quirk_applied": false,
    "quirk_class": "zigpy.device.Device",
    "manufacturer_code": 4718,
    "power_source": "Mains",
    "lqi": 120,
    "rssi": -70,
    "last_seen": "2023-07-07T12:43:19",
    "available": true,
    "device_type": "EndDevice",
    "signature": {
      "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.MainsPowered|AllocateAddress: 132>, manufacturer_code=4718, maximum_buffer_size=127, maximum_incoming_transfer_size=100, server_mask=11264, maximum_outgoing_transfer_size=100, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=True, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
      "endpoints": {
        "1": {
          "profile_id": "0x0104",
          "device_type": "0x0106",
          "input_clusters": [
            "0x0000",
            "0x0001",
            "0x0003",
            "0x0400"
          ],
          "output_clusters": [
            "0x0003"
          ]
        }
      },
      "manufacturer": "LUMI",
      "model": "lumi.sen_ill.agl01"
    },
    "active_coordinator": false,
    "entities": [
      {
        "entity_id": "button.lumi_lumi_sen_ill_agl01_identify",
        "name": "LUMI lumi.sen_ill.agl01"
      },
      {
        "entity_id": "sensor.lumi_lumi_sen_ill_agl01_illuminance",
        "name": "LUMI lumi.sen_ill.agl01"
      },
      {
        "entity_id": "sensor.lumi_lumi_sen_ill_agl01_rssi",
        "name": "LUMI lumi.sen_ill.agl01"
      },
      {
        "entity_id": "sensor.lumi_lumi_sen_ill_agl01_lqi",
        "name": "LUMI lumi.sen_ill.agl01"
      }
    ],
    "neighbors": [],
    "routes": [],
    "endpoint_names": [
      {
        "name": "LIGHT_SENSOR"
      }
    ],
    "user_given_name": null,
    "device_reg_id": "4af9c66c77f298fff514ff0407f47e2b",
    "area_id": "kitchen",
    "cluster_details": {
      "1": {
        "device_type": {
          "name": "LIGHT_SENSOR",
          "id": 262
        },
        "profile_id": 260,
        "in_clusters": {
          "0x0000": {
            "endpoint_attribute": "basic",
            "attributes": {
              "0x0001": {
                "attribute_name": "app_version",
                "value": 27
              },
              "0x0004": {
                "attribute_name": "manufacturer",
                "value": "LUMI"
              },
              "0x0005": {
                "attribute_name": "model",
                "value": "lumi.sen_ill.agl01"
              }
            },
            "unsupported_attributes": {}
          },
          "0x0400": {
            "endpoint_attribute": "illuminance",
            "attributes": {
              "0x0000": {
                "attribute_name": "measured_value",
                "value": 33786
              }
            },
            "unsupported_attributes": {}
          },
          "0x0003": {
            "endpoint_attribute": "identify",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x0001": {
            "endpoint_attribute": "power",
            "attributes": {
              "0x0033": {
                "attribute_name": "battery_quantity",
                "value": 1
              },
              "0x0031": {
                "attribute_name": "battery_size",
                "value": 7
              },
              "0x0020": {
                "attribute_name": "battery_voltage",
                "value": 32
              }
            },
            "unsupported_attributes": {
              "0x0021": {
                "attribute_name": "battery_percentage_remaining"
              }
            }
          }
        },
        "out_clusters": {
          "0x0003": {
            "endpoint_attribute": "identify",
            "attributes": {},
            "unsupported_attributes": {}
          }
        }
      }
    }
  }
}
```

</details>


Discussion:
You need to attach the device signature or device diagnostic information.
EDIT: Now also in original post.
ah, yes how did I forget that. Sorry about that. Here's the diagnostic information (file download)

[zha-35e4f47bd1aec2897f2fa1af0eeb1329-LUMI lumi.sen_ill.agl01-4af9c66c77f298fff514ff0407f47e2b.json.txt](https://github.com/zigpy/zha-device-handlers/files/11985011/zha-35e4f47bd1aec2897f2fa1af0eeb1329-LUMI.lumi.sen_ill.agl01-4af9c66c77f298fff514ff0407f47e2b.json.txt)

Z2M Page & code block if that helps.  Onces this is added i should be able to run ZHA :)

 https://www.zigbee2mqtt.io/devices/GZCGQ11LM.html

`    {
        zigbeeModel: ['lumi.sen_ill.agl01'],
        model: 'GZCGQ11LM',
        vendor: 'Xiaomi',
        description: 'Aqara T1 light intensity sensor',
        fromZigbee: [fz.battery, fz.illuminance, fz.aqara_opple],
        toZigbee: [tz.GZCGQ11LM_detection_period],
        meta: {battery: {voltageToPercentage: '3V_2850_3000'}},
        exposes: [e.battery(), e.battery_voltage(), e.illuminance(), e.illuminance_lux(),
            e.numeric('detection_period', exposes.access.ALL).withValueMin(1).withValueMax(59).withUnit('s')
                .withDescription('Time interval in seconds to report after light changes')],
        configure: async (device, coordinatorEndpoint, logger) => {
            const endpoint = device.getEndpoint(1);
            await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f, disableResponse: true});
            await endpoint.read('aqaraOpple', [0x0000], {manufacturerCode: 0x115f});
        },
        ota: ota.zigbeeOTA,
    },`
@Anto79-ops Can you check what the device reports for "Power Source"? (See screenshots in https://github.com/zigpy/zha-device-handlers/issues/1473)

@TheJulianJES 
![Screenshot_20230801_154041_Home Assistant.jpg](https://github.com/zigpy/zha-device-handlers/assets/79593761/15e23fe1-47a1-4693-9784-a81e779749c0)



Resolving patch:
diff --git a/zhaquirks/xiaomi/aqara/illumination.py b/zhaquirks/xiaomi/aqara/illumination.py
--- a/zhaquirks/xiaomi/aqara/illumination.py
+++ b/zhaquirks/xiaomi/aqara/illumination.py
@@ -1,8 +1,9 @@
-"""Quirk for lumi.sen_ill.mgl01 illumination sensor."""
+"""Quirk for Aqara illumination sensor."""
 import logging
 
 from zigpy.profiles import zha
-from zigpy.zcl.clusters.general import Basic, Identify
+import zigpy.types as types
+from zigpy.zcl.clusters.general import Basic, Identify, PowerConfiguration
 from zigpy.zcl.clusters.measurement import IlluminanceMeasurement
 from zigpy.zdo.types import NodeDescriptor
 
@@ -16,18 +17,23 @@
     OUTPUT_CLUSTERS,
     PROFILE_ID,
 )
-from zhaquirks.xiaomi import LUMI, BasicCluster, XiaomiCustomDevice
+from zhaquirks.xiaomi import (
+    LUMI,
+    BasicCluster,
+    XiaomiAqaraE1Cluster,
+    XiaomiCustomDevice,
+)
 
 _LOGGER = logging.getLogger(__name__)
 
 
 class Illumination(XiaomiCustomDevice):
-    """Aqara LUMI lumi.sen_ill.mgl01."""
+    """Aqara LUMI lumi.sen_ill.mgl01 illumination sensor."""
 
     signature = {
         # <SimpleDescriptor endpoint=1 profile=260 device_type=262
         # device_version=1
-        # input_clusters=[0, 1024, 3, 1]
+        # input_clusters=[0, 1, 3, 1024]
         # output_clusters=[3]>
         MODELS_INFO: [(LUMI, "lumi.sen_ill.mgl01"), ("XIAOMI", "lumi.sen_ill.mgl01")],
         ENDPOINTS: {
@@ -36,9 +42,9 @@ class Illumination(XiaomiCustomDevice):
                 DEVICE_TYPE: zha.DeviceType.LIGHT_SENSOR,
                 INPUT_CLUSTERS: [
                     Basic.cluster_id,
+                    PowerConfiguration.cluster_id,
                     Identify.cluster_id,
                     IlluminanceMeasurement.cluster_id,
-                    PowerConfigurationCluster.cluster_id,
                 ],
                 OUTPUT_CLUSTERS: [Identify.cluster_id],
             }
@@ -63,3 +69,39 @@ class Illumination(XiaomiCustomDevice):
             }
         },
     }
+
+
+class OppleCluster(XiaomiAqaraE1Cluster):
+    """Opple cluster with configurable detection interval."""
+
+    ep_attribute = "opple_cluster"
+    attributes = {
+        0x0000: ("detection_interval", types.uint16_t, True),
+    }
+
+
+class IlluminationT1(XiaomiCustomDevice):
+    """Aqara LUMI T1 illumination sensor with configurable detection interval."""
+
+    signature = {
+        MODELS_INFO: [(LUMI, "lumi.sen_ill.agl01")],
+        ENDPOINTS: Illumination.signature[ENDPOINTS],
+    }
+
+    replacement = {
+        NODE_DESCRIPTOR: Illumination.replacement[NODE_DESCRIPTOR],
+        ENDPOINTS: {
+            1: {
+                PROFILE_ID: zha.PROFILE_ID,
+                DEVICE_TYPE: zha.DeviceType.LIGHT_SENSOR,
+                INPUT_CLUSTERS: [
+                    BasicCluster,
+                    Identify.cluster_id,
+                    IlluminanceMeasurement.cluster_id,
+                    PowerConfigurationCluster,
+                    OppleCluster,
+                ],
+                OUTPUT_CLUSTERS: [Identify.cluster_id],
+            }
+        },
+    }


Test patch: