How to use a sensor for calculate my energy consumption costs?

Hi there, I have been reading a lot here in the forums and the official docs for Template and Templating but still not get this working.

I am trying to calculate the costs of my current energy usage at home. To get the values I have installed and configured the AMR2MQTT addon.

First, these are the charges as per my monthly bill:

Then this is what my sensor code looks like:

template:
  - sensor:
      - name: "Electricity Price"
        unit_of_measurement: "$"
        state: >
          {% set consumption = states('sensor.energy_meter_consumption') | float(0) %}
          {% if consumption < 1000 %}
            {% set factor=0.10489 %}
          {% else %}
            {% set factor=0.10714 %}
          {% endif %}
          
          {{ consumption * factor + 0.055 }}

However, if try to use the sensor from the Grid Consumption I cannot find it anywhere:

I tried to setup the Utility Meter helper to track the costs but is not clear to me how to set the tariff properly so it uses 0.10489 if consumption < 1000 or 0.10489 if it is above.

Can I get some help? What I am missing here?

I think you need to give the sensor a unique_id:

Here’s a sample of my price sensor to change the price based upon time of day (we get cheap electricity overnight but more expensive during the day).

template
  - sensor:
      - name: Electricity Buy Unit Price
        unique_id: electricity_buy_unit_price
        unit_of_measurement: GBP/kWh
        state: >
          {% if now().hour >= 0 and now().hour < 7 %}
            0.12276
          {% else %}
            0.47827
          {% endif %}

You should then be able to reference it as sensor.<unique_id>

I find it easier to check using the Developer Tools and States tab to see if the sensor is showing and check it’s names etc.

1 Like

Going back to your original issue with tracking the cost using different rates when you go over 1000 kWh in a month. I think you are on the right track with the utility meter approach.

If you look at the Utility Meter Documentation there is an example about mid-way which tracks two tariffs, one for peak, the other for off peak. You should be able to follow this principle, perhaps changing the labels to standard (for the first 1000) and excess (for anything above). You can then create an automation to change the tariff to the excess when the monthly utility meter value exceeds 1000. This would be instead of the time of day automation in the example.

You will I suspect need another automation on the cycle of the utility meter to set the tariff back to the standard tariff.

For the energy dashboard, I’m not sure exactly how that would work, but I’m thinking you would choose the “Use An Entity Tracking The Total Costs” option?