Energy Tariff Picture Card

I’m wondering if someone can help.

I have just set up some automations to show what electricity tariff is currently running based on time.

In Spain we now have 3 tariffs - Off Peak. Peak and Mid.

These run at different times of the day.

I wanted to show with a picture the current tariff using different images:

This is something probably quite straight forward to do but I’ve not managed it yet.

I have set some times in my config to use as a start but not sure if it will work.

  - platform: tod
    name: Offpeak 
    after: '00:00'
    before: '08:00'
  - platform: tod
    name: Mid AM
    after: '08:00'
    before: '10:00'
  - platform: tod
    name: Peak AM 
    after: '10:00'
    before: '14:00'
  - platform: tod
    name: Mid PM 
    after: '14:00'
    before: '18:00'
  - platform: tod
    name: Peak PM 
    after: '18:00'
    before: '22:00'
  - platform: tod
    name: Mid PM2
    after: '22:00'
    before: '00:00'

So I thought to use a Conditional Card but I can’t work it out. My theory is if Mid PM2 is currently ON it will show the relevant pie chart picture… that’s my thinking but maybe there is a better way?

Thanks in advance

The custom state switch card might be a better fit for your application:

Instead of a whole bunch of seperate tod sensors create one sensor with the states Offpeak , Mid AM, Peak AM, etc…

The using the state of that sensor use the state switch card to display the appropriate picture card.

The sensor (will update every minute):

template:
  - sensor:
      - name: "Tariff in Use"
        state: >
          {% set t_now = as_timestamp(now()) | timestamp_custom('%H:%M') %}
          {% if '00:00' <= t_now < '08:00' %}
            Offpeak
          {% elif '08:00' <= t_now < '10:00' %}
            Mid AM
          {% elif '10:00' <= t_now < '14:00' %}
            Peak AM
          {% elif '14:00' <= t_now < '18:00' %}
            Mid PM
          {% elif '18:00' <= t_now < '22:00' %}
            Peak PM
          {% elif '22:00' <= t_now < '00:00' %}
            Mid PM2
          {% endif %}

The state switch card:

type: custom:state-switch
entity: sensor.tariff_in_use
states:
  'Offpeak':
    type: picture
    imgae: your_offpeak_image.png
  'Mid AM':
    type: picture
    imgae: your_mid_am_image.png
  'Peak AM':
    type: picture
    imgae: your_peak_am_image.png
  'Mid PM':
    type: picture
    imgae: your_mid_pm_image.png
etc...

You can get fancy and use a transition when switching between cards if you like.

@tom_l again to the rescue!

Cool, I’ll give it a go :slight_smile:

How can I add to this code if it the weekend then it is se to off peak?

Like this:

template:
  - sensor:
      - name: "Tariff in Use"
        state: >
          {% set t_now = as_timestamp(now()) | timestamp_custom('%H:%M') %}
          {% if ('00:00' <= t_now < '08:00') or (now().isoweekday() > 5) %}
            Offpeak
          {% elif '08:00' <= t_now < '10:00' %}
            Mid AM
          {% elif '10:00' <= t_now < '14:00' %}
            Peak AM
          {% elif '14:00' <= t_now < '18:00' %}
            Mid PM
          {% elif '18:00' <= t_now < '22:00' %}
            Peak PM
          {% elif '22:00' <= t_now < '00:00' %}
            Mid PM2
          {% endif %}

Thank you. Works perfectly :slight_smile:

template:
  - sensor:
      - name: "Tariff in Use"
        state: >
          {% set t_now = as_timestamp(now()) | timestamp_custom('%H:%M') %}
          {% if ('00:00' <= t_now < '08:00')
            Offpeak
          {% elif '08:00' <= t_now < '10:00' %}
            Mid AM
          {% elif '10:00' <= t_now < '14:00' %}
            Peak AM
          {% elif '14:00' <= t_now < '18:00' %}
            Mid PM
          {% elif '18:00' <= t_now < '22:00' %}
            Peak PM
          {% elif '22:00' <= t_now < '00:00' %}
            Mid PM2
          {% elif (now().isoweekday() > 5) %}
            Off Peak WKND
          {% endif %}

type: 'custom:state-switch'
entity: sensor.tariff_in_use
states:
  Offpeak:
    type: picture
    image: \local\tariffs\offpeak.jpg
  Mid AM:
    type: picture
    image: \local\tariffs\mid_am.png
  Peak AM:
    type: picture
    image: \local\tariffs\peak_am.png
  Peak PM:
    type: picture
    image: \local\tariffs\peak_pm.png
  Mid PM:
    type: picture
    image: \local\tariffs\mid_pm.jpg
  Mid PM2:
    type: picture
    image: \local\tariffs\mid_pm1.jpg
  Off Peak WKND:
    type: picture
    image: \local\tariffs\off_peak_wknd.png

You need to move the weekend test in your sensor template to be the first if statement. Otherwise one of the time tests will be true first, even if it is the weekend.

        state: >
          {% set t_now = as_timestamp(now()) | timestamp_custom('%H:%M') %}
          {% if now().isoweekday() > 5 %}
            Off Peak WKND
          {% elif ('00:00' <= t_now < '08:00')
            Offpeak
          {% elif '08:00' <= t_now < '10:00' %}
            Mid AM
          {% elif '10:00' <= t_now < '14:00' %}
            Peak AM
          {% elif '14:00' <= t_now < '18:00' %}
            Mid PM
          {% elif '18:00' <= t_now < '22:00' %}
            Peak PM
          {% elif '22:00' <= t_now < '00:00' %}
            Mid PM2
          {% endif %}
1 Like

Yes you are right. It would pick up the time before the weekend :0

Thanks again

1 Like

I don’t know if you know, but there is a custom card for Spain Electricity Prices. Is different than what you want, but I want to tell just in case you don’t know it.

it displais a icon depending on the tarif.