In my network I have a large number of zigbee devices from MI /AQARA etc. These send a nice JSON formatted message when they are triggered. This message contains an “ACTION” field which I filter out for my items.
BUT, sometimes these devices send an “hello I’m still alive” message, which missses the “ACTION” part. This leads to a very large and long error message (at least 30 lines) in my logging. Unneeded I would say. It is sort of a crash log.
Can it be disabled?
Or is there a trick to prevent JSON errors when the incomming string does not contain the field the transformation was looking for?
Then made a rule which triggers on the “AqaraDeurcontact1_raw” received update. Check if certain keys are in the JSON and then filter out the relevant info from the JSON and update the visible items on the UI. Meanwhile also triggering “actions”.
Item AqaraDeurcontact1_raw received update
val String json = AqaraDeurcontact1_raw.state.toString
logInfo("Garagedeur", "Garagedeurcontact update: " + json)
val String contact = transform("JSONPATH", "$.contact", json)
val String battery = transform("JSONPATH", "$.battery", json)
if (contact == "true")
That works correctly, even when the JSON contains different keys sometimes (in fact is missing some keys sometimes).
Ofcourse it would have been nice if the JSON parser would shut up if a key is not present and not fill the log with the “crash report”. Until then, this seems a nice solution.
@job I can’t seem to find the configuration setting for the attribute transmission (or could be misunderstanding what it is supposed to do as I’ve only just started looking at zigbee2mqtt). Can you point me to the relevant config parameter?