Anyone know how i can pull the value of rad out of this string in a rule to update an item. This is a little different then normal as its a string within a string so the traditional method isnt working…
Yes im trying to change this rule into that. This rule works for normal waypoint updates but when you manually push update waypoints it sends a string in a string which is different so this rule dont see it…
rule "OwnTracks Waypoint Jay"
when
Item JCWayPointData received update
then
logInfo("MQTT", "OwnTracks waypoint updated for Jay")
val String json = (JCWayPointData.state as StringType).toString
val String type = transform("JSONPATH", "$._type", json)
if (type == "waypoints") {
val String desc = transform("JSONPATH", "$.desc", json)
JCRadius.postUpdate(desc)
logInfo("OwnTracks", "Jay is at " + desc)
}
end
Yea i know, forget about that part… im just looking for the correct string to use in that rule to pull the data i need when i manually push update waypoint
I cant use “waypoint” currently because i cannot read that string in a string. Currently i can only grab the initial “waypoints” from it to use. That’s why i needed help to read that. Then i can change it to the “waypoint” string in there.
This is the manually pushed string: (trying to read this in a rule)
All depends on how the json string is posted to the rule! As stated above, the variable JSON-String expects the json as posted above (first example).
I’d use some lines like
rule "OwnTracks Waypoint Jay"
when
Item JCWayPointData received update
then
logInfo("MQTT", "OwnTracks waypoint updated for Jay")
val String json = (JCWayPointData.state as StringType).toString
var Number myType = transform("JSONPATH", "$.waypoints[0]._type", JSON_String)
if (mytype == "waypoint") {
val String myRad = transform("JSONPATH", "$.waypoints[0].rad", JSON_String)
JCRadius.postUpdate(rad)
logInfo("OwnTracks", "Jay is at " + desc)
}
end
Error during the execution of rule ‘OwnTracks Waypoint Jay’: The name ‘JSON_String’ cannot be resolved to an item or type.
2017-02-11 11:26:08.331 [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn’t post update for 'JCRadius’
2017-02-11 11:26:08.562 [INFO ] [openhab.model.script.OwnTracks] - Jay is at null
rule "OwnTracks Waypoint Jay"
when
Item JCWayPointData received update
then
logInfo("MQTT", "OwnTracks waypoint updated for Jay")
val String json = (JCWayPointData.state as StringType).toString
var String myType = transform("JSONPATH", "$.waypoints[0]._type", JSON_String)
if (myType == "waypoint") {
val String myRad = transform("JSONPATH", "$.waypoints[0].rad", JSON_String)
JCRadius.postUpdate(myRad)
logInfo("OwnTracks", "Jay is at " + desc)
}
end
rule "OwnTracks Waypoint Jay"
when
Item JCWayPointData received update
then
logInfo("MQTT", "OwnTracks waypoint updated for Jay")
val String json = (JCWayPointData.state as StringType).toString
var String myType = transform("JSONPATH", "$.waypoints[0]._type", json)
if (myType == "waypoint") {
val String myDesc = transform("JSONPATH", "$.waypoints[0].desc", json)
JCRadius.postUpdate(myDesc)
logInfo("OwnTracks", "Jay is at " + myDesc)
}
end