High low fixed price levels - jonasbkarlsson/ev_smart_charging GitHub Wiki

If the electriticty price has two different fixed price levels depending time of day and weekday, the followin template sensor can be used.

In the example below, the low price is 0.25 and the high price is 0.31. The low price applies to Monday to Friday between 07:00 and 23:00.

template:
  - trigger:
      - trigger: homeassistant
        event: start
      - platform: time_pattern
        # Update once per hour
        minutes: 0
    sensor:
      - name: "My price sensor"
        state: "No value shown"
        unique_id: my_price_sensor
        attributes:
          prices: >
            {# 0=Monday, 1=Tuesday, 2=Wednesday...       #}
            {% set low_tariff_weekdays = [0, 1, 2, 3, 4] %}

            {# Exampel: range(7,23) give low price between 07:00 and 23:00. #}
            {% set low_tariff_hours    = range(7,23)                        %}

            {% set low_tariff_price    = 0.25            %}
            {% set high_tariff_price   = 0.31            %}

            {% set time_now = now() %}
            {% set day_of_week = time_now.weekday() %}
            {% set prices = namespace(data=[]) %}
            {% for hour in range(0, 24) %}
              {% set price = low_tariff_price if day_of_week in low_tariff_weekdays and hour in low_tariff_hours else high_tariff_price %}
              {% set price_time = time_now.replace(hour=hour, minute=0, second=0, microsecond=0).isoformat() %}
              {% set prices.data = prices.data + [{'time': price_time, 'price': price}] %}
            {% endfor %}
            {% set time_tomorrow = now() + timedelta(days=1) %}
            {% set day_of_week = time_tomorrow.weekday() %}
            {% for hour in range(0, 24) %}
              {% set price = low_tariff_price if day_of_week in low_tariff_weekdays and hour in low_tariff_hours else high_tariff_price %}
              {% set price_time = time_tomorrow.replace(hour=hour, minute=0, second=0, microsecond=0).isoformat() %}
              {% set prices.data = prices.data + [{'time': price_time, 'price': price}] %}
            {% endfor %}
            {{ prices.data}}