Configuring a trigger-based template sensor

I have configured a trigger-baser template sensor in my configure.yaml. It is working as intended, but I would like to make some enhancements and don’t know how to go about it.

  1. Is it possible to associate this sensor with a device? It can be done when a template sensor is created from the Helpers GUI, but I haven’t been able to find a yaml example.

  2. Is it possible to specify an entity_category for this sensor? I switched to yaml from the Helpers GUI because I would like to specify an entity_category of “diagnostic” for this sensor and that doesn’t seem to be possible from the GUI.