I found out what to do by thinking - at a different time, when I was calm - about what was going on when I had them, what they represented to me. Not the content or a specific thing that triggered them, more like what were my emotions or subconscious doing? Then I'd come up with things that countered those.
I wonder if, when people say their grounding techniques don't work well, one reason might be that they aren't "their" grounding techniques. They're generic ones that aren't necessarily the best fit. They haven't really explored what the ungroundedness feels like or represents for them individually. For me, ungroundedness includes feeling like I've lost my present self and am falling into a past reality. For that reason, the most powerful things would be to remind myself of the date (which creates a clear difference between past and present), my name (also a clear difference - I changed my name) and where I live (also different now). What's weaker for me personally would be things like counting colours or touching things. It requires a bit of concentration/physicality but the colours/objects don't define past and present, so they don't reinforce anything to do with that.
For someone else it could be completely different. I'm not saying no-one should count colours or touch things. Only that what each person does needs to be the best fit for how they experience things.
Another example is that with flashbacks I felt helpless, vulnerable and alone. Again thinking about the feeling and how I could counter that, I decided I wanted some sort of talisman which had strong symbolism and good energy. My best friend helped me improvise a charm bracelet in a bead shop, finding beads to be symbols for things like healing, strength, connectedness etc. It has very strong meaning and resonance for me - including my friend's support which it always reminds me of - so it's more powerful against feeling helpless and alone than a regular bracelet would be.
Flashbacks used to make me feel under attack so I visualised being protected all the time.
And so on.
As far as remembering to do things goes, we have to practise a lot. Especially when it's not needed. The idea is to practise so much when you don't need it that it will be second nature when you do. Think Karate Kid. :)
More than that, it becomes your nature. You're more likely to stay grounded, present and psychologically safe if you practise grounding and safety frequently every day.