Calculate "last seen" from zbbridge output

Hi all,
I’m in the process of migrating my Zigbee devices to Tasmota Sonoff zbBridge. Unfortunately, it doesn’t output the battery life with every update which means I keep getting log entries about failed transformation which I guess I can live with (if there is a neat solution please let me know)

Anyway it also outputs the time last seen as part of a different output message and it does so in seconds. How does one go about calculating the last time a device was seen? (in the latest Tasmota v9.2 release it actual shows it on the web interface. I wish it were possible to get that from the json output too.

Thank you in advance

Not without more detail, but at a guess if some JSON element is not alwas present you can exploit the chain transform feature of MQTT binding, and use REGEX to see if some keyword is present, fail silently if not, or use JSONPATH to extract data.

You mean you have a “Epoch” style timestamp, and you’d like to transform to OH datetime?

That’s exactly it. It outputs the remaining battery percentage but once in a while and not with every update. How would one go about using REGEX to do that?

Yes. It outputs the last seen value in Epoch timestamp. I’d like to transform it to OH time value if possible.

I believe the OH DateTime type Item is clever enough to accept Epoch integer as an update directly, and guess whether its a seconds- or milliseconds-style value.

The problem you might run into is that this contains no timezone info, and will be assumed to UTC.

Thank you for that. I haven’t tried Epoch yet. however, I’m having trouble with Regex

|2020-12-24 19:50:46|2020-12-24 19:50:45.878 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service REGEX for pattern (.*Contact.*) not found!|
|---|---|
|2020-12-24 19:50:46|2020-12-24 19:50:45.882 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service REGEX for pattern (.*BatteryPercentage.*) not found!|
|2020-12-24 19:50:46|2020-12-24 19:50:45.885 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: An error occurred while transforming JSON expression.|
|2020-12-24 19:50:46|2020-12-24 19:50:45.887 [DEBUG] [ab.binding.mqtt.generic.ChannelState] - Transformation '{"ZbReceived":{"Door_Sensor":{"Device":"0x33D7","Name":"Door_Sensor","BatteryVoltage":3.01,"BatteryPercentage":100,"Contact":0,"Endpoint":1,"LinkQuality":123}}}' returned null on 'JSONPATH', discarding message|

Here is the thing config

Thing topic DoorSensor "Aqara Door Sensor" @"MQTT"

        {

                Channels:

                        Type contact : contact "Door Sensor"

                        [

                                stateTopic = "tele/Door_Sensor/SENSOR",

                                transformationPattern="REGEX:(.*Contact.*)∩JSONPATH:$.ZbReceived.Door_Sensor.Contact",

                                on="1", //there is NO contact so the door is Open

                                off="0"  //there is contact so the door must be closed

                        ]

                        Type number : battery "Door Sensor Battery"

                        [

                                stateTopic="tele/Door_Sensor/SENSOR",

                                transformationPattern="REGEX:(.*BatteryPercentage.*)∩JSONPATH:$.ZbReceived.Door_Sensor.BatteryPercentage, unit=%"

                        ]

                        Type number : link_quality "Door Sensor Link Quality"

                        [

                                stateTopic="tele/Door_Sensor/SENSOR",

                                transformationPattern="JSONPATH:$.ZbReceived.Door_Sensor.LinkQuality"

                        ]

                        Type datetime : last_seen "Last Seen"

                        [

                                //stateTopic="tele/Door_Sensor/SENSOR",

                                //transformationPattern="JSONPATH:$.ZbReceived.Door_Sensor.LinkQuality"

                        ]

        }

What am I doing wrong?