Metainformationen zur Seite
PHP Module loxberry_loxonetemplatebuilder.php
The module loxberry_loxonetemplatebuilder.php is used to more easily generate Loxone Templates for Virtual UDP Inputs, Virtual HTTP Inputs and Virtual Outputs. On usage, you create an VI or VO object, and can add Commands to the VI/VO one by one.
Parameters for the VI/VO and the VI/CO-Cmds are sent as named array. See the table at the bottom for supported parameters for every VI/VO and VI/VO Cmd type.
LoxBerry Compatibility
This module is available from LoxBerry V2.0. Set the minimum LoxBerry version in your plugin.cfg.
Inclusion
require_once "loxberry_loxonetemplatebuilder.php" ; |
loxberry_loxonetemplatebuilder.php has no dependencies. It's not required to add a path to the PHP library's filename.
Abstract
require_once "loxberry_loxonetemplatebuilder.php"; /* Virtual HTTP Inputs */ /* =================== */ $VIhttp = new VirtualInHttp( [ "Title" => "LoxBerry Healthcheck", "Address" => "http://loxberry:loxberry@loxberry/admin/system/healthcheck.cgi" ] ); // Create a VI Command. (the return value represents the line number that was created) $linenr = $VIhttp->VirtualInHttpCmd ( [ "Title" => "timeepoch", "Check" => '"timeepoch":\v' ] ); // Get the created xml template echo $VIhttp->output(); // Get the content of a specific line number (line 3) $vicmd = $VIhttp->VirtualInHttpCmd ( 3 ); // You now can access it's properties, like $vicmd->Title // Delete a specific line $VIhttp->delete($linenr); // Despite of the deletion, all indexes stay intact /* Virtual UDP Inputs */ /* ================== */ $VIudp = new VirtualInUdp( [ "Title" => "LoxBerry Weather", "Address" => "", "Port" => "12345" ] ); $linenr = $VIudp->VirtualInUdpCmd( [ "Title" => "Temperature", "Check" => '"temperature":\v', "Analog" => true ] ); // Get the content of a specific line number (line 3) $vicmd = $VIhttp->VirtualInUdpCmd ( 3 ); // Get the created XML template echo $VIudp->output(); /* Virtual Outputs */ /* =============== */ $VO = new VirtualOut( [ "Title" => "Sonos", "Address" => "http://192.168.1.232:1400" ] ); $linenr = $VO->VirtualOutCmd( [ "Title" => "Play", "CmdOnMethod" => "post", "CmdOn" => '/MediaRenderer/AVTransport/Control', "CmdOnHTTP" => 'SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"', "CmdOnPost" => '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'. '<s:Body><u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>' ] ); echo $VO->output();
Classes
new VirtualInHttp( array $params ) : object
new VirtualInUdp
( array $params ) : object
new VirtualOut
( array $params ) : object
Methods
These methods create the commands in the VI/VO. Using a method not fitting to the correct class throws an exception (e.g. using the class VirtualIn
Http
and creating a command of type VirtualIn
Udp
Cmd
). The methods return an int
that represents the line number of the object.
->VirtualInHttpCmd ( array $params ) : int
->VirtualInUdpCmd ( array $params ) : int
->VirtualOutCmd ( array $params ) : int
If $params is not an array
but a single int
, the method returns an object
with the given line number. You then can access the values with e.g. $lineobj->Title
.
->delete ( int $linenr )
The delete method deletes a line, using the provided index. Despite of the deletion, the index of all other Cmds stay intact (e.g. after deleting line 3, line 4 still is line 4)
->output()
output returns the string of the created VirtualInHttp/VirtualInUdp/VirtualOut
in the correct encoding and quotation.
See the tables below, what parameters and default values the classes provide.
- Omitting a parameter uses the default value.
- Parameters are case-sensitive.
- Boolean values may be written in your favour as true/false, "true"/"false" or 1/0.
- Using a parameter that does not exist, is (currently) ignored (but may throw an exception in the future)
Virtual HTTP Input
Virtual HTTP Input Constructor
new VirtualInHttp
Parameter | Default value | Description in Loxone Config |
Title | Name | |
Comment | Description | |
Address | URL | |
PollingTime | 60 | Polling Cycle [s] |
Virtual HTTP Input Command
VirtualInHttp->VirtualInHttpCmd
Parameter | Default value | Description in Loxone Config |
Title | Name | |
Comment | Description | |
Check | Command recognition | |
Signed | true | Signed values (checkbox) |
Analog | true | (not present) |
SourceValLow | 0 | Input value 1 |
DestValLow | 0 | Target value 1 |
SourceValHigh | 100 | Input value 2 |
DestValHigh | 100 | Target value 2 |
DefVal | 0 | Default value |
MinVal | -2147483647 | Minimum value |
MaxVal | 2147483647 | Maximum value |
Virtual UDP Input
Virtual UDP Input Constructor
new VirtualInUdp
Parameter | Default value | Description in Loxone Config |
Title | Name | |
Comment | Description | |
Address | Sender address | |
Port | UDP receive port |
Virtual UDP Input Command
VirtualInUdp->VirtualInUdpCmd
Parameter | Default value | Description in Loxone Config |
Title | Name | |
Comment | Description | |
Address | Sender address | |
Check | Command recognition | |
Signed | true | Signed values (checkbox) |
Analog | true | Use as digital input (checkbox) |
SourceValLow | 0 | Input value 1 |
DestValLow | 0 | Target value 1 |
SourceValHigh | 100 | Input value 2 |
DestValHigh | 100 | Target value 2 |
DefVal | 0 | Default value |
MinVal | -2147483647 | Minimum value |
MaxVal | 2147483647 | Maximum value |
Virtual Output
Virtual Output Constructor
new VirtualOut
Parameter | Default value | Description in Loxone Config |
Title | Name | |
Comment | Description | |
Address | Address | |
CmdInit | Command to establish connection | |
CloseAfterSend | true | Close connection after sending (checkbox) |
CmdSep | Separator |
Virtual Output Command
VirtualOut->VirtualOutCmd
Parameter | Default value | Description in Loxone Config |
Title | Name | |
Comment | Description | |
CmdOnMethod | HTTP method for ON (dropdown) | |
CmdOn | Command for ON | |
CmdOnHTTP | HTTP extensions for ON | |
CmdOnPost | HTTP Post command for ON | |
CmdOffMethod | HTTP method for OFF (dropdown) | |
CmdOff | Command for OFF | |
CmdOffHTTP | HTTP extensions for OFF | |
CmdOffPost | HTTP Post command for OFF | |
Analog | false | Use as digital input (checkbox) |
Repeat | 0 | First repetition (s) |
RepeatRate | 0 | Repetition Interval (s) |
Further hints
Escaping of checks (\v,...)
- Keep in mind, that \v, \i,… syntax is parsed by PHP. Examples:
- If you use single quotes
'\iHallo:\i\v'
, PHP is directly print these strings. - If you use double quotes, you have to escape the backslash char by a backslash:
"\\iHallo\\i\\v"
.
Filenames for templates
Loxone Config requests specific prefixes for the templates:
- Virtual HTTP Inputs: VI_<name>.xml
- Virtual UDP Inputs: VIU_<name>.xml
- Virtual Outputs: VO_<name>.xml
Writing to file - BOM
The class →output() method creates a string that can be used as required.
Loxone's template files use the BOM (Byte Order Mark), a byte-sequence at the start of the file to signal the usage of UTF-8.
To write a template file to disk, you can create the BOM in this way:
$xmlfilename = "VI_mytemplate.xml"; $xml = $VIhttp->output(); // Add BOM to string $xml = chr(239) . chr(187) . chr(191) . $xml; file_put_contents($xmlfilename, $xml);
Respond web request with a template download
You can create a php script to create the template and directly respond with a file download:
$xmlfilename = "VI_mytemplate.xml"; $xml = $VIhttp->output(); // Add BOM to string $xml = chr(239) . chr(187) . chr(191) . $xml; // Send download response header($_SERVER["SERVER_PROTOCOL"] . " 200 OK"); header("Cache-Control: public"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: Binary"); header("Content-Length: ".strlen($xml)); header("Content-Disposition: attachment; filename=$xmlfilename"); echo $xml;