MQTT packet length problem

I am receiving a packet that contains this:

2022-12-06 08:52:39, Duration: 3:37:08, Estimated Fuel: 7.07 L, 2022-12-06 08:37:44, Duration: 0:04:47, Estimated Fuel: 0.09 L, 2022-12-02 14:53:06, Duration: 0:02:26, Estimated Fuel: 0.59 L, 2022-12-02 14:52:43, Duration: 0:00:11, Estimated Fuel: 0.45 L, 2022-12-02 14:51:26, Duration: 0:00:11, Estimated Fuel: 0.39 L, 2022-12-02 14:50:07, Duration: 0:00:10, Estimated Fuel: 0.35 L, 2022-12-02 12:35:46, Duration: 2:13:05, Estimated Fuel: 0.60 L, 2022-11-24 05:52:26, Duration: 0:04:20, Estimated Fuel: 0.11 L

When I publish the same packet in the Mosquito MQTT config and listen on the same topic, the packet is shown as received.

However, my MQTT sensor ignores it and only changes if I publish a packet that is less than 252 characters, which the sensor’s state then shows correctly in Dev tools.

To be a bit clearer:

  • If I publish “hello” for example, the sensor works fine.
  • If I publish the first 252 characters of the packet above, it also works fine.
  • If I publish the first 253 characters of the packet above, the sensor state doesn’t change to the new packet.

My sensor is:

  - unique_id: "7797ec3c-e1c5-4e10-ba9d-f8f15d27a019"
    expire_after: 300
    name: Generator Outage Log
    state_topic: "generator/generator/Outage/Outage_Log"

Using dev tools to set the state gives the same problem.

It seems that there is a 255 character limit for the sensor ( probably miscounted the 252!)

The packet represents 8 events and I need to parse the most recent and then extract the data.

How can I get around this?

Use an attribute instead of the state. Attributes can contain more than 255 characters.

Ha!

I was just reading your same post in another thread.

That sounds like a solution. but I don’t yet know how to do that. Could you please point me in the right direction?

I’ve tried this:

  - unique_id: "7797ec3c-e1c5-4e10-ba9d-f8f15d27a019"
    expire_after: 300
    name: Generator Outage Log
    state_topic: "generator/generator/Outage/Outage_Log"
    json_attributes_topic: "generator/generator/Outage/Outage_Log"
    json_attributes_template: "{{ value_json | tojson }}"

but I don’t think the packet/payload is json formatted so needs parsing another way.

I figured that using a value_template and several sensors to extract the data I want might be the way to go:

  - unique_id: "7797ec3c-e1c5-4e10-ba9d-f8f15d27a019"
    expire_after: 300
    name: Generator Outage Log
    state_topic: "generator/generator/Outage/Outage_Log"
    value_template: "{{ states(value)[50:] | trim}}"

However, this just returns an empty state.