Energy Tariff Entity

How can I create an entity that will provide the new energy feature with my current electricity tariff.
I am using Octopus Go that has a peak rate of 13p/kwh & an off peak rate of 5p/kwh. The rate changes at 00:30 & 04:30 every day.

thanks in advance . . .

You can create a template sensor like this

sensor:
  - platform: template
    sensors:
      your_tarif:
        friendly_name: My Tarif
        unit_of_measurement: CHF
        value_template: >
          {% set tariff = { "HT": 22.1, "LT": 15.1 } %}
          {% if (now().weekday() < 5 and (7 <= now().hour <= 20)) or (now().weekday() == 5 and (7 <= now().hour <= 13)) %}
            {{ tariff.HT }}
          {% else %}
            {{ tariff.LT }}
          {% endif %}
4 Likes

Modified the above to do the correct times (0:30 - 4:30) and unit (GBP/kWh) to use in the energy tab.

- platform: template
    sensors:
      octopus_go:
        friendly_name: Octopus Go
        unit_of_measurement: GBP/kWh
        value_template: >
          {% set tariff = { "HT": 0.1559, "LT": 0.05 } %}
          {% if ((30 <= (now().hour * 100) + now().minute <= 430)) %}
            {{ tariff.LT }}
          {% else %}
            {{ tariff.HT }}
          {% endif %}
4 Likes

Hey All,

I have used pretty much this code to give me a entity with pricing for my tariff (Night and Day) and it works great, however I need to update / change or add some functionality, and this is where I am not succeeding (despite trying for some time)… I would also say I am a beginner here :smiley:

So basically during DST our cheap energy is 23:00 - 06:00 and outside of DST (so winter) it’s 00:00 - 07:00, I’ve set up another binary sensor which updates daily with DST = On / Off (True / False) and I was hoping to do some clever nested IF statement, but I can’t get the syntax right, and I am at the end of my expertise, anyone have any ideas? Or even if there is a simple way to already do it :smiley:

I hope I can join this conversation.
I have a dashboard page showing current W being used and total kwh used.
I am just using simple entity cards.
What I want to do now is add an entity card showing the total cost of the kWh.
I presume I would have to create a couple of calculations in yaml to make this entity and I’m not sure how to do this.
Here is a picture of the dashboard. The 3rd column on the grid card would be the total kwh cost.
I have only 1 set tariff from my energy provider.
Thanks in advance

Hi
can you show me how to modify this code for tarif thats different from 01.01 to 30.06 and 1.07 to 31.12 ?

thank you.

Many thanks for this input. I adapted it to our tarif schedule (a city in Switzerland) and extended it for the return tarif for our PV energy.

How could this be adapted with the annual tarif changes? I.e. we had a significant increase of the tarif starting form January 1 2023?
Best would be to have a kind ao matrix to reflect the (annual) tarif changes.

I got it to work. I inserted this in my configuration.yaml:

template:
  - sensor:
      - name: "Strompreis"
        unit_of_measurement: "CHF/kWh"
        state: >
          {% set tariff = { "HT1": 0.2366, "LT1": 0.1935 } %}
          {% if (now().weekday() < 5 and (7 <= now().hour <= 20)) or (now().weekday() == 5 and (7 <= now().hour <= 7)) %}
            {{ tariff.HT }}
          {% else %}
            {{ tariff.LT }}
          {% endif %}

but this works also:

  - platform: template
    sensors:
      your_tarif:
        friendly_name: My Tarif
        unit_of_measurement: CHF/kWh
        value_template: >
          {% set tariff = { "HT": 0.2366, "LT": 0.1935 } %}
          {% if (now().weekday() < 5 and (7 <= now().hour <= 20)) or (now().weekday() == 5 and (7 <= now().hour <= 7)) %}
            {{ tariff.HT }}
          {% else %}
            {{ tariff.LT }}
          {% endif %}

anyone know what is the difference?

Use utcnow() rather than now(). GMT without the DST. Like

state: {{‘Day’ if today_at(‘08:00’) < utcnow() < today_at(‘23:00’) else ‘Night’ }}