Exemplo n.º 1
0
def addTradfriSceneRemote(sensor_id, group_id):
    rules = [{"actions": [{"address": "/groups/" + group_id + "/action","body": {"on": True},"method": "PUT"}],"conditions": [{"address": "/sensors/" + sensor_id + "/state/lastupdated","operator": "dx"},{"address": "/sensors/" + sensor_id + "/state/buttonevent","operator": "eq","value": "1002"},{"address": "/groups/" + group_id + "/state/any_on","operator": "eq","value": "false"}],"name": "Remote " + sensor_id + " button on"}, {"actions": [{"address": "/groups/" + group_id + "/action","body": {"on": False},"method": "PUT"}],"conditions": [{"address": "/sensors/" + sensor_id + "/state/lastupdated","operator": "dx"},{"address": "/sensors/" + sensor_id + "/state/buttonevent","operator": "eq","value": "1002"},{"address": "/groups/" + group_id + "/state/any_on","operator": "eq","value": "true"}],"name": "Remote " + sensor_id + " button off"},{ "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "bri_inc": 30, "transitiontime": 9 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "2002" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " up-press" }, { "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "bri_inc": 56, "transitiontime": 9 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "2001" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " up-long" }, { "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "bri_inc": -30, "transitiontime": 9 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "3002" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " dn-press" }, { "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "bri_inc": -56, "transitiontime": 9 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "3001" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " dn-long" }, { "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "scene_inc": -1 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "4002" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " ctl-press" }, { "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "scene_inc": -1 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "4001" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " ctl-long" }, { "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "scene_inc": 1 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "5002" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " ct-press" }, { "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "scene_inc": 1 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "5001" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " ct-long" }]
    resourcelinkId = nextFreeId(bridgeConfig, "resourcelinks")
    bridgeConfig["resourcelinks"][resourcelinkId] = {"classid": 15555,"description": "Rules for sensor " + sensor_id, "links": ["/sensors/" + sensor_id], "name": "Emulator rules " + sensor_id,"owner": list(bridgeConfig["config"]["whitelist"])[0]}
    for rule in rules:
        ruleId = nextFreeId(bridgeConfig, "rules")
        bridgeConfig["rules"][ruleId] = rule
        bridgeConfig["rules"][ruleId].update({"created": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"), "lasttriggered": None, "owner": list(bridgeConfig["config"]["whitelist"])[0], "recycle": True, "status": "enabled", "timestriggered": 0})
        bridgeConfig["resourcelinks"][resourcelinkId]["links"].append("/rules/" + ruleId)
Exemplo n.º 2
0
def addTradfriOnOffSwitch(sensor_id, group_id):
    rules = [{"actions": [{"address": "/groups/" + group_id + "/action","body": {"on": True},"method": "PUT"}],"conditions": [{"address": "/sensors/" + sensor_id + "/state/lastupdated","operator": "dx"},{"address": "/sensors/" + sensor_id + "/state/buttonevent","operator": "eq","value": "1002"}],"name": "Remote " + sensor_id + " button on"}, {"actions": [{"address": "/groups/" + group_id + "/action","body": {"on": False},"method": "PUT"}],"conditions": [{"address": "/sensors/" + sensor_id + "/state/lastupdated","operator": "dx"},{"address": "/sensors/" + sensor_id + "/state/buttonevent","operator": "eq","value": "2002"}],"name": "Remote " + sensor_id + " button off"},{ "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "bri_inc": 30, "transitiontime": 9 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "1001" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " up-press" }, { "actions": [{ "address": "/groups/" + group_id + "/action", "body": { "bri_inc": -30, "transitiontime": 9 }, "method": "PUT" }], "conditions": [{ "address": "/sensors/" + sensor_id + "/state/buttonevent", "operator": "eq", "value": "2001" }, { "address": "/sensors/" + sensor_id + "/state/lastupdated", "operator": "dx" }], "name": "Dimmer Switch " + sensor_id + " dn-press" }]
    resourcelinkId = nextFreeId(bridgeConfig, "resourcelinks")
    owner = bridgeConfig["apiUsers"][list(bridgeConfig["apiUsers"])[0]]
    bridgeConfig["resourcelinks"][resourcelinkId] = HueObjects.ResourceLink({"id_v1": resourcelinkId, "classid": 15555,"description": "Rules for sensor " + sensor_id, "links": ["/" + bridgeConfig["sensors"][sensor_id].getObjectPath()["resource"] + "/" + bridgeConfig["sensors"][sensor_id].getObjectPath()["id"]], "name": "Emulator rules " + sensor_id,"owner": owner})
    for rule in rules:
        ruleId = nextFreeId(bridgeConfig, "rules")
        data = rule
        data.update({"id_v1": ruleId, "owner": owner, "recycle": True})
        bridgeConfig["rules"][ruleId] = HueObjects.Rule(data)
        bridgeConfig["resourcelinks"][resourcelinkId].add_link(bridgeConfig["rules"][ruleId])
Exemplo n.º 3
0
def addHueSwitch(uniqueid, sensorsType):
    new_sensor_id = nextFreeId(bridgeConfig, "sensors")
    if uniqueid == "":
        uniqueid = "00:17:88:01:02:"
        if len(new_sensor_id) == 1:
            uniqueid += "0" + new_sensor_id + ":4d:c6-02-fc00"
        else:
            uniqueid += new_sensor_id + ":4d:c6-02-fc00"
    deviceData = {
        "id_v1": new_sensor_id,
        "state": {
            "buttonevent": 0,
            "lastupdated": "none"
        },
        "config": {
            "on": True,
            "battery": 100,
            "reachable": True
        },
        "name":
        "Dimmer Switch" if sensorsType == "ZLLSwitch" else "Tap Switch",
        "type": sensorsType,
        "modelid": "RWL021" if sensorsType == "ZLLSwitch" else "ZGPSWITCH",
        "manufacturername": "Philips",
        "swversion": "5.45.1.17846" if sensorsType == "ZLLSwitch" else "",
        "uniqueid": uniqueid
    }
    bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(deviceData)
    return (bridgeConfig["sensors"][new_sensor_id])
Exemplo n.º 4
0
def addHueMotionSensor(name, protocol, protocol_cfg):
    uniqueid = generate_unique_id()
    motion_sensor_id = nextFreeId(bridgeConfig, "sensors")
    motion_sensor = {
        "name": "Hue motion " + name[:21],
        "id_v1": motion_sensor_id,
        "protocol": protocol,
        "modelid": "SML001",
        "type": "ZLLPresence",
        "protocol_cfg": protocol_cfg,
        "uniqueid": uniqueid + "-02-0406"
    }
    bridgeConfig["sensors"][motion_sensor_id] = HueObjects.Sensor(
        motion_sensor)
    new_sensor_id = nextFreeId(bridgeConfig, "sensors")
    light_sensor = {
        "name": "Hue ambient light " + name[:14],
        "id_v1": new_sensor_id,
        "protocol": protocol,
        "modelid": "SML001",
        "type": "ZLLLightLevel",
        "protocol_cfg": protocol_cfg,
        "uniqueid": uniqueid + "-02-0400"
    }
    bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(light_sensor)
    new_sensor_id = nextFreeId(bridgeConfig, "sensors")
    temp_sensor = {
        "name": "Hue temperature " + name[:16],
        "id_v1": new_sensor_id,
        "protocol": protocol,
        "modelid": "SML001",
        "type": "ZLLTemperature",
        "protocol_cfg": protocol_cfg,
        "uniqueid": uniqueid + "-02-0402"
    }
    bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(temp_sensor)
    return
Exemplo n.º 5
0
def addNewLight(modelid, name, protocol, protocol_cfg):
    newLightID = nextFreeId(bridgeConfig, "lights")
    if modelid in lightTypes:
        light = lightTypes[modelid]
        light["name"] = name
        light["id_v1"] = newLightID
        light["modelid"] = modelid
        light["protocol"] = protocol
        light["protocol_cfg"] = protocol_cfg
        newObject = HueObjects.Light(light)
        bridgeConfig["lights"][newLightID] = newObject
        bridgeConfig["groups"]["0"].add_light(newObject)
        # trigger stream messages
        rooms = []
        lights = []
        for group, obj in bridgeConfig["groups"].items():
            rooms.append(obj.id_v2)
        for light, obj in bridgeConfig["lights"].items():
            lights.append(obj.id_v2)
        bridgeConfig["groups"]["0"].groupZeroStream(rooms, lights)
        configManager.bridgeConfig.save_config(backup=False, resource="lights")

        return newLightID
    return False
Exemplo n.º 6
0
    def post(self, username, resource):
        authorisation = authorize(username, resource)
        if "success" not in authorisation:
            return authorisation

        if resource in ["lights", "sensors"
                        ] and request.get_data(as_text=True) == "":
            print("scan for light")
            # if was a request to scan for lights of sensors
            Thread(target=scanForLights).start()
            return [{"success": {"/" + resource: "Searching for new devices"}}]
        postDict = request.get_json(force=True)
        logging.debug(postDict)
        if resource == "lights":  # add light manually from the web interface
            Thread(target=manualAddLight,
                   args=[
                       postDict["ip"], postDict["protocol"], postDict["config"]
                   ]).start()
            return [{"success": {"/" + resource: "Searching for new devices"}}]
        v2Resource = None
        # find the first unused id for new object
        new_object_id = nextFreeId(bridgeConfig, resource)
        postDict["id_v1"] = new_object_id
        postDict["owner"] = bridgeConfig["apiUsers"][username]
        if resource == "groups":
            if "type" in postDict:
                if postDict["type"] == "Zone":
                    v2Resource = "zone"
                    bridgeConfig[resource][new_object_id] = HueObjects.Group(
                        postDict)
                elif postDict["type"] == "Room":
                    v2Resource = "room"
                    bridgeConfig[resource][new_object_id] = HueObjects.Group(
                        postDict)
                elif postDict["type"] == "Entertainment":
                    v2Resource = "entertainment_configuration"
                    bridgeConfig[resource][
                        new_object_id] = HueObjects.EntertainmentConfiguration(
                            postDict)

            if "lights" in postDict:
                for light in postDict["lights"]:
                    bridgeConfig[resource][new_object_id].add_light(
                        bridgeConfig["lights"][light])
            if "locations" in postDict:
                for light, location in postDict["locations"].items():
                    bridgeConfig[resource][new_object_id].locations[
                        bridgeConfig["lights"][light]] = [{
                            "x": location[0],
                            "y": location[1],
                            "z": location[2]
                        }]
            # trigger stream messages
            GroupZeroMessage()
        elif resource == "scenes":
            v2Resource = "scene"
            if "group" in postDict:
                postDict["group"] = weakref.ref(
                    bridgeConfig["groups"][postDict["group"]])
            elif "lights" in postDict:
                objLights = []
                for light in postDict["lights"]:
                    objLights.append(weakref.ref(
                        bridgeConfig["lights"][light]))
                postDict["lights"] = objLights
            bridgeConfig[resource][new_object_id] = HueObjects.Scene(postDict)
            scene = bridgeConfig[resource][new_object_id]
            if "lightstates" in postDict:
                for light, state in postDict["lightstates"].items():
                    scene.lightstates[bridgeConfig["lights"][light]] = state
            else:
                if "group" in postDict:
                    for light in postDict["group"]().lights:
                        scene.lightstates[light()] = {
                            "on": light().state["on"]
                        }
                elif "lights" in postDict:
                    for light in postDict["lights"]:
                        scene.lightstates[light()] = {
                            "on": light().state["on"]
                        }
                # add remaining state details in one shot.
                sceneStates = list(scene.lightstates.items())
                for light, state in sceneStates:
                    if "bri" in light.state:
                        state["bri"] = light.state["bri"]
                    if "colormode" in light.state:
                        if light.state["colormode"] == "ct":
                            state["ct"] = light.state["ct"]
                        elif light.state["colormode"] == "xy":
                            state["xy"] = light.state["xy"]
                        elif light.state["colormode"] == "hs":
                            state["hue"] = light.state["hue"]
                            state["sat"] = light.state["sat"]

        elif resource == "rules":
            bridgeConfig[resource][new_object_id] = HueObjects.Rule(postDict)
        elif resource == "resourcelinks":
            bridgeConfig[resource][new_object_id] = HueObjects.ResourceLink(
                postDict)
        elif resource == "sensors":
            v2Resource = "device"
            bridgeConfig[resource][new_object_id] = HueObjects.Sensor(postDict)
        elif resource == "schedules":
            bridgeConfig[resource][new_object_id] = HueObjects.Schedule(
                postDict)
        newObject = bridgeConfig[resource][new_object_id]
        if v2Resource != "none":
            streamMessage = {
                "creationtime":
                datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
                "data": [],
                "id_v1": "/" + resource + "/" + new_object_id,
                "id": str(uuid.uuid4()),
                "type": "add"
            }
            if resource == "groups":
                if v2Resource == "room":
                    streamMessage["data"].append(newObject.getV2Room())
                elif v2Resource == "zone":
                    streamMessage["data"].append(newObject.getV2Zone())
                elif v2Resource == "entertainment_configuration":
                    streamMessage["data"].append(newObject.getV2Api())
                else:
                    streamMessage["data"].append(newObject.getV2GroupedLight())
            elif hasattr(newObject, 'getV2Api'):
                streamMessage["data"].append(newObject.getV2Api())
            bridgeConfig["temp"]["eventstream"].append(streamMessage)
            logging.debug(streamMessage)
        logging.info(
            json.dumps([{
                "success": {
                    "id": new_object_id
                }
            }],
                       sort_keys=True,
                       indent=4,
                       separators=(',', ': ')))
        configManager.bridgeConfig.save_config(backup=False, resource=resource)
        return [{"success": {"id": new_object_id}}]
Exemplo n.º 7
0
def on_message(client, userdata, msg):
    if bridgeConfig["config"]["mqtt"]["enabled"]:
        try:
            current_time = datetime.now()
            logging.debug("MQTT: got state message on " + msg.topic)
            data = json.loads(msg.payload)
            logging.debug(msg.payload)
            if msg.topic.startswith(discoveryPrefix + "/light/"):
                on_autodiscovery_light(msg)
            elif msg.topic == "zigbee2mqtt/bridge/devices":
                for key in data:
                    if "model_id" in key and (
                            key["model_id"] in standardSensors
                            or key["model_id"]
                            in motionSensors):  # Sensor is supported
                        if getObject(key["friendly_name"]
                                     ) == False:  ## Add the new sensor
                            logging.info("MQTT: Add new mqtt sensor " +
                                         key["friendly_name"])
                            if key["model_id"] in standardSensors:
                                new_sensor_id = nextFreeId(
                                    bridgeConfig, "sensors")
                                sensor_type = list(
                                    sensorTypes[key["model_id"]].keys())[0]
                                uniqueid = convertHexToMac(
                                    key["ieee_address"]) + "-01-1000"
                                sensorData = {
                                    "name": key["friendly_name"],
                                    "protocol": "mqtt",
                                    "modelid": key["model_id"],
                                    "type": sensor_type,
                                    "uniqueid": uniqueid,
                                    "protocol_cfg": {
                                        "friendly_name": key["friendly_name"],
                                        "ieeeAddr": key["ieee_address"],
                                        "model": key["definition"]["model"]
                                    },
                                    "id_v1": new_sensor_id
                                }
                                bridgeConfig["sensors"][
                                    new_sensor_id] = HueObjects.Sensor(
                                        sensorData)
                            ### TRADFRI Motion Sensor, Xiaomi motion sensor, etc
                            elif key["model_id"] in motionSensors:
                                logging.info("MQTT: add new motion sensor " +
                                             key["model_id"])
                                addHueMotionSensor(
                                    key["friendly_name"], "mqtt", {
                                        "modelid": key["model_id"],
                                        "lightSensor": "on",
                                        "friendly_name": key["friendly_name"]
                                    })
                            else:
                                logging.info("MQTT: unsupported sensor " +
                                             key["model_id"])
            elif msg.topic == "zigbee2mqtt/bridge/log":
                light = getObject(data["meta"]["friendly_name"])
                if data["type"] == "device_announced":
                    if light.config["startup"]["mode"] == "powerfail":
                        logging.info("set last state for " + light.name)
                        payload = {}
                        payload["state"] = "ON" if light.state["on"] else "OFF"
                        client.publish(light.protocol_cfg['command_topic'],
                                       json.dumps(payload))
                elif data["type"] == "zigbee_publish_error":
                    logging.info(light.name + " is unreachable")
                    light.state["reachable"] = False
            else:
                device_friendlyname = msg.topic.split("/")[1]
                device = getObject(device_friendlyname)
                if device != False:
                    if device.getObjectPath()["resource"] == "sensors":
                        if "battery" in data and isinstance(
                                data["battery"], int):
                            device.config["battery"] = data["battery"]
                        if device.config["on"] == False:
                            return
                        convertedPayload = {
                            "lastupdated":
                            datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
                        }
                        if ("action" in data and data["action"] == "") or (
                                "click" in data and data["click"] == ""):
                            return
                        ### If is a motion sensor update the light level and temperature
                        if device.modelid in motionSensors:
                            convertedPayload["presence"] = data["occupancy"]
                            lightPayload = {
                                "lastupdated":
                                datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
                            }
                            lightSensor = findLightSensor(device)
                            if "temperature" in data:
                                tempSensor = findTempSensor(device)
                                tempSensor.state = {
                                    "temperature":
                                    int(data["temperature"] * 100),
                                    "lastupdated":
                                    datetime.utcnow().strftime(
                                        "%Y-%m-%dT%H:%M:%S")
                                }
                            if "illuminance_lux" in data:
                                hue_lightlevel = int(
                                    10000 * math.log10(data["illuminance_lux"])
                                ) if data["illuminance_lux"] != 0 else 0
                                if hue_lightlevel > lightSensor.config[
                                        "tholddark"]:
                                    lightPayload["dark"] = False
                                else:
                                    lightPayload["dark"] = True
                                lightPayload["lightlevel"] = hue_lightlevel
                            elif lightSensor.protocol_cfg[
                                    "lightSensor"] == "on":
                                lightPayload["dark"] = not bridgeConfig[
                                    "sensors"]["1"].state["daylight"]
                                if lightPayload["dark"]:
                                    lightPayload["lightlevel"] = 6000
                                else:
                                    lightPayload["lightlevel"] = 25000
                            else:  # is always dark
                                lightPayload["dark"] = True
                                lightPayload["lightlevel"] = 6000
                            lightPayload["daylight"] = not lightPayload["dark"]
                            if lightPayload["dark"] != lightSensor.state[
                                    "dark"]:
                                lightSensor.dxState["dark"] = current_time
                            lightSensor.state.update(lightPayload)
                            # send email if alarm is enabled:
                            if data["occupancy"] and bridgeConfig["config"][
                                    "alarm"]["enabled"] and bridgeConfig[
                                        "config"]["alarm"][
                                            "lasttriggered"] + 300 < current_time.timestamp(
                                            ):
                                logging.info(
                                    "Alarm triggered, sending email...")
                                requests.post(
                                    "https://diyhue.org/cdn/mailNotify.php",
                                    json={
                                        "to":
                                        bridgeConfig["config"]["alarm"]
                                        ["email"],
                                        "sensor":
                                        device.name
                                    },
                                    timeout=10)
                                bridgeConfig["config"]["alarm"][
                                    "lasttriggered"] = int(
                                        current_time.timestamp())
                        elif device.modelid in standardSensors:
                            convertedPayload.update(standardSensors[
                                device.modelid]["dataConversion"][
                                    data[standardSensors[device.modelid]
                                         ["dataConversion"]["rootKey"]]])
                        for key in convertedPayload.keys():
                            if device.state[key] != convertedPayload[key]:
                                device.dxState[key] = current_time
                        device.state.update(convertedPayload)
                        logging.debug(convertedPayload)
                        if "buttonevent" in convertedPayload and convertedPayload[
                                "buttonevent"] in [
                                    1001, 2001, 3001, 4001, 5001
                                ]:
                            Thread(target=longPressButton,
                                   args=[
                                       device, convertedPayload["buttonevent"]
                                   ]).start()
                        rulesProcessor(device, current_time)
                    elif device.getObjectPath()["resource"] == "lights":
                        state = {"reachable": True}
                        if "state" in data:
                            if data["state"] == "ON":
                                state["on"] = True
                            else:
                                state["on"] = False
                        if "brightness" in data:
                            state["bri"] = data["brightness"]
                        device.state.update(state)

                on_state_update(msg)
        except Exception as e:
            logging.info("MQTT Exception | " + str(e))
Exemplo n.º 8
0
def scanDeconz():
    deconzConf = bridgeConfig["config"]["deconz"]
    deconz_config = requests.get("http://" + deconzConf["deconzHost"] + ":" +
                                 str(deconzConf["deconzPort"]) + "/api/" +
                                 deconzConf["deconzUser"] + "/config").json()
    deconzConf["websocketport"] = deconz_config["websocketport"]

    #sensors
    deconz_sensors = requests.get("http://" + deconzConf["deconzHost"] + ":" +
                                  str(deconzConf["deconzPort"]) + "/api/" +
                                  deconzConf["deconzUser"] +
                                  "/sensors").json()
    for id, sensor in deconz_sensors.items():
        if not getObject("sensors", id):
            new_sensor_id = nextFreeId(bridgeConfig, "sensors")
            if sensor["modelid"] in motionSensors:
                logging.info("register motion sensor as Philips Motion Sensor")
                addHueMotionSensor(
                    sensor["name"], "deconz", {
                        "lightSensor": "on",
                        "deconzId": id,
                        "modelid": sensor["modelid"]
                    })
            elif sensor["modelid"] == "lumi.sensor_motion.aq2":
                if sensor["type"] == "ZHALightLevel":
                    logging.info("register new Xiaomi light sensor")
                    lightSensor = {
                        "name": "Hue ambient light " + sensor["name"][:14],
                        "id_v1": new_sensor_id,
                        "protocol": "deconz",
                        "modelid": "SML001",
                        "type": "ZLLLightLevel",
                        "protocol_cfg": {
                            "deconzId": id
                        },
                        "uniqueid": "00:17:88:01:02:" + sensor["uniqueid"][12:]
                    }
                    bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(
                        lightSensor)
                elif sensor["type"] == "ZHAPresence":
                    logging.info("register new Xiaomi motion sensor")
                    motion_sensor = {
                        "name": "Hue motion " + sensor["name"][:21],
                        "id_v1": new_sensor_id,
                        "protocol": "deconz",
                        "modelid": "SML001",
                        "type": "ZLLPresence",
                        "protocol_cfg": {
                            "deconzId": id
                        },
                        "uniqueid": "00:17:88:01:02:" + sensor["uniqueid"][12:]
                    }
                    bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(
                        motion_sensor)
                    new_sensor_id = nextFreeId(bridgeConfig, "sensors")
                    temp_sensor = {
                        "name":
                        "Hue temperature " + sensor["name"][:16],
                        "id_v1":
                        new_sensor_id,
                        "protocol":
                        "deconz",
                        "modelid":
                        "SML001",
                        "type":
                        "ZLLTemperature",
                        "protocol_cfg": {
                            "deconzId": "none",
                            "id_v1": new_sensor_id
                        },
                        "uniqueid":
                        "00:17:88:01:02:" + sensor["uniqueid"][12:-1] + "2"
                    }
                    bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(
                        temp_sensor)
            elif sensor["modelid"] not in ["PHDL00"]:
                logging.info("register new sensor " + sensor["name"])
                sensor.update({
                    "protocol": "deconz",
                    "protocol_cfg": {
                        "deconzId": id
                    },
                    "id_v1": new_sensor_id
                })
                bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(
                    sensor)