Current energy cost in Energy dashboard

Hi folks,

I’m trying to implement a mechanism, so that the sensors in the Energy Dashboard use the current energy price.
From roaming through the forums here, I found the following configuration snippet:

  - platform: template
    sensors:
      current_electricity_rate:
        friendly_name: Current Electricity Rate
        value_template: >-
          {% set t = strptime(states('sensor.time'), '%H:%M') %}
          {%- if t.hour >=6 and t.hour <22 -%}0.2648
          {%- else -%}0.2124
          {%- endif -%}
        unit_of_measurement: €/kWh

Unfortunately, when I try to use this newly created sensor in the energy dashboard, I get the following error message:
image

I’m fairly new to Home Assistant, so bear with me :slight_smile:
Any help here is appreciated!

Further information:
I tried to see what this virtual (?) sensor is actually returning.
It seems it doesnt return anything at all.
When I add a card to my dashboard to show the entity “Current Electricity Rate” it shows as “unavailable”.
Sorry I can’t add a screenshot here because of being a new user.

What part am I missing here?

You can only add entities (sensors) that provide energy (i.e. Wh or kWh) to the energy dashboard.

You can provide tariffs to the utility meter and perhaps visualise some of that data with your own charts. If you add a state class to a sensor, you’ll get long-term stats.

The error comes when I added the Current Electricity Rate as “Use an entity with the current price” option on a grid consumption entry

Nevertheless, my tariffs change base upon time of day.
So for example, from 6-22h, the energy cost is higher than from 22-6h.
The energy dashboard needs to take this into account somehow.

I hope that makes the issue a bit more clear :slight_smile:

Right, I see. Unfortunately, I’m not familiar with that part of the functionality (in my country we only have a flat rate). Perhaps someone else can chime in, but I think my previous point still holds: Create a utility meter and I think you can then select that in the dialogue. See Frequently Asked Questions about home energy management.

If you add | float to your sensor it should be ok