public function setDeviceStatus($deviceId, $state = null, $level = null)
    {
        $groupAction = 'NO';
        $devices = $this->getPairedDevices();
        foreach ($devices as $d) {
            if ($deviceId === $d['DeviceID']) {
                $groupAction = $d['IsGroupAction'];
            }
        }

        if (intval($level) > 0 && $state === 0) {
            $state = '1';
        }

        $capids = [];
        $capval = [];
        if ($state !== null) {
            $capids[] = '10006';
            $capval[] = $state;
        }
        if ($level !== null) {
            $capids[] = '10008';
            $capval[] = $level . ':0';
        }

        $capIdsString = implode(',', $capids);
        $capValString = implode(',', $capval);

        $service = $this->services['BridgeService']['serviceType'];
        $controlUrl = $this->services['BridgeService']['controlURL'];
        $method = 'SetDeviceStatus';
        $arguments = [
            'DeviceStatusList' => '&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;DeviceStatusList&gt;&lt;DeviceStatus&gt;&lt;IsGroupAction&gt;' .
                $groupAction .
                '&lt;/IsGroupAction&gt;&lt;DeviceID available=&quot;YES&quot;&gt;' .
                $deviceId .
                '&lt;/DeviceID&gt;&lt;CapabilityID&gt;' .
                $capIdsString .
                '&lt;/CapabilityID&gt;&lt;CapabilityValue&gt;' .
                $capValString .
                '&lt;/CapabilityValue&gt;&lt;LastEventTimeStamp&gt;0&lt;/LastEventTimeStamp&gt;&lt;/DeviceStatus&gt;&lt;/DeviceStatusList&gt;'
        ];

        $rs = $this->client->request($controlUrl, $service, $method, $arguments);
        $rs = $this->unwrapResponse($rs);

        if (isset($rs['s:Fault'])) {
            throw new \Exception('Failed to change bulb state. ' . print_r($rs, true));
        }

        return true;
    }