How to handle variable electric rates with an entity

I’m trying to figure out how to use an entity to provide the current cost per kWh. My electric provider has a list of rates that change by the amount of electric consumed and the time of year.

The summer rate (June through September) is 11.81 cents / kWh.
The winter rate (October through May) has two tiers:

  • First 750 kWh - 8.04 cents / kWh
  • Over 750 kWh - 5.38 cents / kWh

It appears that there are a few parts to this puzzle.

  • Tracking the time of the year:
    • If summer time, use a flat rate
    • If in winter time:
      • know when a billing cycle starts and ends. Use that information to reset a kWh counter.
      • use the counter to vary the rate based on the amount consumed in a billing cycle.

I think I could figure this out with a bunch of different entities and helpers, but its going to be hacky and unreliable. Do you guys have any suggestions?

Thank you

1 Like

You can use-

And a couple of automation triggers (based on month) to change the tariff when the season changes.

Holy cow you’re fast. I’ll dig into this now.

Did you ever figure out how to do the first 1000kwh and over 1000kwh in your tariff? Our rate is the same year round, but after 1000kwh it goes up.

1 Like

Hey looks like you are using Ameren MO for electric? Can you share your code, I use Ameren and cannot get this thing to work for me…

Ameren MO Residental Rates for April 1, 2020

I’m sorry, this is an extremely late reply. I did not find an easy solution to this.

I went with a custom node red automation and a couple of helpers. This works and has been reliable, but its pretty “hacky”. I use two helpers and three automations. One of the helpers stores the current tariff value and the other acts as a kWh counter to determine when I’m over/under 750 kWh.

At 11:59:59 PM every night, one automation looks at the daily kWh usage and adds it to the counter.
There is another automation that triggers on the 13th of the month to reset the kWh counter.

The last automation is a glorified if / then statement. First, is it summer or winter? If summer, set the current tariff helper to the summer value. If its winter, look at the kWh counter. If over 750 kWh, set the tariff helper to that value. If under 750 kWh, set that tariff helper to that value.

I think I can pull this off using something that looks like this.

    name: sensor.electric_meter_daily_cost
    unit_of_measurement: "$"
    value_template: >-
      {% if as_timestamp(now()) | date("%m") in ["06", "07", "08", "09"] %}
        {{ (states.sensor.electric_meter_daily_usage.state * 0.1296) + 9 }}
      {% else %}
        {% if states.sensor.electric_meter_daily_usage.state <= 750 %}
          {{ (states.sensor.electric_meter_daily_usage.state * 0.0881) + 9 }}
        {% else %}
          {{ (750 * 0.0881) + ((states.sensor.electric_meter_daily_usage.state - 750) * 0.0591) + 9 }}
        {% endif %}
      {% endif %}

I want it to estimate my electric bill, however the meter reading dates for 2023 occur on these dates below.
1/31/2023, 3/1/2023, 3/30/2023, 4/28/2023, 5/30/2023, 6/28/2023, 7/28/2023, 8/28/2023, 9/27/2023, 10/26/2023, 11/28/2023.

I am using utility_meter to reset the counter for the hourly, daily, and monthly usages and costs.

Code is not finished yet but soon. The + 9 is represented by the monthly “Customer Charge” which I need to devide by the amount of days still or not include it except for the month or not at all since it’s only $9 LOL

1 Like

That being said, your billing group may differ for a number of factors. To find your billing group, locate your bill and look at the "Electric Service from mm/dd/yyyyy to mm/dd/yyyy and line that up with what Ameren provides on their website.

We do a similar thing here except the rates doesnt change during the year. But, there are three tiers during the month. Should I be referencing the monthly_usage for this?

I have Ameren:

This is what the rates say

You’ll pay a discounted rate on the energy you use between 9 p.m. and 9 a.m.
And you’ll be charged a slightly higher rate between the hours of 9 a.m. to 9 p.m.

For: Winter: October through May: All rates are per kWh

1st 750 kWh on-peak: 8.92¢ (9 a.m. to 9 p.m. Sun-Sat)
Over 750 kWh on-peak: 6.03¢ (9 a.m. to 9 p.m. Sun-Sat)

1st 750 kWh off-peak: 8.67¢ (9 p.m. to 9 a.m. Sun-Sat)
Over 750 kWh off-peak: 5.78¢ (9 p.m. to 9 a.m. Sun-Sat)

Summer: June through September: All rates are per kWh
On-peak 12.88¢ (9 a.m. to 9 p.m. Sun-Sat)
Off-peak 12.63¢ (9 p.m. to 9 a.m. Sun-Sat)

There are other ways to do this just showing what I did.

Find the part on your bill that has your rates this is your cost per kWh
you just want the rates you might need to look at a number of bills to get your summer and winter rates.

on your bill you will have a few rates:
all you want is the cost per Kwh

Summer Total Energy Charge: 0.12630000
Winter Elec Energy Chg 0-750: 0.08670000
Winter Elec Energy Chg >750: 0.05780000
On-Pk Energy Adjustment: 0.00258332

Customer Charges:
Fuel Adjustment Charge: 0.00623631
Energy Efficiency Investment Charge: 0.00366500
Renewable Energy Adjustment: 0.00035000

Now we need helpers:
I put numbers on my helpers to keep them sorted in the order I want.

Make input helpers with 6 dec places.

These are your input sensors, you can change them so the are not hard-coded.

Ameren010 Summer Total Energy Charge
Ameren020 Winter Elec Energy Chg 0-750
Ameren030 Winter Elec Energy Chg > 750
Ameren040 On-Pk Energy Adjustment
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Now for some math combine your imput sensors:
add a new helpers that combine the state of several sensors using SUM

Ameren210 Winter peak
Sum
Ameren020 Winter Elec Energy Chg 0-750
Ameren040 On-Pk Energy Adjustment
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Ameren220 Winter non-peak
Sum
Ameren020 Winter Elec Energy Chg 0-750
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Ameren230 Winter peak > 750
Sum
Ameren020 Winter Elec Energy Chg 0-750
Ameren030 Winter Elec Energy Chg >750
Ameren040 On-Pk Energy Adjustment
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Ameren240 Winter non-peak > 750
Ameren020 Winter Elec Energy Chg 0-750
Ameren030 Winter Elec Energy Chg >750
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Ameren310 Summer peak
Ameren010 Summer Total Energy Charge
Ameren040 On-Pk Energy Adjustment
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Ameren320 Summer non-peak
Ameren010 Summer Total Energy Charge
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Ameren330 Summer peak > 750
Ameren010 Summer Total Energy Charge
Ameren040 On-Pk Energy Adjustment
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Ameren340 Summer non-peak > 750
Ameren010 Summer Total Energy Charge
Ameren050 Fuel Adjustment Charge
Ameren060 Energy Efficiency Investment Charge
Ameren070 Renewable Energy Adjustment

Ameren710 Peak start
9:00 AM

Ameren720 peak end
9:00 PM

*Create a utility sensor that resets each month
using the sensor reading the total energy from Ameren and reset each month
you need this to check if the KWH used is greater that 750

I put a “s” at the end of Month, but I was to lazy to redo my code to remove the “s” as I would have had to delete the utility meter sensor. the sensor needs to start on the first of the month to track usage so if you get it wrong will need to wait for a new billing cycle to start over.

Ameren Energy Used this Months

Now for your YAML code
The sensor: ameren810_current kwh_rate
will have your current cost per kWh

I used a lot of if/elif to make coding simple, and made it a sensor so no automation or scripts.

  - sensor:
    - name: "Ameren810 Current kWh Rate"
      unique_id: ameren810_current kwh_rate
      unit_of_measurement: "USD/kWh"
      state: >
          {% set n1 = now() %}
          {% set n2 = (now().month) %}
          {% set summer = [ 11, 12, 1, 2, 3, 4, 5] %}
          {% set winter = [ 6, 7, 8, 9] %}


          {% if ((n2 in summer))
             and (states('sensor.ameren_energy_used_this_months')) | int > 750
             and today_at( states('input_datetime.ameren710_peak_start'))
                 < n1 < today_at( states('input_datetime.ameren720_peak_end')) 
            %}
              {{ float(states('sensor.ameren330_summer_peak_750')) }}



          {% elif ((n2 in summer))
             and (states('sensor.ameren_energy_used_this_months')) | int < 751
            %}
              {{ float(states('sensor.ameren310_summer_peak')) }}


          {% elif ((n2 in summer))
             and (states('sensor.ameren_energy_used_this_months')) | int > 750
            %}
              {{ float(states('sensor.ameren340_summer_non_peak_750')) }}
              

          {% elif ((n2 in summer))
             and (states('sensor.ameren_energy_used_this_months')) | int < 751
            %}
              {{ float(states('sensor.ameren320_summer_non_peak')) }}
              

          {% elif ((n2 in winter))
             and (states('sensor.ameren_energy_used_this_months')) | int > 750
             and today_at( states('input_datetime.ameren710_peak_start'))
                 < n1 < today_at( states('input_datetime.ameren720_peak_end')) 
            %}
              {{ float(states('sensor.ameren230_winter_peak_750')) }}
                            


          {% elif ((n2 in winter))
             and (states('sensor.ameren_energy_used_this_months')) | int < 751
            %}
              {{ float(states('sensor.ameren210_winter_peak')) }}
              
          
          {% elif ((n2 in winter))
             and (states('sensor.ameren_energy_used_this_months')) | int > 750
            %}
              {{ float(states('sensor.ameren240_winter_non_peak_750')) }}
              


          {% elif ((n2 in winter))
             and (states('sensor.ameren_energy_used_this_months')) | int < 751
            %}

               {{ float(states('sensor.ameren220_winter_non_peak')) }}
          {% endif %}

Now you can use the “Ameren810 Current kWh Rate” for any place you need current cost like.
go to setting > dashboards > energy
Under Electricity grid you can now edit you Grid Consumption sensor and check use an entity with
current price then use “Ameren810 Current kWh Rate”