Compare commits

...

3 Commits

Author SHA1 Message Date
bwssystems
51ce10cfc7 Fixed build device button in Harmony Device helper tab.
Fixes #116
2016-05-15 12:25:28 -05:00
Admin
b5f7144c9c Update readme with a script construction. 2016-05-11 14:36:58 -05:00
Admin
86a931d383 added exec:// type for loops. updated button maptypeid naming.
Fixes #114
Fixes #115
2016-05-11 12:23:43 -05:00
4 changed files with 78 additions and 18 deletions

View File

@@ -21,10 +21,10 @@ Then locate the jar and start the server with:
ATTENTION: This requires JDK 1.8 to run
```
java -jar ha-bridge-2.0.5.jar
java -jar ha-bridge-2.0.6.jar
```
### Automation on Linux systems
To have this conigured and running automatically ther eare a few resources to use. One is using Docker and a docker container has been built for this and can be gotten here: https://github.com/aptalca/docker-ha-bridge
To have this configured and running automatically there are a few resources to use. One is using Docker and a docker container has been built for this and can be gotten here: https://github.com/aptalca/docker-ha-bridge
For next gen Linux systems, here is a systemctl unit file that you can install. Here is a link on how to do this: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
```
@@ -35,11 +35,43 @@ After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/amazon-echo/data/habridge.config /home/pi/amazon-echo/ha-bridge-2.0.5.jar
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/amazon-echo/data/habridge.config /home/pi/amazon-echo/ha-bridge-2.0.6.jar
[Install]
WantedBy=multi-user.target
```
Basic script setup to run the bridge on a pi.
Create the directory and make sure that ha-bridge-2.0.6.jar is in your /home/pi/habridge directory.
```
pi@raspberrypi:~ $ mkdir habridge
pi@raspberrypi:~ $ cd habridge
pi@raspberrypi:~/habridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v2.0.6/ha-bridge-2.0.6.jar
```
Edit the shell script for starting:
```
pi@raspberrypi:~/habridge $ nano starthabridge.sh
```
Then cut and past this, modify any locations that are not correct
```
cd /home/pi/habridge
rm /home/pi/habridge/habridge-log.txt
nohup java -jar /home/pi/habridge/ha-bridge-2.0.6.jar > /home/pi/habridge/habridge-log.txt 2>&1 &
chmod 777 /home/pi/habridge/habridge-log.txt
```
Exit and save the file with ctrl-X and follow the prompts and then execute on the command line:
```
pi@raspberrypi:~/habridge $ chmod u+x starthabridge.sh
```
Then execute the script:
```
pi@raspberrypi:~/habridge $ ./starthabridge.sh
```
You should now be running the bridge. Check for errors:
```
pi@raspberrypi:~/habridge $ tail -f habridge-log.txt
```
## Available Arguments
Arguments are now deprecated. The ha-bridge will use the old -D arguments and populate the configuration screen, Brisge Control Tab, which can now be saved to a file and will not be needed. There is only one optional argument that overrides and that is the location of the configuration file. The default is the relative path "data/habridge.config".
### -Dconfig.file=`<filepath>`
@@ -151,7 +183,7 @@ tcp://192.168.5.5:110000/0x
```
#### Multiple Call Construct
Also available is the ability to specify multiple commands in the On URL, Dim URL and Off URL areas by adding Json constructs listed here.
Also available is the ability to specify multiple commands in the On URL, Dim URL and Off URL areas by adding Json constructs listed here. This is only for the types of tcp, udp, http, https or a new exec type.
Format Example in the URL areas:
```
[{"item":"http://192.168.1.1:8180/do/this/thing"},
@@ -165,7 +197,8 @@ Format Example in the URL areas:
[{"item":"udp://192.168.1.1:5000/0x450555"},
{"item":"http://192.168.1.1:8180/do/this/thing"},
{"item":"tcp://192.168.2.1/sendthisdata"},
{"item":"https://192.168.12.1/do/this/secure/thing"}]
{"item":"https://192.168.12.1/do/this/secure/thing"},
{"item":"exec://notepad.exe"}]
```
#### Script or Command Execution
The release as of v2.0.0 will now support the execution of a local script or program. This will blindly fire off a process to run and is bound by the privileges of the java process.
@@ -185,6 +218,10 @@ OR
/home/me/startsomething.sh
OR
[{"item":"exec://notepad.exe"}]
```
Also, you may want to use the REST API's listed below to configure your devices.

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>2.0.5</version>
<version>2.0.7</version>
<packaging>jar</packaging>
<name>HA Bridge</name>

View File

@@ -428,7 +428,7 @@ public class HueMulator implements HueErrorStringSet {
else
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"No HUE configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
return responseString;
return responseString;
}
if(stateHasBri)
@@ -570,18 +570,19 @@ public class HueMulator implements HueErrorStringSet {
if( i > 0) {
Thread.sleep(bridgeSettings.getButtonsleep());
}
try {
log.debug("Executing request: " + callItems[i].getItem());
Process p = Runtime.getRuntime().exec(replaceIntensityValue(callItems[i].getItem(), state.getBri(), false));
log.debug("Process running: " + p.isAlive());
} catch (IOException e) {
log.warn("Could not execute request: " + callItems[i].getItem(), e);
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
String intermediate;
if(callItems[i].getItem().contains("exec://"))
intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
else
intermediate = callItems[i].getItem();
String anError = doExecRequest(intermediate, state, lightId);
if(anError != null) {
responseString = anError;
i = callItems.length+1;
}
}
}
}
else // This section allows the usage of http/tcp/udp calls in a given set of items
else // This section allows the usage of http/tcp/udp/exec calls in a given set of items
{
log.debug("executing HUE api request for network call: " + url);
if(!url.startsWith("[")) {
@@ -634,6 +635,14 @@ public class HueMulator implements HueErrorStringSet {
dataSendSocket.close();
}
}
else if(callItems[i].getItem().contains("exec://")) {
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
String anError = doExecRequest(intermediate, state, lightId);
if(anError != null) {
responseString = anError;
i = callItems.length+1;
}
}
else {
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + callItems[i].getItem());
@@ -781,6 +790,19 @@ public class HueMulator implements HueErrorStringSet {
}
return theContent;
}
private String doExecRequest(String anItem, DeviceState state, String lightId) {
log.debug("Executing request: " + anItem);
String responseString = null;
try {
Process p = Runtime.getRuntime().exec(replaceIntensityValue(anItem, state.getBri(), false));
log.debug("Process running: " + p.isAlive());
} catch (IOException e) {
log.warn("Could not execute request: " + anItem, e);
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
}
return responseString;
}
private String formatSuccessHueResponse(DeviceState state, String body, boolean stateHasOn, String lightId) {

View File

@@ -988,21 +988,22 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
};
$scope.buildButtonUrls = function (harmonydevice, onbutton, offbutton) {
bridgeService.clearDevice();
var currentOn = $scope.device.onUrl;
var currentOff = $scope.device.offUrl;
var actionOn = angular.fromJson(onbutton);
var actionOff = angular.fromJson(offbutton);
if( $scope.device.mapType == "harmonyButton") {
$scope.device.mapId = $scope.device.mapId + "-" + actionOn.command;
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
$scope.device.offUrl = currentOff.substr(0, currentOff.indexOf("]")) + ",{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
}
else if ($scope.device.mapType == null || $scope.device.mapType == "") {
bridgeService.clearDevice();
$scope.device.deviceType = "button";
$scope.device.targetDevice = harmonydevice.hub;
$scope.device.name = harmonydevice.device.label;
$scope.device.mapType = "harmonyButton";
$scope.device.mapId = harmonydevice.device.id + "-" + actionOn.command + "-" + actionOff.command;
$scope.device.mapId = harmonydevice.device.id + "-" + actionOn.command;
$scope.device.onUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
$scope.device.offUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
}