Need help creating a string for text-to-speech based on entity states

In a nutshell, I have a “Goodnight” script that turns off lights and stuff. What I would also like it to do is have my google home mini respond back if doors are left open. For example, if the garage door was left open it could say “Garage door is open, please close it.” If the back door and garage door were left open it would say “Garage door is open, please close it. Back door is open, please close it.” The idea is that I could concatenate parts of the status report based on the state of entities. I have been having a really hard time though figuring out how to create a string variable in a script to allow for that concatenation in essentially a bunch of if statements for state checks. Any help would be appreciated.

Here is some pseudo code of what I am trying to do:

variable: textToSay = ""
if cover.garage_door == open
textToSay += "Close the garage door. "
if binary_sensor.back_door == open
textToSay += "Close the back door. "
if textToSay == ""
textToSay == "All clear."

The Jinja2 template will be something like this:

{% set textToSay = '' %}
{% if is_state('cover.garage_door', 'open') %}
  {% set textToSay = textToSay ~ 'Close the garage door. ' %}
{% endif %}
{% if is_state('binary_sensor.back_door', 'on') %}
  {% set textToSay = textToSay ~ 'Close the back door. ' %}
{% endif %}
{{ textToSay if textToSay | length > 0 else 'All clear.' }}

If you have many doors, there is a way to simply way to list all open doors within a single sentence.

The only added complexity for your application is that one of the doors is a cover as opposed to a binary_sensor.

Thanks Taras! This was very very helpful! Sometimes good example is all that is needed. Your example of putting it into a markdown card was great because its easy to test with! I modified it a bit more to add on an additional message about the pool pump.

  alias: Status report
    - service: tts.google_translate_say
          - media_player.den_speaker
          - media_player.family_room_speaker
        message: >-
          {% set doors = expand('binary_sensor.garage_sensor_105_2','binary_sensor.garage_sensor_105_3')
          | selectattr('state', 'eq', 'on')
          | map(attribute='name') | list %}
          {% set qty = doors | count %}
          {% set p1 = 'are' if qty > 1 else 'is' %}

          {% set textToSay = '' %}
          {% if qty > 0 %} 
            {% set textToSay = ' and '.join((doors | join(', ')).rsplit(', ', 1)) + p1 + 'open. ' %}
          {% endif %}
          {% if is_state('switch.z_wave_pool_pump_switch','on') %}
            {% set textToSay = textToSay + 'Pool pump is on.' %}
          {% endif %}
          {{ textToSay if textToSay | length > 0 else 'All clear.' }}