This has been bugging me for a while, so I’m finally biting the bullet and asking. How can I create a function in HA that can be used in an automation, script, etc so I don’t have to constantly write the same code over and over?
Let’s say I want to write my own function to convert a temperature value in C to F. In Python that would like:
def CelsiusToFahrenheit(c):
f = (x * 9 / 5) + 32
return f
Now I want to use that in a automation, like:
{% x = CelsiusToFahrenheit(0) %}
I assume there is a way to actually expose and consume a python function, but that’s not what I’m going for. I would like to use templates to implement the simple (x * 9 / 5) + 32
without having to use Python at all.