Mathematic template sensor w If/Else

Dont quite know how to format the syntax for this template (brackets/curly brackets) so Id appreciate any help

I have two sensors - one binary and the other is numeric. I want to subtract a value of 6000 if a binary sensor (sensor.chiller_power_on_off) is ‘on’ from a numeric power sensor called (sensor.plant_power_consumption) to give me a numeric value for a third numeric sensor (plant_alert_power)

  - platform: template
    sensors:
      plant_alert_power:
        value_template: >-
          {% if states('binary_sensor.chiller_power_on_off') == 'on' %}
            {% states('sensor.plant_power_consumption') | float - 6000 %}
          {% else %}
            {% states('sensor.plant_power_consumption') | float %}
          {% endif %}

Im absolutely terrible at Jinja formatting and the dev tools panel really doesnt help w if/else/endif for a value template (works gloriously for binary sensors)

Just cant seem to get it working correctly

Thanks Jinja HA community… =)

Try like this, please don’t ask me why, total noob when it comes to templates, but it works.

          {% if states('binary_sensor.chiller_power_on_off') == 'on' %}
            {{ states('sensor.plant_power_consumption') | float - 6000 }}
          {% else %}
            {{ states('sensor.plant_power_consumption') | float }}
          {% endif %}
- platform: template
    sensors:
      plant_alert_power:
        value_template: >-
          {% set p = states('sensor.plant_power_consumption') | float(0) %}
          {{ p - 6000 if is_state('binary_sensor.chiller_power_on_off', 'on') else p }}