Is there any way to get the metadata_id from a trigger automation?

I am using trigger automations and want to print out the metadata_id of the sensor that corresponds to the entity_id that triggers the automation.

Is there any way to retrieve the metadata_id from the sensor that triggers the automation similar to how you can retrieve various attributes using trigger.to_state.attribute.xxxx

Note I want to do this so I can later run a SQL query on the metadata_id.