Tracking Energy Cost based on Usage per KwH

Hi All,

I’ve created a helper that links all of my multiple inputs so I have a total used, and based on that helper grouping my power sockets, I’ve then created a utility meter that resets every day. It has created two counters for my two energy tariffs.

I have 2 rates; The First Rate is collected for the first 2 kWh of electricity used per day. The Saver Rate applies for all remaining kWh of electricity used in the day.

What I’m wanting to do, is to have a price of consumption per day and/or month, that can be added to my normal lovelace dashboard, that is inclusive of both these tariffs.

I tried using the template below, but I keep getting errors so thought I’d reach out for some expert help.

The error I’m getting is;

Cannot quick reload all YAML configurations because the configuration is not valid: Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']. Got [{'name': 'Energy Price', 'unique_id': 'energy_price', 'icon': 'mdi:counter', 'state_class': 'total_increasing', 'device_class': 'energy', 'unit_of_measurement': '£/kWh', 'state': "{% set consumption=states('select.energy_consumed_today')|float(0) %} {{ 0.6054 if consumption > 2 else 0.2889 }}\n", 'availability': "{{ states('select.energy_consumed_today')|is_number }}"}]. (See ?, line ?).

The template I’m using which I’ve added into my configuration.yaml file is below;

  - platform: template
    sensors:
    - name: Energy Price
      unique_id: energy_price
      icon: mdi:counter
      state_class: total_increasing
      device_class: energy
      unit_of_measurement: "£/kWh"
      state: >
        {% set consumption=states('select.energy_consumed_today')|float(0) %}
        {{ 0.6054 if consumption > 2 else 0.2889 }}
      availability: "{{  states('select.energy_consumed_today')|is_number }}"

Please help me fix what I’ve broken, or get me to a working prototype/functioning entity that I can add to my dashboards :slight_smile: Thanks

EDIT: The two rates I have are: First Rate at 60.54p per KwH, then Saver Rate at 28.89p per KwH