Hi!
I have a template sensor, which is calculating a difference between setpoints and real values. Its working, how i want it. My problem is, i would like to implement this calculation inside a script, but i cant figure it out.
I tried to read docs here and on jinja site. But i didnt find anything helpful.
Is it possible to make something like this inside a script:
Possibly itâs that you put the âround(0)â in the output which effectively turns it into an integer instead of a float?
Or I donât know if it makes any difference or not but try changing âdata_templateâ to just âdataâ. âdata_templateâ was deprecated a long time ago. But I think it should still be OK tho.
Otherwise, maybe the climate.set_temperature service doesnât support templating in the temperature field?
It doesnât look like thereâs anything wrong in the template that I can see. Especially if the same template works and shows the correct result in a template sensor. But the sensor wonât care about a float or int result either.
I also donât know why you get a different error without the quotes as mentioned above. It shouldnât need them as far as I know.
Sh*t.
I copied the bad calculation into the template. I need to decrease the setpoint with result from this. And i tried to pass the bad value to the ACâŚ
Thanks for the idea, how can i test my scripts!
This is the final format which is accepted by the AC unit:
An entityâs state value is always a string, even when itâs numeric. Therefore the float filter, or int filter, is needed to convert it to a number. However, you should supply the filter with a default value. Because if the value supplied to float is non-numeric, it will produce an error message. If a non-numeric value is supplied to float(0) it will use 0 as the default (you can set the default to whatever you want).
An entityâs attribute can contain a value that is a number, list, dictionary, string, etc. In this case, the temperature and current_temperature are numbers so thereâs no need to use the float filter.
If you add a line continuation character after an entityâs option, it means the template starts on the next line and may span multiple lines. In that case, you should not wrap the template in any quotes. Here are examples of line continuation characters: > >- |
The variable named new_setpoint contains a number so thereâs no need to use the float filter before applying the round filter.
The modern way of identifying a service callâs entity is by using the target option. All else is under the data option. The data_template option was deprecated a long time ago and now data also accepts templates.