Installation
composer require dodev34/sdk-domoticz-bundle
Ensure your project uses Symfony 2.x/3.x (last release was 2017).
Register the Bundle
Add to app/AppKernel.php:
new M12U\Bundle\Sdk\DomoticzBundle\M12USdkDomoticzBundle(),
Configure Domoticz Connection
Add to app/config/config.yml:
m12_u_sdk_domoticz:
username: YOUR_DOMOTICZ_USERNAME
password: YOUR_DOMOTICZ_PASSWORD
base_uri: http://<DOMOTICZ_IP>:8080
Verify Domoticz has a user with API access enabled.
First Use Case: Fetch Sunrise/Sunset Inject the service and call:
$provider = $this->get('m12u.sdk.domoticz.provider_proxy');
$command = $provider->getClient('command');
$sunTimes = $command->getSunRiseSet();
Device Management
$deviceClient = $provider->getClient('device');
$devices = $deviceClient->getDevices();
$device = $deviceClient->getDevice(DEVICE_ID);
Light/Switch Control
$command = $provider->getClient('command');
$command->switchLight(DEVICE_ID, true/false);
$command->setColbrightnessValue(DEVICE_ID, 50); // 0-100
Logging
$command->addLogMessage("System rebooted at " . date('Y-m-d H:i:s'));
{"status":"OK"} or {"status":"ERROR"}.provider_proxy service in controllers/services.getDevices()) using Symfony’s cache layer if Domoticz updates are infrequent.Deprecated Symfony Version
No Rate Limiting
try {
$result = $command->switchLight($id, $state);
} catch (\Exception $e) {
if (strpos($e->getMessage(), 'timeout') !== false) {
sleep(2); // Retry after delay
}
}
Undocumented Responses
switchLight) lack clear return-value docs. Inspect raw responses:
var_dump($command->switchLight($id, true)); // Check structure
Base URI Quirks
base_uri includes the port (e.g., :8080) and no trailing slash. Test with:
base_uri: http://192.168.1.100:8080/
$client = $provider->getClient('command');
$client->setLogger($this->get('logger')); // Requires custom extension
Custom Commands
DomoticzClient class (requires modifying the bundle or creating a decorator service).Authentication
Authenticator service and binding it to the bundle’s authenticator tag.Response Transformers
response_transformer to normalize responses:
# config/services.yml
services:
app.domoticz.response_transformer:
class: App\Service\DomoticzResponseTransformer
tags: [m12u.sdk.domoticz.response_transformer]
How can I help you explore Laravel packages today?