I know, it’s time to have a look at the Next-Gen rules…
But until then, I have a problem with my rule here.
- I configured Nuki callback, which presents a JSON (which I relay via a PHP-script on my webserver, because a) the Nuki binding is broken and b) a direct callback doesn’t work)
- the JSON is sent to a item
- if the JSON gets an update, I like to parse it and update my Nuki items
so, the items:
String Nuki_callback "Callback-Meldung [%s]"
Number Nuki_doorState "Nuki State (Status) [%d]"
Number Nuki_doorStateName "Nuki State (Name) [%s]"
Number Nuki_doorsensorState "Nuki Sensor (Status) [%d]"
String Nuki_doorsensorName "Nuki Sensor (Name) [%s]"
Switch Nuki_doorBattery "Nuki Batteriestatus [%s]"
the item “Nuki_callback
” gets updated from Nuki via this JSON:
{"deviceType": 0, "nukiId": 123456789, "mode": 2, "state": 3, "stateName": "unlocked", "batteryCritical": false, "doorsensorState": 3, "doorsensorStateName": "door opened"}
in my rule, I like to update the items like this:
rule "Nuki Update"
when
Item Nuki_callback received command
then
logInfo("Nuki doorsensorname", "Name: " + transform("JSONPATH", "$.doorsensorStateName", Nuki_callback.state.toString))
if (transform("JSONPATH", "$.batteryCritical", Nuki_callback.state).toString === "true") {
Nuki_doorBattery.sendCommand(ON)
} else {
Nuki_doorBattery.sendCommand(OFF)
}
Nuki_doorsensorName.sendCommand(transform("JSONPATH", "$.doorsensorStateName", Nuki_callback.state.toString).toString)
Nuki_doorsensorState.sendCommand(transform("JSONPATH", "$.doorsensorState", Nuki_callback.state.toString).toString)
Nuki_doorState.sendCommand(transform("JSONPATH", "$.state", Nuki_callback.state.toString).toString)
Nuki_doorStateName.sendCommand(transform("JSONPATH", "$.stateName", Nuki_callback.state.toString).toString)
end
If the callback gets updated, I get this in the log:
2020-09-29 18:16:58.918 [ome.event.ItemCommandEvent] - Item 'Nuki_callback' received command {"deviceType": 0, "nukiId": 1234567879, "mode": 2, "state": 3, "stateName": "unlocked", "batteryCritical": false, "doorsensorState": 3, "doorsensorStateName": "door opened"}
==> /var/log/openhab2/openhab.log <==
2020-09-29 18:16:58.938 [INFO ] [ome.model.script.Nuki doorsensorname] - Name: door opened
2020-09-29 18:16:58.945 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Nuki Update': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.core.transform.actions.Transformation.transform(java.lang.String,java.lang.String,java.lang.String) on instance: null
I guess, I’ll never get my head wrapped around the “.toString
”, when to use, I tried with and without and it won’t change the ERROR.
What do I miss here? Thanks!