It looks like !secret (and !include for that matter) will only work in the frontend (UI) in YAML mode.
I have no experience with YAML mode, but this is what I read elsewhere:
Just cannot get !secret to work - Home Assistant Community (home-assistant.io)