Need help with creating template for climate sensor

I am switching from openhab to homeassistant and I am facing issues to make my MQTT devices work.

THe problem is that if the mqtt topic “home/EMSHeizungCat/boiler_data” is under {{ value_json.burnGas }} ON then I want that the climate is in status HEAT and if not in status OFF

Can somebody please help me? I searched here but found no where that I need to extract first the status and then evaluate it.

  climate: # https://www.home-assistant.io/integrations/generic_thermostat/
#            https://www.home-assistant.io/integrations/#search/mqtt
  - name: "Heizung Temperatur"
    unique_id: Heizung_Thermostat
    current_temperature_topic: "home/EMSHeizungCat/thermostat_data"
    current_temperature_template: '{{ value_json.thermostat_seltemp }}'
    temperature_command_topic: "home/EMSHeizungCat/thermostat_cmd_temp"
    temperature_state_topic:   "home/EMSHeizungCat/thermostat_data"
    temperature_state_template: '{{ value_json.thermostat_seltemp }}'
    max_temp: 25
    min_temp: 15
    modes:
      - "off"
      - "heat"
    availability_topic: "home/EMSHeizungCat/status"
    retain: true
    mode_state_topic: "home/EMSHeizungCat/boiler_data"
    mode_state_template:  > 
      var x = {{ value_json.burnGas }}; 
        {% if (x === "on") %}
          heat
        {% else %}
          off
        {% endif %}

Assuming lowercase on/off/heat (it’s important: do check what it really is):

    mode_state_template:  "{{ 'heat' if value_json.burnGas == 'on' else 'off' }}"

No Javascript === or semicolons in Jinja templates.

Many thanks for that fast help Troon! And thanks for the Jinja template remark, I was on the complete wrong path.

I could thanks to your feedback fix it as follows:

  climate: # https://www.home-assistant.io/integrations/generic_thermostat/
#            https://www.home-assistant.io/integrations/#search/mqtt
  - name: "Heizung Temperatur"
    unique_id: Heizung_Thermostat
    current_temperature_topic: "home/EMSHeizungCat/thermostat_data"
    current_temperature_template: '{{ value_json.thermostat_seltemp }}'
    temperature_command_topic: "home/EMSHeizungCat/thermostat_cmd_temp"
    temperature_state_topic:   "home/EMSHeizungCat/thermostat_data"
    temperature_state_template: '{{ value_json.thermostat_seltemp }}'
    max_temp: 25
    min_temp: 15
    modes:
      - "off"
      - "heat"
    availability_topic: "home/EMSHeizungCat/status"
    retain: true
    mode_state_topic: "home/EMSHeizungCat/boiler_data"
    mode_state_template: >
        {% if value_json.burnGas  == "on" %}
        heat
        {% else %}
        off
        {% endif %}