Energy Dashboard - Multiple Rate + standing daily charge

Hi

I am trying to configure the energy dashboard to correctly show my electricity charges. I have an economy 7 style tariff. I have tried to setup a template I copied from another post but I am getting errors.

template:
  # Home Energy sensors for HAEnergy
      - name: Octopus GO
        unit_of_measurement: GBP
        state: >
          {% set e7_normal = 0.3443 %}
          {% set e7_cheap = 0.0750 %}
          {% if states('sensor.time_utc') >= ('04:30' | timestamp_custom('%H:%M', False)) %}
          {{( e7_normal ) | float}}  {% else %}
          {% if states('sensor.time_utc') >= ('00:30' | timestamp_custom('%H:%M', False)) %}
          {{( e7_cheap ) | float}}  {% else %}
          {{( e7_normal ) | float}}  {% endif %} {% endif %}

I want to then add on the standing daily charge but not sure how to do this.
Any help would be greatly appreciated

From Time template troubles - #6 by 123

          {% set e7_normal = 0.3443 %}
          {% set e7_cheap = 0.0750 %}
          {% set t = (utcnow().time()|string)[:5] %}
          {% if t >= '04:30' %} {{ e7_normal }}
          {% elif t >= '00:30' %} {{e7_cheap }}
          {% else %} {{ e7_normal }}  
          {% endif %}

I am still getting errors unfortunately

Where your “# home energy” comment is you need to put - sensor so it will start like this

template:
  - sensor:
      - name: Octopus GO

ahh, thanks, yes, got it working now and it is pulling the correct price into the energy dashboard, so many thanks.

How would I go about adding in the standing charge? Do I create another sensor which is

usage * rate + standing charge

Not sure how this would iterate around though throughout the day

OK, so I think I have something working

Configuration.yaml
utility_meter:
  daily_energy:
    source: sensor.shelly_shem_3_c45bbe7998ad_1_total_consumption # adjust o your sensor name 
    cycle: daily
    tariffs:
      - peak
      - offpeak

sensors.yaml
  - platform: template
    sensors:
      total_electricity_spend:
        friendly_name: Electricity Cost
        unit_of_measurement: GBP
        icon_template: mdi:currency-gbp
        value_template: >-
          "{{ (states('sensor.daily_energy_peak') | float * 0.3443) | round(2) + (states('sensor.daily_energy_offpeak') | float * 0.075) | round(2)  + 0.4448 }}"


Automations.yaml
- id: '1655900283601'
  alias: Peak/OffPeak
  description: ''
  trigger:
  - platform: time
    at: 04:30:00
  - platform: time
    at: '00:30:00'
  condition: []
  action:
  - service: utility_meter.next_tariff
    data: {}
    target:
      entity_id: utility_meter.daily_energy
  mode: single

Yes at a quick glance you are on the right path.

Your original sensor simply displays the current price at that moment but you need to use the static values (or multiple static sensors) as you have done in your latest post to actually calculate the totals.

My tarrifs are far more complex so i have to set them specifically. i’ve not used the next tariff service myself as i needed to use the select tariff service. Check your tarrif is actually changing

yes, the tariff seems to change. When I setup a sensor manually it all seems to work. However if I try to input this into the energy dashboard as an entity tracking total cost I cannot select my sensor. I have tried rounding to 2 decimal places, but that doesnt fix it

add these to your total cost sensor

    state_class: total_increasing
    device_class: monetary

OK thanks. When I add these I get a config error

  - platform: template
    sensors:
      total_electricity_spend:
        friendly_name: Electricity Cost
        unit_of_measurement: GBP
        icon_template: mdi:currency-gbp
        state_class: total_increasing
        device_class: monetary
        value_template: >-
          "{{ ((states('sensor.daily_energy_peak') | float * 0.3443) | round(2) + (states('sensor.daily_energy_offpeak') | float * 0.075) | round(2) + 0.4448) | round(2) }}"

Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->total_electricity_spend->state_class. (See ?, line ?).

Hmmm. You’ve moved to the legacy template sensor config. Try the newer method again how you originally started. It may not work in sensors.yaml though so if there are issues just test it in configuration.yaml.

Moving something in config files won’t break it if you move it around down the track so nothing to fear there.

template:
  - sensor:
      - name: Octopus GO
        unit_of_measurement: GBP
        state_class: total_increasing
        device_class: monetary
        state: >
          {% set e7_normal = 0.3443 %}
          {% set e7_cheap = 0.0750 %}
          {% set t = (utcnow().time()|string)[:5] %}
          {% if t >= '04:30' %} {{ e7_normal }}
          {% elif t >= '00:30' %} {{e7_cheap }}
          {% else %} {{ e7_normal }}  
          {% endif %}

OK, so I have copied it into the main config and it is now selectable

template:
  - sensor:
      - name: Octopus GO Spend
        state_class: total_increasing # measurement 
        device_class: monetary
        unit_of_measurement: GBP
        icon: mdi:currency-gbp
        state: >
          "{{ ((states('sensor.daily_energy_peak') | float * 0.3443) | round(2) + (states('sensor.daily_energy_offpeak') | float * 0.075) | round(2) + 0.4448) | round(2) }}"

However now it gives me a different error
image

If I show on a different dashboard the variables they do display though

Thanks for all the help

One issue I see is the double quotes of the spend sensor are being passed as part of the state. Remove those from the start and end of the sensors state.

that seems to have sorted it :slight_smile: Many thanks