I have a rule, which should parse a JSON sent to an item, which works “normally” fine, but I’m afraid, the rule/script engine is too fast for the changing value, if I look at the logs:
==> /var/log/openhab/events.log <==
2021-01-08 15:34:04.063 [INFO ] [openhab.event.ItemCommandEvent ] - Item NukiSmartLock_CallbackJSON' received command {"deviceType": 0, "nukiId": 1234, "mode": 2, "state": 3, "stateName": "unlocked", "batteryCritical": "OFF", "batteryCharging": "OFF", "batteryChargeState": 72, "doorsensorState": 2, "doorsensorStateName": "door closed"}
==> /var/log/openhab/openhab.log <==
2021-01-08 15:34:04.068 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'NukiCallbackJSON': Fail to execute action: 2
==> /var/log/openhab/events.log <==
2021-01-08 15:34:04.071 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'NukiSmartLock_CallbackJSON' changed from {"mode":2,"state":3,"stateName":"unlocked","batteryCritical":false,"batteryCharging":false,"batteryChargeState":72,"doorsensorState":3,"doorsensorStateName":"door opened","timestamp":"2021-01-08T14:31:12+00:00"} to {"deviceType": 0, "nukiId": 1234, "mode": 2, "state": 3, "stateName": "unlocked", "batteryCritical": "OFF", "batteryCharging": "OFF", "batteryChargeState": 72, "doorsensorState": 2, "doorsensorStateName": "door closed"}
I know, the update-JSON has a different structure as the old one, I interpret only attributes in both JSONs
triggers:
- id: "1"
configuration:
itemName: NukiSmartLock_CallbackJSON
type: core.ItemCommandTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >
var nukicallback = JSON.parse(items["NukiSmartLock_CallbackJSON"]);
events.postUpdate("NukiSmartLock_Batteriestatus", nukicallback.batteryChargeState);
events.postUpdate("NukiSmartLock_DoorState", nukicallback.doorsensorState);
events.postUpdate("NukiSmartLock_LockState", nukicallback.state);
events.postUpdate("NukiSmartLock_NiedrigerBatteriestatus", nukicallback.batteryCritical);
type: script.ScriptAction
Is there a way to have the rule wait for the “changedValue” or something?