Repository: zigpy/zha-device-handlers

Issue:
[Device Support Request] Philips Hue Outdoor Sensor SML002
**Is your feature request related to a problem? Please describe.**
The sensor is working fine. Values for motion detection, temperature, battery status, illuminance are updated and shown as expected. But some settings are missing. There is a sensitivity setting which can't be set. 

**Describe the solution you'd like**
A quirk that implements the sensitivity setting? The sensitivy setting is located on cluster 0x0406 attribute 0x0030. For the outdoor sensor the sensitivy can be set between 0 and 4. There is also a sensititivy max setting (cluster 0x0406 attribute 0x0031) which is readonly. That represents the maximum sensitivy level (for the outdoor 4). 
for more information see https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Philips-Hue-sniffing#hue-motion-sensor

**Device signature - this can be acquired by removing the device from ZHA and pairing it again from the add devices screen.**

``` 
{
"node_descriptor": "<NodeDescriptor byte1=2 byte2=64 mac_capability_flags=128 manufacturer_code=4107 maximum_buffer_size=89 maximum_incoming_transfer_size=63 server_mask=0 maximum_outgoing_transfer_size=63 descriptor_capability_field=0>",
  "endpoints": {
    "1": {
      "profile_id": 49246,
      "device_type": "0x0850",
      "in_clusters": [
        "0x0000"
      ],
      "out_clusters": [
        "0x0000",
        "0x0003",
        "0x0004",
        "0x0005",
        "0x0006",
        "0x0008",
        "0x0300"
      ]
    },
    "2": {
      "profile_id": 260,
      "device_type": "0x0107",
      "in_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0400",
        "0x0402",
        "0x0406"
      ],
      "out_clusters": [
        "0x0019"
      ]
    }
  },
  "manufacturer": "Philips",
  "model": "SML002",
  "class": "zigpy.device.Device"
}
```

**EDIT by @dmulcahey to make the code formatting a block and not a line**

**Additional context**
Add any other context or screenshots about the feature request here.



Discussion:
~Please provide the other required information and I'll get this implemented. I need the device signature. There is a reason we ask for this stuff in the templates :) Once you provide this I'll get a quirk up for the device!~ WOW don't mind me... apparently I can't read!

Resolving patch:
diff --git a/zhaquirks/philips/__init__.py b/zhaquirks/philips/__init__.py
--- a/zhaquirks/philips/__init__.py
+++ b/zhaquirks/philips/__init__.py
@@ -1 +1,2 @@
 """Module for Phillips quirks implementations."""
+PHILLIPS = "Philips"
diff --git a/zhaquirks/philips/sml002.py b/zhaquirks/philips/sml002.py
new file mode 100644
--- /dev/null
+++ b/zhaquirks/philips/sml002.py
@@ -0,0 +1,115 @@
+"""Quirk for Phillips SML002."""
+from zigpy.profiles import zha, zll
+from zigpy.quirks import CustomCluster, CustomDevice
+import zigpy.types as t
+from zigpy.zcl.clusters.general import (
+    Basic,
+    Groups,
+    Identify,
+    LevelControl,
+    OnOff,
+    Ota,
+    PowerConfiguration,
+    Scenes,
+)
+from zigpy.zcl.clusters.lighting import Color
+from zigpy.zcl.clusters.measurement import (
+    IlluminanceMeasurement,
+    OccupancySensing,
+    TemperatureMeasurement,
+)
+
+from . import PHILLIPS
+from ..const import (
+    DEVICE_TYPE,
+    ENDPOINTS,
+    INPUT_CLUSTERS,
+    MODELS_INFO,
+    OUTPUT_CLUSTERS,
+    PROFILE_ID,
+)
+
+
+class OccupancyCluster(CustomCluster, OccupancySensing):
+    """Phillips occupancy cluster."""
+
+    attributes = OccupancySensing.attributes.copy()
+    attributes.update({0x0030: ("sensitivity", t.uint8_t)})
+    attributes.update({0x0031: ("sensitivity_max", t.uint8_t)})
+
+
+class PhilipsSML002(CustomDevice):
+    """Phillips SML002 device."""
+
+    signature = {
+        MODELS_INFO: [(PHILLIPS, "SML002")],
+        ENDPOINTS: {
+            #  <SimpleDescriptor endpoint=1 profile=49246 device_type=0x0850
+            #  device_version=?
+            #  input_clusters=[0]
+            #  output_clusters=[0, 3, 4, 5, 6, 8, 768]>
+            1: {
+                PROFILE_ID: zll.PROFILE_ID,
+                DEVICE_TYPE: zll.DeviceType.ON_OFF_SENSOR,
+                INPUT_CLUSTERS: [Basic.cluster_id],
+                OUTPUT_CLUSTERS: [
+                    Basic.cluster_id,
+                    Identify.cluster_id,
+                    Groups.cluster_id,
+                    Scenes.cluster_id,
+                    OnOff.cluster_id,
+                    LevelControl.cluster_id,
+                    Color.cluster_id,
+                ],
+            },
+            #  <SimpleDescriptor endpoint=2 profile=260 device_type=0x0107
+            #  device_version=?
+            #  input_clusters=[0, 1, 3, 1024, 1026, 1030]
+            #  output_clusters=[25]>
+            2: {
+                PROFILE_ID: zha.PROFILE_ID,
+                DEVICE_TYPE: zha.DeviceType.OCCUPANCY_SENSOR,
+                INPUT_CLUSTERS: [
+                    Basic.cluster_id,
+                    PowerConfiguration.cluster_id,
+                    Identify.cluster_id,
+                    IlluminanceMeasurement.cluster_id,
+                    TemperatureMeasurement.cluster_id,
+                    OccupancySensing.cluster_id,
+                ],
+                OUTPUT_CLUSTERS: [Ota.cluster_id],
+            },
+        },
+    }
+
+    replacement = {
+        ENDPOINTS: {
+            1: {
+                PROFILE_ID: zll.PROFILE_ID,
+                DEVICE_TYPE: zll.DeviceType.ON_OFF_SENSOR,
+                INPUT_CLUSTERS: [Basic.cluster_id],
+                OUTPUT_CLUSTERS: [
+                    Basic.cluster_id,
+                    Identify.cluster_id,
+                    Groups.cluster_id,
+                    Scenes.cluster_id,
+                    OnOff.cluster_id,
+                    LevelControl.cluster_id,
+                    Color.cluster_id,
+                ],
+            },
+            2: {
+                PROFILE_ID: zha.PROFILE_ID,
+                DEVICE_TYPE: zha.DeviceType.OCCUPANCY_SENSOR,
+                INPUT_CLUSTERS: [
+                    Basic.cluster_id,
+                    PowerConfiguration.cluster_id,
+                    Identify.cluster_id,
+                    IlluminanceMeasurement.cluster_id,
+                    TemperatureMeasurement.cluster_id,
+                    OccupancyCluster,
+                ],
+                OUTPUT_CLUSTERS: [Ota.cluster_id],
+            },
+        }
+    }


Test patch: