Batch Reporting Device State via losantmqtt Python library fails

I have devices in the field which I would like to configure to do batch reporting, where they sample data and return an array of payloads. It seems as though this is a supported feature, as there is mention of it in the docs.

I’m mostly wondering if it’s possible to continue using the losantmqtt library in python for this, as it seems that reporting the device state only supports single payloads (at least with the send_state method).

Currently my state is reported something like this:

data = [{'data': {'ABC': 1}, 'time': '2024-03-27T17:46:58.380Z'}, {'data': {'ABC': 1}, 'time': '2024-03-27T17:47:01.392Z'}, {'data': {'ABC': 1}, 'time': '2024-03-27T17:47:05.408Z'}, {'data': {'ABC': 1}, 'time': '2024-03-27T17:47:09.429Z'}]
device.send_state(data)

Is there support for this that I am missing, or will I need to implement a lower level MQTT library to do this?

Hey @Logan_Parker,

You are correct that the send_state function is assuming a single state report. To send multiple states, you can access the underlying MQTT client directly and publish the array:

import json

device._mqtt_client.publish(device._state_topic(), json.dumps(data))
1 Like

Hey Brandon,

Thanks for that - I figured I was likely using the send_state function incorrectly. I appreciate the quick response!