lazloman
(Lorenzo THurman)
June 16, 2021, 2:28am
1
Here is my yaml. The template editor and the UI both display a float instead of an integer. Why is this?
{%- if (is_state('light.desk_lamp_dimmer', 'on')) -%}
{{ state_attr('light.desk_lamp_dimmer', 'brightness') | int
/ 255 * 100 | int }}{{'%' }}
{% else %}
{%- endif %}
I’ve also tried piping through round(0), round(1), round(0, “floor”) in place of the final pipe through int, but always a float like this:
56.470588235294116%
tom_l
June 16, 2021, 2:32am
2
lazloman:
100 | int
Because you are converting the number 100 to an integer. Put some brackets around the whole expression.
{% if (is_state('light.desk_lamp_dimmer', 'on')) %}
{{ ( state_attr('light.desk_lamp_dimmer', 'brightness') | int
/ 255 * 100 ) | int }} {{ '%' }}
{% else %}
{% endif %}
1 Like
lucazeta
(Luca Zeta)
March 2, 2022, 3:57pm
4
Hi all!
I have the same problem but something is not working for me… can u help me?
myscript:
variables:
az_min: 10
az_max: 55
az_tot: "{{ ( cos ( az_min + az_max ) * 100 ) | int }}" # I need an integer number
sequence:
- service: notify.persistent_notification
data:
message: "COS of the sum is {{ az_tot }}"
I continuously obtain -56.2453851238172
petro
(Petro)
March 2, 2022, 4:02pm
5
Nothing is wrong with your code. Tested and working on my end. Are you sure you reloaded the script after making the changes?
1 Like
lucazeta
(Luca Zeta)
March 2, 2022, 4:06pm
6
It worked. After a full server restart.
Thank you
petro
(Petro)
March 2, 2022, 4:07pm
7
You just need to reload scripts, you don’t have to do a full restart