This template does not trigger when it changes from False to True

I have created this template in Developer Templates and I can see the calculated value are correct and see the status change from (False,) to (True,) in Developer Templates but it does not trigger in the automation. Can someone correct my code to make it work?

Thanks

alias: Water heater element 2 on
description: Turn on water heater element 2 if there is excess solar power
trigger:
  - platform: template
    value_template: >-
      {% set pvinverter_power =
      (states('sensor.victron_pvinverter_power_total_32','')) | float * -1000 |
      float %}
     {% set solarcharger_total =
      states('sensor.victron_solarcharger_yield_power_226') | float +
      states('sensor.victron_solarcharger_yield_power_100') | float %}
     {{ pvinverter_power | float > solarcharger_total | float, }} 

Remove the comma after the last float filter.

The comma is not needed and the float options in your last line are redundant
Try changing the last line to

{{ pvinverter_power > solarcharger_total }}

Edit: @123 was faster.

You also have an unnecessary blank second argument to states() in the above, and 1000 doesn’t need the float. Where has this code come from?

Here’s the cleaned-up trigger:

trigger:
  - platform: template
    value_template: >-
      {% set pvinverter_power   = states('sensor.victron_pvinverter_power_total_32')|float(0) * -1000 %}
      {% set solarcharger_total = states('sensor.victron_solarcharger_yield_power_226')|float(0)
                                + states('sensor.victron_solarcharger_yield_power_100')|float(0) %}
      {{ pvinverter_power > solarcharger_total }} 
1 Like

Thanks very much.

It’s my first attempt at code!!!

2 Likes