What you arrived at should work everywhere, so I’m not following what more you’re looking for. Other options are .get("foo bar") or |attribute("foo bar"), and should be equivalent to ["foo bar"] as a way to index using a string, including one that has spaces or special characters in it.
There is a decluttering template which has an input variable - "SENSOR".
The decluttering template includes displaying a "last-changed" value for the "SENSOR" - in the manner that needs using things like (example for "sun.sun"):
I mean that I cannot just specify something like "secondary_info: last-changed", I have to form it by myself since that "last-changed" value must be displayed in some special place.
3. So I need a method to form that "states.sun.sun.last_changed" expression - not just for "sun.sun" but for any "SENSOR" (which could be of any domain).