Help with variable tariff's depending on month and kWh usage

Hello,

My utility provider has a couple conditionals at which we are billed on per month, but I am at a complete loss on the YAML side given those extra complexities.

If anyone could help walk me through how to create sensor(s?) for the varying tariff conditions outlined below, I’ll do my best keep up.

Assumptions:

  • Ignore Basic Service fee/charge
  • Four conditions for energy rate
    • Summer (June through Sept) or Winter (October through May)?
    • kWh consumption amount per month
      • <1000kWh or >1000kWh

Attached is the thought (ignore all the syntax errors at the moment!)

- id: "Summer Electric Tariff"
  alias: "Summer Electric Tariff"
  description: ''
  condition:
    - condition: template
      value_template: "{{ now().month in [6,7,8,9] }}"
  action:
    - service: i.dont.know?
      target:
        entity_id: create.number_helper_here?
  mode: single

Hi, you can do this fairly easy with one or more template sensors.
I assume you are using the energy dashboard and you have allready a sensor tracking your energy consumption?

Something like this should do it, depending on which consumption sensor you allready have.

template:
  - sensor:
      - name: "Electricity_price"
        unit_of_measurement: "$/kWh"
        state: >
          {% if now().month < 6 or now().month > 9 %}
            {% if states('sensor.monthly_consumption')|float < 1000  %}
              0.08044
            {% else %}
              0.04536
            {% endif %}
          {% else %}
            0.10575
          {% endif %}

@assembly - thank you for the template sensor layout. That is exactly what I was hoping to accomplish!

The only thing I need to accomplish is a monthly aggregation sensor that takes the energy sensor I defined here:

mqtt:
  sensor:
    - name: "Electric Meter"
      state_topic: "rtl_433/1b53430861e2/devices/ERT-SCM/55877039/consumption_data"
      device_class: energy
      state_class: total_increasing
      unique_id: electric_meter
      unit_of_measurement: 'Wh'

Fortunately, it looks like the utility meter docs cover that pretty comprehensively (I’ll just have to simplify the state to reference my one entity named sensor.electric_meter).

template:
  - sensor:
    - name: 'Daily Energy Total'
      device_class: energy
      unit_of_measurement: kWh
      state: >
        {% if is_number(states('sensor.daily_energy_offpeak')) and is_number(states('sensor.daily_energy_peak')) %}
          {{ states('sensor.daily_energy_offpeak') | float + states('sensor.daily_energy_peak') | float }}
        {% else %}
          None
        {% endif %}

    - name: 'Monthly Energy Total'
      device_class: energy
      unit_of_measurement: kWh
      state: >
        {% if is_number(states('sensor.monthly_energy_offpeak')) and is_number(states('sensor.monthly_energy_peak')) %}
          {{ states('sensor.monthly_energy_offpeak') | float + states('sensor.monthly_energy_peak') | float }}
        {% else %}
          None
        {% endif %}

Thanks again!

Here is what my configuration.yaml looks like

utility_meter:
  daily_energy:
    source: sensor.electric_meter
    name: Daily Energy
    cycle: daily
#    tariffs:
#      - peak
#      - offpeak
  monthly_energy:
    source: sensor.electric_meter
    name: Monthly Energy
    cycle: monthly
#    tariffs:
#      - peak
#      - offpeak

Any my templates.yaml

- sensor:
    - name: "Electricity_price"
      unit_of_measurement: "$/kWh"
      state: >
        {% if now().month < 6 or now().month > 9 %}
          {% if states('sensor.monthly_energy')|float < 1000  %}
            0.08044
          {% else %}
            0.04536
          {% endif %}
        {% else %}
          0.10575
        {% endif %}

I’ll let it run for a few hours and see how things go. Thanks again :slight_smile:

It’s tracking cost in the Energy dashboard from the sensor you helped with in templates.yaml, but I think in the utility_meter section, I need to retain the “tariffs” section mentioned in the docs. In the docs, it’s not really clear to me how to have that respect the sensor.electricity_price.

Here is the YAML from the docs, for reference of what I’m talking about:

Assuming your energy provider tariffs are time based according to:

    peak: from 9h00 to 21h00
    offpeak: from 21h00 to 9h00 next day

a time based automation can be used:
automation:
  trigger:
    - platform: time
      at: "09:00:00"
      variables:
        tariff: "peak"
    - platform: time
      at: "21:00:00"
      variables:
        tariff: "offpeak"
  action:
    - service: select.select_option
      target:
        entity_id: select.daily_energy
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.monthly_energy
      data:
        option: "{{ tariff }}"

The reason I’m suspicious of the napkin math in my head is that the Energy dashboard has my 5kWh used as equating to $331.xx

Would you have any insight into how to configure my daily_energy/monthly_energy sensors?

What values do you have for monthly_energy and electricity_price?

You don’t need any tariffs, however you do need to make sure the id of the utility meter matches the id referenced in the template sensor (which isn’t the case in your code).

I would make sure all values are calculated correctly before adding them to the energy dashboard. It’s hard to correct erroneous values later on.

Also, are you sure the threshold of 1000kWh is per month and not per year? 1000kWh per month seems like very very much.

Hi there, apologies for the delay, but thank you for your persistence. I will revisit the id of the utility meter against he template sensor like you mentioned.

I’d really like to iron this out to track my electric consumption. We are a family of 6 in a 5 bed/5 bath home, so our utilities are quite high.

Here is my daily_energy and monthly_energy.

And an example from the utility company of last month’s usage:

As I mentioned, I’m pulling in my meter’s 900mHz signal via rtl_433 & MQTT. It is a Wh meter. When I was first tracking usage, my recordings were all over the place with the Wh/kWh conversion. For example, hourly usage was in the hundreds of kWh on the Energy dashboard. Wrong or right, I went into the database and manually set this and am getting more reasonable (although I’m not sure if they’re correct, of about 0.25-0.3 kWh):

Where I’m suspicious is, I have the mqtt sensor defined as Wh, but I wasn’t sure if that needed to be defined in the database, too? Or, should I have left the database value definition as kWh?

Ok. Seems like your units of measurement are off.
If your meter reports in Wh I wouldn’t artificially change that to kWh.
Instead it’s probably best to create a template sensor which converts Wh to kWh by dividing with 1000.