The variable trigger has no value in the Template editor, unless you assign one to it.
You can use Trigger IDs to simplify your automation, and you need to place the entity ID under target or data (this is the source of the Message malformed error):
FWIW, ChatGPT and other LLM are particularly bad at Home Assistant. They hallucinate answers the majority of the time. And their hallucinations are often plausible-looking, making them difficult to identify without significant HA experience.
Another tip for using templates in automations – use the UI to create the action first using placeholder values before going back to add the templates. This makes sure you get the structure of the YAML correct and would have avoided the error of not having entity_id under target in this case.