Hello,
I’m using the websocket client, which is really great. I find it more useful to process only devices that have changed rather than making an API request on a device, retrieving the state of a device, checking if it has changed, and if so, processing it.
It’s easy to process messages received via the websocket in JSON since they are all ‘changed’. In my use case, I ignore JSON messages whose first key is “attr” that don’t have a changed ‘state’, and I process the others. My goal is to retrieve the ‘state’ key of each message and process it. It works very well, except that I encounter this situation quite often:
{“e”:“changed”,“id”:“140”,“r”:“sensors”,“state”:{“alarm”:false,“demain”:“----”,“lastupdated”:“2025-07-02T08:21:10.081”,“ltarf”:“”,“ngtf_optarif”:“BBR(”,“ntarf”:0,“production”:0,“stge”:“”,“tariffPeriod”:“HPJB”},“t”:“event”,“uniqueid”:“00:15:8d:00:06:20:57:06-01-ff66”}
{“e”:“changed”,“id”:“140”,“r”:“sensors”,“state”:{“alarm”:false,“demain”:“----”,“lastupdated”:“2025-07-02T08:21:10.145”,“ltarf”:“”,“ngtf_optarif”:“BBR(”,“ntarf”:0,“production”:0,“stge”:“”,“tariffPeriod”:“HPJB”},“t”:“event”,“uniqueid”:“00:15:8d:00:06:20:57:06-01-ff66”}
{“e”:“changed”,“id”:“140”,“r”:“sensors”,“state”:{“alarm”:false,“demain”:“----”,“lastupdated”:“2025-07-02T08:21:10.273”,“ltarf”:“”,“ngtf_optarif”:“BBR(”,“ntarf”:0,“production”:0,“stge”:“”,“tariffPeriod”:“HPJB”},“t”:“event”,“uniqueid”:“00:15:8d:00:06:20:57:06-01-ff66”}
In these three consecutive messages, I retrieve the ‘state’ key, and the only modification is ‘lastupdated’.
This is annoying because it limits a major benefit of the websocket: transmitting only modified messages.
To compare the ‘state’ values, I have to delete $json[‘state’][‘lastupdated’] and compare them afterward.
This is possible; I do it systematically now, but I must say it’s very annoying.
I sometimes need ‘lastseen’ information, but I’ve never needed ‘lastupdated’.
Is it possible to not transmit [‘state’][‘lastupdated’] in the websocket?
Or is it possible to have an option somewhere to not receive this key in messages if you don’t want it. [‘lastupdated’] probably makes sense on the server side, but for me on the client side, [‘lastupdated’] is making my life harder.
My message was a bit long, but I feel like I’m constantly checking that a message contains the key [‘lastupdated’] and deleting it, just because time is passing…