Get the value of a sensor at a specific time

They 100% are, as are in-line if expressions.

Please note that sensors with defined unit_of_measurement must return a numeric state... the way the state is defined in your most recent example will never work.

To address the actual issue described in your first post... you may want to take a look at the custom integration, Measure It, which combines some of the features of History Stats, Utility Meter, and Template Sensors.

Or, if you don't actually need these values to exist statically, you could use the recorder.get_statistics action.