How to zero a sensor value when a boolean = false. Else, use equation

I have created a float sensor value called “Garage Boiler Heat Output” (in BTUs/hr) that bases its value off of another sensor value called “Modulation” (in %) using an equation.

How can I modify the equation so that “Garage Boiler Heat Output” equals zero if binary_sensor.flame is false, and uses the normal equation when it is true?

Background: 0% modulation = ~17k btu/hr when the boiler is actually running (monitored via binary_sensor.flame). If it is not running, 0% modulation = 0k btu/hr.

Thanks!

Forgot to post what I have tried:


template:
  - sensor:
    - name: "Garage Boiler Heat Output"
      unit_of_measurement: "BTU/Hr"
      state: >
        {% if is_state('binary_sensor.opentherm_flame', 'not running') %} 0
        {% elif ('binary_sensor.opentherm_flame', 'running') %}
          {{ ((((states('sensor.opentherm_modulation_level')|float(0)) * 430) + 17000)| round(2)) }}
        {% else %} 15
        {% endif %}

It seems to compile, and I have tried some different variants, but value stays at 17,000 when flame is off. (The else 15 was just to try to gain better understanding.)