is there no way of accessing standard python modules within a macro? For example time, timestamp, or math?
Unfortunately not. There are some clever things you can do in jinja2 with the “undocumented” native attributes of the python objects that jinja employs, but at least with Klipper’s implementation of it, you can’t simply import python modules.
There’s a pretty good discussion of the issue here, specifically related to time.
And the lack of the math module does create limitations. Depending on your needs in that regard, you might have to see what’s possible within the basic arithmetic supported by jinja. I’m sure it’s not the best example but I was recently working on a macro where I needed to calculate a square root and was disappointed to learn that we don’t have something like a
root operand or filter. Then I remembered (somehow) from high school that you can also get a number’s square root by raising the number to the 1/2 power, and we can do that in jinja2 with the
** operand. So depending on your needs, there could be some ugly math hacks you could use to get where you need to be with the limited toolset available.