Energy consumption - price tracking template / helper

New to Home Assistant, any help is greatly appreciated. Below is my local energy rates and peak hour schedules from the providers website. Any chance someone could help me define this in a Template?

  • Demand Charge: $3.15/kW during peak hours
    • Peak hours occur Monday through Friday from 7 to 10 a.m. and 5 to 8 p.m. There are no demand charges on weekends or major federal holidays, including New Year’s Day, Memorial Day, Independence Day, Labor Day, Thanksgiving, and Christmas. In the event that the holiday occurs on Sunday, there are no demand charges on the following Monday.
  • Energy Charge:
    • $0.0552 per kWh (for the first 600 kWh per month)
    • $0.0660 per kWh (for 601-3,500 kWh per month)
    • $0.1002 per kWh (for 3,501 and over kWh per month)
    • Basic Charge (single-phase service): $24.31 per month (not sure how to include this)

This is where I am so far, but I don’t know enough about this and I think the formatting, and possibly variables are off. Also interested in finding a way to define holidays without having to manually update the dates.

if		date =['2024-11-28', '2024-12-25', '2025-01-01', '2025-05-26', '2025-07-04', '2025-09-01', '2025-11-27', '2025-12-25']
		total <601
			price =0.0552
		or total >=601
		and total <=3500
			price =0.0660
		or total <3501
			price 0.1002
elseif 	now().weekday >=0
		and now().weekday <5
		and now().hour >=7
		and now().hour <10
			price=3.15
elseif 	now().weekday >=0
		and now().weekday <5
		and now().hour >=17
		and now().hour <20
			price=3.15
else 	total <601
			price =0.0552
		or total >=601
		and total <=3500
			price =0.0660
		or total <3501
			price 0.1002

Credit to hilburn on Discord -

The solution was to create a calendar to track the holidays, a scheudle helper to track the peak hours, and the below template sensor helper to define the rates. We were going to use the Holidays calendar integration, but it tracks holidays that do not apply and we are not aware of a way to modify the contents, so a static calendar was created and must be maintained manually.

{% if states('calendar.major_federal_holidays') == 'on' or states('schedule.flathead_electric_peak') == 'off' %}
  {% set monthly = states('sensor.solaredge_imported_energy') | float (0) %}
  {% if monthly < 601000 %}
    0.0000552
  {% elif monthly < 3501000 %}
    0.0000660
  {% else %}
    0.0001002
  {% endif %}
{% else %}
  0.0031500
{% endif %}