Template outputting code as part of the string

I just wanted to add my code to this if its not too late. Please note I live in ontario so we have two differnet tariffs based on Summer or winter if you are subscribed to Time of Use billing. This is only for TOU

So I set some variabels liek is it the weekend or holiday or summer its all based on ours. Again just adding theis code here icanse any one else wants it!!

{% set is_holiday = is_state('calendar.canada_on', 'on') %} 
{% set is_weekend = now().isoweekday() in [0, 6] %}
{% set is_summer = now().month >= 5 and now().month < 11 %}

{% if is_holiday or is_weekend %}
  {{ "off-peak" }}
{% elif is_summer %}
  {% if now().hour in [0,1,2,3,4,5,6,19,20,21,22,23] %}
  {{ "off-peak" }}
  {% elif now().hour in [7,8,9,10,17,18] %}
  {{ "mid-peak" }}
  {% elif now().hour in [11,12,13,14,15,16] %}
  {{ "on-peak" }}
  {% endif %}
{% else %}
  {% if now().hour in [0,1,2,3,4,5,6,19,20,21,22,23] %}
  {{ "off-peak" }}
  {% elif now().hour in [7,8,9,10,17,18] %}
  {{ "on-peak" }}
  {% elif now().hour in [11,12,13,14,15,16] %}
  {{ "mid-peak" }}
  {% endif %}
{% endif %}

Also using your example above and some help from Discord server I was able to come up with this code which I like a lot better and is simple to change in the future!

{% set isHoliday = is_state('calendar.canada_on', 'on') %}
{% set isWeekend = now().isoweekday() > 5 %}
{% set isSummer = 4 < now().month < 11 %}
{% if isWeekend or isHoliday %}
  {% set lookup = 'OOOOOOOOOOOOOOOOOOOOOOOO' %}
{% elif isSummer %}
  {% set lookup = 'OOOOOOOMMMMPPPPPPMMOOOOO' %}
{% else %}
  {% set lookup = 'OOOOOOOPPPPMMMMMMPPOOOOO' %}
{% endif %}
{% set map = {'O': 'off-peak', 'M': 'mid-peak', 'P': 'on-peak'} %}
{{ map[lookup[now().hour]] }}