Template sensor: how to write to log (to debug specific&rare situations)

And another approach suggested here using the syslog integration: