Template - create sensor with negative value

Hi,

I have question, I need to create Helper sensor which show value of entity and based on another entity value it make it positive or negative, in this case input value is current/power which is always positive number and second value is PowerFactor which is 0-99 or -99-0 (consumption/production).
I made this template but I always get a positive value at output not matter if PF above or below 0 (or I change >= to <=)

{{ states(‘sensor.0xd878f0fffeaffaa9_power_a’)|float(0) * iif(states(‘sensor.0xd878f0fffeaffaa9_power_factor_a’,float(0) >= 0), 1, -1) }}

Have anyone idea what I am doing wrong here ? I tried to modify it in many ways but still stuck in “true” and never get “false” in iif.

Thanks for any idea

/Tomi

Try this:

{{ states('sensor.0xd878f0fffeaffaa9_power_a')|float(0) *
  iif(states('sensor.0xd878f0fffeaffaa9_power_factor_a')|float(0) >= 0, 1, -1) }}

Ou, thank you so much, I spent few hours with searching for error and now I see where I made a mistake :slightly_smiling_face:

/Tomi