Scene flipping to became unknown with MQTT device

I’m trying to integrate some C# code into HA that I’ve written to tie my ANPR system in via MQTT. I’ve got the code to register a ‘tag device’ on MQTT (this seems to be working nicely) and I’ve set up the MQTT integration - this also seems to be ok. But when I try and create an automation e.g ‘XYZ’ - When an MQTT message has been received - the log shows ‘XYZ’ became unknown and then ‘XYZ’ turned on both in the same moment (sometimes the other way around) - I’m guessing they have the same timestamp.

But the thing is the automation doesn’t work, although I can trigger it manually.

Anybody got any clues? I’m not sure if its my discovery tags that are wrong or something else!

My discovery topic I’m publishing to MQTT looks like this:

(topic) “homeassistant/tag/ANPR/config”
(payload) {“topic”: “ANPR/tag_scanned”, “value_template”: {{ value_json.PN532.UID }} }"

and the message published is:

(topic) “ANPR/tag_scanned”
(payload) { “Time”:“2023-04-21Z15:31:31”,“PN532”:{“UID”:“25c9afc5-3a71-4206-8ed4-a7cb384f7377”, “DATA”:“CarRegHere”}}"