/*####################################################################################################################################
# As Nashorn does not have http capabilities through XMLHttpRequest (DOM API), we have to use regular Java classes instead.
# This sample shows how this can be acheived without depending on any third party libraries. Just a standard Java 8 JDK.
# Make sure to have JAVA_HOME/bin on your PATH for the shebang to work. Then just chmod +x away and run...
# Alternatively if you're on a non *nix OS, start with jjs -scritping httpsample.js
####################################################################################################################################*/
var url = "https://api.github.com/repos/openhab/openhab-distro";
var response;
response = httpGet(url).data;
var repo = JSON.parse(response);
events.postUpdate('Open_Issues', repo.open_issues_count);
/*************
UTILITY FUNCTIONS
*************/
function httpGet(theUrl){
var con = new java.net.URL(theUrl).openConnection();
con.requestMethod = "GET";
return asResponse(con);
}
function httpPost(theUrl, data, contentType){
contentType = contentType || "application/json";
var con = new java.net.URL(theUrl).openConnection();
con.requestMethod = "POST";
con.setRequestProperty("Content-Type", contentType);
// Send post request
con.doOutput=true;
write(con.outputStream, data);
return asResponse(con);
}
function asResponse(con){
var d = read(con.inputStream);
return {data : d, statusCode : con.responseCode};
}
function write(outputStream, data){
var wr = new java.io.DataOutputStream(outputStream);
wr.writeBytes(data);
wr.flush();
wr.close();
}
function read(inputStream){
var inReader = new java.io.BufferedReader(new java.io.InputStreamReader(inputStream));
var inputLine;
var response = new java.lang.StringBuffer();
while ((inputLine = inReader.readLine()) != null) {
response.append(inputLine);
}
inReader.close();
return response.toString();
}
Spent a couple hours on the debugger this morning:
The log messages are more user friendly (not all event types are recognized).
Add items to a watchlist and monitor their states.
You can also send update the state from the watchlist by editing the text box and hitting Return:
this will send a command (or hit Esc to discard your changes).
Add an item to the watchlist by clicking its name in the log.
This might be useful to you even if you don’t use the other features.
I see you set “visibility: hidden” for rules in the latest version - but that seems to have the side effect of them not being shown when using the REST API: eg. http://openhab:8080/rest/rules. Do you have any suggestions? Otherwise I’ll raise this as an issue against eclipse smarthome
About the rules being hidden now: this is intentional, to avoid polluting the view in Paper UI with “technical” rules, and discourage editing them directly. Certainly not an issue with ESH!
They are tagged with the ID of the flow so for example if you published rules related to “flow1” they can still be listed with: http://openhab:8080/rest/rules?tags=flow1
If you’re not sure exactly about which rules are in your system you can always check out the JSON DB in userdata/jsondb/automation_rules.json
Yes, the problem is there seems to be no way to retrieve all hidden rules from the API without first knowing the rule exists. On the text console you can run automation listRules and that returns everything.
Ah, good to know. Another possible solution is to leave the “root” rules (those with triggers) visible and hide the “additional” ones (those created when traversing the flow).
Still using this to make rules i think it will be an awesome addition.
Some things i have noticed:
When you press “Delete” on they keyboard if you are editing some text in the “Module Configuration” section it removes the full node. I was only expecting it to remove the text character i was editing. Note: backspace works fine
you dont seem to be able to copy and paste into the the text boxs in the configuration panel
When you add the “say something” blob it doesnt let you select the Audio sink from a drop down like the “pay a sound” does
it would be nice to be able to see the debug panel while in the configuration panel
Thanks for the reports
1. & 2. are essentially the same silly bug - the event handlers for deleting and copy-pasting nodes take precedence even when the focus is in a text box; I’ll have a fix
3. happens in Paper UI too, there is apparently a mistake in the config descriptions for the “say something” module
4. could be tricky - what’s wrong with simply deselecting the node?
Hi Yannick, do you still develop and maintain this great project? If not you could ask Kai Kreuzer if this can become part of openhab or maintained there. Your project has great potential and make openhab a lot easier to use. Thanx a lot for your great work!
Are there still problems with the new rules engine or has it improved the last 8 month?
I think your flow builder is exactly the way how rules should be created. I really think openhab needs a developer like you with great ideas and the knowledge to build stuff like the flow builder for a great user experience.
Your great work should not get lost because of some bugs in the experimental rules engine - instead the bugs should get fixed so your work can continue.
Will you continue your work on flow builder when the rules engine improves?
The main bug imo is that the rules are not initialized after a restart, the logs show that modules are missing (not found).
I really can’t say if I’ll have the time or interest to continue working on this, but I’m not excluding it if I start using it again. Btw the work is not “lost”! - the source code is there on GitHub, anyone could take over eventually.