hi,
question is related Openhab and Dashing.
the problem is, how to define the OH-rules, in order to push the data to Dashing:
the code for the openhab-rule from:
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import java.util.*
import java.util.concurrent.locks.*
var Map lastStateMap = new HashMap()
var Lock lock = new ReentrantLock()
rule “Post changes to Dashing Dashboard”
when
Item gDashboard received update
then
lock.lock()
//logInfo(“Dashboard”,“Dashing group rule triggered.”)
gDashboard?.members.forEach[t |
var lastState = lastStateMap.put(t.name, t.state)
if (lastState != t.state || lastState == null) {
val DASHING_TOKEN = '"auth_token" : "YOUR_AUTH_TOKEN"' val DASHING_URI = "http://localhost:3030/widgets/"
///logInfo("Dashboard","Item " + item.name + " changed.") logInfo("Dashboard","Item " + t.name + " has changed state from " +lastState.toString + " to: " + t.state.toString) var uri = DASHING_URI + t.name var json = '{' + DASHING_TOKEN + ', '
if (t.state.toString.startsWith("{")){ var internalJSON = t.state.toString.substring(1) //remove opening '{' as the string will be concatenated with our prefix items //internalJSON = internalJSON.substring(0,internalJSON.length() - 1) json = json + t.state.toString.substring(1) logInfo ("Dashboard","[Debug] json = " + json) } else{ json = json + ' "state" : "' + t.state.toString + '"}' }
logInfo ("Dashboard", "POSTING: " + json) logInfo ("Dashboard", "URI: " + uri + "; JSON = " + json ) sendHttpPostRequest(uri, "HTTP.CONTENT_TYPE_JSON", json) } ] lock.unlock()
end
in Openhab2 (latest snap) i get this error:
2016-02-25 19:43:54.142 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Post changes to Dashing Dashboard': Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
in Openhab1 it is working.(same file)
2016-02-25 20:28:00.012 [INFO ] [openhab.model.script.Dashboard] - Item Temperature_FF_Office has changed state from 17.60000000 to: 19.00000000 2016-02-25 20:28:00.016 [INFO ] [openhab.model.script.Dashboard] - POSTING: {"auth_token" : "YOUR_AUTH_TOKEN", "value" : "19.00000000"} 2016-02-25 20:28:00.017 [INFO ] [runtime.busevents ] - Temperature_FF_Bed state updated to 17.90000000 2016-02-25 20:28:00.016 [INFO ] [openhab.model.script.Dashboard] - URI: http://localhost:3030/widgets/Temperature_FF_Office; JSON = {"auth_token" : "YOUR_AUTH_TOKEN", "value" : "19.00000000"}
what is the issue, why in OH2 it is not working, but in OH1 it is OK?
is there any better way to post the data to dashing?
thanks, Martin