I would like to name an individual openHAB instance in an .items file to be able to discriminate multiple such instances and to administer them remotely. That means to send out the entire configuration, logs, and to write configuration back - manually or by cron. The scenario could be industrial control applications across multiple sites.
Currently I misuse the http plugin and an “echo” mechanism to do something like this - openhab.items:
String Config_ID "ID [%s]" (Config) { http="<[http://www.mysite.com/echo/?text=openHAB001:300000:REGEX()]" }
String Config_Version "version [%s]" (Config) { http="<[http://www.mysite.com/echo/?text=20170203:300000:REGEX()]" }
String Config_Path "path [%s]" (Config) { http="<[http://www.mysite.com/echo/?text=%%2Fopt%%2Fopenhab-1.8.3-runtime:300000:REGEX()]" } // escaping for URL and java.util.Formatter
Switch Config_Toggle_Send_Config "Konfiguration senden" (Config)
Switch Config_Toggle_Send_Logs "Logs senden" (Config)
Switch Config_Toggle_Get "Konfiguration empfangen" (Config)
<?php echo urldecode($_GET['text']) ?>
openhab.sitemap:
Text label="Konfiguration und Support" icon="icon-tools-0032" {
Frame label="Konfiguration und Support" {
Text item=Config_ID
Text item=Config_Version
Text item=Config_Path
Switch item=Config_Toggle_Send_Config icon="icon-box-out-0032" label="Konfiguration an Betreiber senden (auslesen)"
Switch item=Config_Toggle_Send_Logs icon="icon-box-out-0032" label="Logs an Betreiber senden (auslesen)"
Switch item=Config_Toggle_Get icon="icon-box-in-0032" label="Konfiguration von Betreiber holen (überschreiben)"
}
}
openhab.rules:
rule "Send config"
when Item Config_Toggle_Send_Config changed from OFF to ON
then
sendMail(mailTo, "openHAB: send_config " + Config_ID.state, "N/A", "file://" + Config_Path.state + "/configurations/sitemaps/hausgart.sitemap")
// TODO: include others (*.rules, .items) and zip up before sending
sendCommand(Config_Toggle_Send_Config, OFF)
end
rule "Send logs"
when Item Config_Toggle_Send_Logs changed from OFF to ON
then
sendMail(mailTo, "openHAB: send_logs " + Config_ID.state, "N/A", "file://" + Config_Path.state + "/logs/openhab.log")
// TODO: and other logs
sendCommand(Config_Toggle_Send_Logs, OFF)
end
rule "Get config"
when Item Config_Toggle_Get changed from OFF to ON
then
/* via http GET: backup, fetch, unzip, overwrite config files */
sendCommand(Config_Toggle_Get, OFF)
end
This works, but is there a simpler way of doing this - namely in regards to the http plugin?
That would need to be a dumb echo plugin or the ability to specify a string literal.
Or is there an other way of doing this, like read in a .properties file?