So basically trying to capture the data received from owntracks via mqtt and have it populate fields such as latitude, longitude, battery, etc…
I am trying to get another users rule working to no avail,
rule "MQTT Owntracks JC"
when
Item JCRawData changed
then
logInfo("MQTT", "MQTT Owntracks JC data received")
val String json = (JCRawData.state as StringType).toString
val String type = transform("JSONPATH", "$._type", json)
if (type == "location") {
val String lat = transform("JSONPATH", "$.lat", json)
val String lon = transform("JSONPATH", "$.lon", json)
val String acc = transform("JSONPATH", "$.acc", json)
val String batt = transform("JSONPATH", "$.batt", json)
logInfo("MQTT", "MQTT Updating values")
JCLatitude.postUpdate(lat)
JCLongitude.postUpdate(lon)
JCLocation.postUpdate(new PointType(lat + "," + lon))
JCAccuracy.postUpdate(new DecimalType(acc))
JCBattery.postUpdate(new PercentType(batt))
}
end
When mqtt posts to JCRawData i get the following
Error during the execution of rule 'MQTT Owntracks JC': Cannot cast org.openhab.core.library.types.DecimalType to org.openhab.core.library.types.StringType
Can anyone help me get this working!!? pleaaasseee!
Your items file has incorrect item types. You must choose ones that match the data you want to hold. For example, the raw data should be a String item. Please go back to your source example and also find docs on items and item types. I hope this helps!
Ive changed them all over and over and no luck. I still get
2017-02-09 10:13:38.945 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-02-09 10:13:38.948 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2017-02-09 10:14:09.401 [INFO ] [org.openhab.model.script.MQTT ] - MQTT Owntracks JC data received
2017-02-09 10:14:14.356 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'MQTT Owntracks JC': Cannot cast org.openhab.core.library.types.DecimalType to org.openhab.core.library.types.StringType
String JCRawData "RawData" (persist) { mqtt="<[mosquitto:owntracks/jcid/]" }
Number JCPosition "Position: %d" (persist)
Number JCLatitude "Lattitude: %d" (persist)
Number JCLongitude "Longitude: %d" (persist)
Number JCLocation "Location: %d" (persist)
Number JCAccuracy "Accuracy: %d" (persist)
Number JCBattery "Battery: %d" (persist)
rule "MQTT Owntracks JC"
when
Item JCRawData changed
then
logInfo("MQTT", "MQTT Owntracks JC data received")
val String json = (JCRawData.state as StringType).toString
val String type = transform("JSONPATH", "$._type", json)
if (type == "location") {
val Number lat = transform("JSONPATH", "$.lat", json)
val Number lon = transform("JSONPATH", "$.lon", json)
val Number acc = transform("JSONPATH", "$.acc", json)
val Number batt = transform("JSONPATH", "$.batt", json)
logInfo("MQTT", "MQTT Updating values")
JCLatitude.postUpdate(lat)
JCLongitude.postUpdate(lon)
JCLocation.postUpdate(new PointType(lat + "," + lon))
JCAccuracy.postUpdate(new DecimalType(acc))
JCBattery.postUpdate(new PercentType(batt))
}
end