Convert payload as string into JSON with seperate attr-key and in sync

Hi guys,

I’m wondering can I convert MQTT-payload, which is received/handled as a string, into a JSON-object And updating the sensor itself?
I don’t use HA for automations. My automations are handled by Node-RED. Now I have to add a JSON-node to convert string into json-object on Node-RED. It would be nice the ESPHome wall switches behave the same like my other zigbee devices.

The advantage I find off receiving payload as string is it will be in sync. An example of published payloads;

topic: home/test/esph_test/sensor/switch_test/state

{"action":"single"}
{"action":""}
{"action":"double"}
{"action":""}
{"action":"hold","count":1}
{"action":"hold","count":2}
{"action":"hold","count":3}
{"action":"hold","count":4}
{"action":"release","count":0}
{"action":""}

When I manually configure a sensor and move count-key to seperate json_attributes_topic the sensor will not show the count in HA’s Developer Tools. Then also the asynchronous handling of topics start to show up. Also HA will drop duplicate payloads. So continuous ‘action:hold’ events will become 1 event > not good. (continuous) messages with payload = hold will be configured as brightness increase of lights.

I want the sensor itself being updated into proper format. Is that possible?

Bump… Pretty please with a cherry on top!