Why is my condition template not evaulating to true?

My condition keeps returning False but I don’t understand why:

if:
  - condition: template
    value_template: >-
      "{{ states('sensor.solar_pv_output_over_last_5_minutes') | float(0) >
      states('input_number.solar_peak_5_minute_output_today') | float(0) }}"

the values look like this:

when I try the template in the developer tools it works:

{{ states('sensor.solar_pv_output_over_last_5_minutes') | float(0) }}
{{ states('input_number.solar_peak_5_minute_output_today') | float(0) }}

{{ states('sensor.solar_pv_output_over_last_5_minutes') | float(0) >
      states('input_number.solar_peak_5_minute_output_today') | float(0) }}

the above output gives:

1790.84
55.5

True

Any idea’s please, thanks!!

because you’re using multiline notation and single line notation together.

Use quotes around your template, and remove the >- and put the template on the same line as value_template.

Or use the >- for multiline yaml notation and remove the quotes around the template.

2 Likes

Oh my Lord, spent ages looking at this trying to figure it out :rofl:

Thanks

One other quick question, if I try and use this template in the trigger part of the automation it does not fire, why is that? (I use the disabled state trigger instead)

alias: Solar - 5 minute peak output today
description: Records the peak 5 minute continuous PV output today and the associated time
trigger:
  - platform: state
    entity_id:
      - sensor.solar_pv_output_over_last_5_minutes
    enabled: false
  - platform: template
    value_template: >-
      {{ states('sensor.solar_pv_output_over_last_5_minutes') | float(0) >
      states('input_number.solar_peak_5_minute_output_today') | float(0) }}

EDIT: Never mind, it seems to have started working now

It will only trigger if the template resolves true after resolving false. That means sensor.solar_pv_output_over_last_5_minutes has to be less than input_number.solar_peak_5_minute_output_today for an extended period before that trigger will fire.

1 Like

Isn’t the first trigger useless anyway (despite it being disabled)? The template trigger already covers a state change of “sensor.solar_pv_output_over_last_5_minutes” . Or doesn’t it? :slight_smile:

I’m assuming they are testing things out.

1 Like