I’ve already been plugging in data from my Emporia Vue, which reads the meter from Southern California Edison and allows me to query my usage in kW/h from Home Assistant. I now need to calculate cost, which is variable based on what SCE calls TOU (Time Of Use).

This essentially means peak hours (typically 4PM - 9PM) have higher rates than off-peak. I broke this problem down into 3 entities to solve:

I can use Cost as the dynamic entity in our Energy Usage dashboard. This, combined with the kW/h reading, can be used to calculate total energy costs per day.

This defines the 3 entities in my sce.yaml. If you’re copying this, plug your peak costs into the last few lines of this snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
template:
  - sensor:
    - name: "TOU Season"
      state: "{{ ['Winter', 'Summer'][now().month >= 6 and now().month < 10] }}"
      icon: mdi:weather-cloudy-clock
  - sensor:
    - name: "TOU Peak"
      icon: mdi:calendar-clock
      state: >
        {% set is_weekend = now().strftime("%w") == 0 or now().strftime("%w") == 6 %}

        {% if states('sensor.tou_season') == "Summer" %}
          {% if now().hour >= 16 and now().hour < 21 %}
            {% if is_weekend %}
              {{ "Mid-Peak" }}
            {% else %}
              {{ "On-Peak" }}
            {% endif %}
          {% else %}
            {{ "Off-Peak" }}
          {% endif %}
        {% else %}
          {% if now().hour >= 16 and now().hour < 21 %}
            {{ "Mid-Peak" }}
          {% elif now().hour >= 21 or now().hour < 8 %}
            {{ "Off-Peak" }}
          {% else %}
            {{ "Super Off-Peak" }}
          {% endif %}
        {% endif %}        
  - sensor:
    - name: "TOU Cost"
      icon: mdi:currency-usd
      device_class: monetary
      state: >
        {% if states('sensor.tou_season') == "Summer" %}
          {{ {"Off-Peak": 0.15, "On-Peak": 0.41, "Mid-Peak": 0.30}[states('sensor.tou_peak')] }}
        {% else %}
          {{ {"Super Off-Peak": 0.15, "Off-Peak": 0.15, "Mid-Peak": 0.38}[states('sensor.tou_peak')] }}
        {% endif %}