Is there a way to create a file as a trigger

As stated. pyscript won’t let you.

AppDaemon is a little overcomplex for this simple task

python_scripts does very little.

So before I spend even more time on this:

Is there a way to create a single file when I flip a switch for example? Via a python script.

I guess that you’re looking for something more complex than

shell_command: 
  create_file: mypython.py

And call it as an automation based on your switch …

switch:
  - platform: command_line
    switches:
      file_making_switch:
        command_on: touch my_file
        command_off: rm my_file

A file only exists when this switch is on. Does that work?

Or do you have an existing switch you want to make files? In that case shell command works fine as shown above. Don’t really need python, touch <filename> works fine.

Pyscript works very well for this. I’m creating a file in one of my automations like this:

import aiofile

@state_trigger("entity_id == 'switch.switch'")
async def create_file():

    output = "file content"

    async with aiofiles.open('/config/file.txt', mode='w') as f:
        await f.write(output)