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?
I’m having the same issue, I think the only way is to create a rule that parses the JSON values and updates the items accordingly (if the value is present). I don’t know of any other solution …
Yep, I followed that route. Made an “item” which is not shown on the basic ui but is linked to a mqtt channel. This item receives the complete json string.
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”.
rule AqaraDeurcontact1_raw
when
Item AqaraDeurcontact1_raw received update
then
val String json = AqaraDeurcontact1_raw.state.toString
if (json.toString.contains("contact"))
{
logInfo("Garagedeur", "Garagedeurcontact update: " + json)
val String contact = transform("JSONPATH", "$.contact", json)
val String battery = transform("JSONPATH", "$.battery", json)
if (contact == "true")
{
garagelampen.sendCommand(OFF)
AqaraDeurcontact1_1.sendCommand("Dicht")
} else
{
garagelampen.sendCommand(ON)
AqaraDeurcontact1_1.sendCommand("Open")
}
AqaraDeurcontact1_2.sendCommand(battery)
}
end
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.
Is that the place to put the combined REGEX + JSON transformation? Or should I put it in the xxx.items files? (which seems to do the same as putting it in the channel configuration).
Yes. See the binding doc section on transformations, that describes chaining using a magic character ∩
You would use REGEX to search for your “ACTION” field, then if present the result passes to JSONPATH.
Apparently, if not present the chain fizzles out without error.
You mean xxx.things file? That’s up to you. The end result is the same. Choose consistently to avoid madness.
You can’t put any channel configuration in xxx.items files.
In case you are are running zigbee2mqtt you should set it to attribute transmission. It’s a new experimental config parameter. No more ugly JSONPATH and no more exceptions.
@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?