How to call a Python script (and get data back) on demand?

I’ve set Blue Iris and Plate Recognizer up to pass any detected license plates of cars on my drive to Home Assistant via MQTT. I have a Python script which will call a restful API (restful sensor didn’t like the data format) and when called as a command line sensor, will set various car vehicle related attributes.

The problem with the command line sensor though is it’s constantly being called, and I just want to call this API when a new plate is posted via MQTT. I have an automation to act on a new plate appearing, but I have no idea how to call the script/API from the automation such that it gets data back into HA.

What’s the best way to go about this?

Run it with a shell_command and send the data to HA via mqtt within the script.

Or… keep the command_line sensor as it is, and just set a very large scan_interval, so that it doesn’t get called that often.

Afterwards, you can call it when needed with the homeassistant.update_entity service.

Thank you. I’d just started contemplating the shell command & MQTT option, but wasn’t aware of the update_entity possibility.