Last updated on August 31, 2024
I wanted to implement a sensor to tell me what the current price per kW is for any time of day.
My rate plan is Home Charging EV2-A and needs to account for the season and several hour-of-day checks to select the correct price. So here is the template sensor I’ve created:
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 |
sensor: - platform: template sensors: pge_ev2a_energy_rate: # UPDATED MARCH 2024 friendly_name: PGE EV2-A Energy Rate unit_of_measurement: '$/kWh' value_template: > {% set rate = { "winterPeak": 0.53117, "winterPartialPeak": 0.51447, "winterOffPeak": 0.34578, "summerPeak": 0.65828, "summerPartialPeak": 0.54779, "summerOffPeak": 0.34578 } %} {% set time = { "month": (now().strftime('%m') | int), "hour": (now().strftime('%H') | int) } %} {%if ((time.month >= 10) or (time.month < 6)) %} {%if (time.hour >= 15) and (time.hour < 16) %} {{ rate.winterPartialPeak }} {%elif (time.hour >= 16) and (time.hour < 21) %} {{ rate.winterPeak }} {%elif (time.hour >= 21) and (time.hour < 24) %} {{ rate.winterPartialPeak }} {%else%} {{ rate.winterOffPeak }} {%endif%} {%else%} {%if (time.hour >= 15) and (time.hour < 16) %} {{ rate.summerPartialPeak }} {%elif (time.hour >= 16) and (time.hour < 21) %} {{ rate.summerPeak }} {%elif (time.hour >= 21) and (time.hour < 24) %} {{ rate.summerPartialPeak }} {%else%} {{ rate.summerOffPeak }} {%endif%} {%endif%} |
Credit to this post for the bones of the sensor logic.
Be First to Comment