Automation for Peak/Off-Peak Tariffs

Hi there
Im an absolutely newbie on HomeAssistant, i set up my Shelly 3EM in Home Assistant, and it works great.

I created a Utility-Meter in helpers for my energy-consumption. I set two tariffs (Peak and Off-Peak).

Now i want to create a automation for the drop down selecter.

The times of „peak“ ar following:

Mo-Fri: 07:00AM till 08:00PM
Saturday: 07:00AM till 01:00PM

„Off-Peak“ times are:
Mo-Fri: 08:00PM till 07:00AM
Saturday: 01:00PM till Monday 07:00AM

I have absolutely no idea how to create a „switching“ automation…

Her is my configuration.yaml:


# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

template:
  - sensor:
      - name: "Total Power Consumption"
        unit_of_measurement: "W"
        device_class: power
        state: >
          {{ [ states('sensor.l1_power'), 
               states('sensor.l2_power'),states('sensor.l3_power') ]
               | map('float') | sum }}
        availability: >
          {{ not 'unavailable' in 
             [ states('sensor.l1_power'), 
               states('sensor.l2_power'),
               states('sensor.l3_power')] }}

  - sensor:
      - name: "Total Energy Consumption"
        unit_of_measurement: "kWh"
        device_class: energy
        state: >
          {{ [ states('sensor.l1_energy'), 
               states('sensor.l2_energy'),states('sensor.l3_energy') ]
               | map('float') | sum }}
        availability: >
          {{ not 'unavailable' in 
             [ states('sensor.l1_energy'), 
               states('sensor.l2_energy'),
               states('sensor.l3_energy')] }}

If someone can help me, it would be awesome :sunglasses:

I recently tried to create in helpers a schedule for peak and off-peak, but i can’t find a way to use this calendar-schedule for switching between my two tariffs🙈

Examples are already available. Please have a look at the following post from search:
https://community.home-assistant.io/search?q=peak%20offpeak%20tarrifs

1 Like

Thank you @Janneman

Now i try to understand the yaml coding… it`s so difficult for me.
Learning by doing :rofl:

If I shouldn’t be able to do it, do you know if there is someone who would do the yaml coding for me ?
So I actually only have to do copy-paste.

What would something like that cost?

So i tried the following automation:


#####AUTOMATION#########################################
- alias: Change Utility Tariffs to offpeak on Weekends
  trigger:
  - platform: time
    at: '20:00:00'
  condition:
  - condition: time
    weekday:
    - sat
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id:
      - utility_meter.total_energy_consumption
      tariff: offpeak

#####AUTOMATION#########################################
- alias: Change Utility Tariffs to peak on Weekdays
  trigger:
  - platform: time
    at: '07:00:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id:
      - utility_meter.total_energy_consumption
      tariff: peak

#####AUTOMATION#########################################
- alias: Change Utility Tariffs to offpeak on Weekdays
  trigger:
  - platform: time
    at: '20:00:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id:
      - utility_meter.total_energy_consumption
      tariff: offpeak

But the automation doesn’t work. This morning i finally got this error message from my HA

Where are the issues? I just changed the entity_id but the issue must be in the service…

please see the below topic for your answer. (I guess)

So i tried different things in the automation. But HA doesn’t change the tariffs… in the log I see that the automation is running but when i try the command in the devloper-tools, every time i get the same fault message… (screenshot)

Im at my work now, thats why i post screenshots from my mobile.



Did you write your automation in YAML or by using the GUI? I am not a pro in YAML, but my automation looks very much different from yours. It has been created within the GUI and looks like this:
(when creating automations in the GUI, there is an option within the top-right-menu to see the YAML itself)

alias: Hochtarif/Niedertarif setzen
description: >-
  Diese Automation verwendet eine Zeitsteuerung, um den gültigen Tarif für den
  Stromzähler Utility Meter zu setzen.
trigger:
  - platform: time
    at: "07:00:00"
  - platform: time
    at: "13:00:00"
  - platform: time
    at: "20:00:00"
condition: []
action:
  - choose:
      - conditions:
          - condition: time
            after: "07:00:00"
            before: "20:00:00"
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
        sequence:
          - service: select.select_option
            data:
              option: Hochtarif
            target:
              entity_id: select.stromzahler_utility_meter
      - conditions:
          - condition: time
            after: "07:00:00"
            before: "13:00:00"
            weekday:
              - sat
        sequence:
          - service: select.select_option
            data:
              option: Hochtarif
            target:
              entity_id: select.stromzahler_utility_meter
    default:
      - service: select.select_option
        data:
          option: Niedertarif
        target:
          entity_id: select.stromzahler_utility_meter
mode: single


EDIT: okay, when looking at the …/config/automations.yaml, the structure is the same as yours. Main difference is, that I created 1 automation, not 5. Perhaps, your automations interfere with each user in an unexpected way?


EDIT2: in my …/config/automations.yaml all automations start with an id. in our screenshots, the id’s are missing.
Here is the same automation out of my automations.yaml:

- id: '1651527795676'
  alias: Hochtarif/Niedertarif setzen
  description: Diese Automation verwendet eine Zeitsteuerung, um den gültigen Tarif
    für den Stromzähler Utility Meter zu setzen.
  trigger:
  - platform: time
    at: 07:00:00
  - platform: time
    at: '13:00:00'
  - platform: time
    at: '20:00:00'
  condition: []
  action:
  - choose:
    - conditions:
      - condition: time
        after: 07:00:00
        before: '20:00:00'
        weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
      sequence:
      - service: select.select_option
        data:
          option: Hochtarif
        target:
          entity_id: select.stromzahler_utility_meter
    - conditions:
      - condition: time
        after: 07:00:00
        before: '13:00:00'
        weekday:
        - sat
      sequence:
      - service: select.select_option
        data:
          option: Hochtarif
        target:
          entity_id: select.stromzahler_utility_meter
    default:
    - service: select.select_option
      data:
        option: Niedertarif
      target:
        entity_id: select.stromzahler_utility_meter
  mode: single


EDIT3:


EDIT4:
one last warning: when changing automations, you need to relead them in order to take effect. go to:

  1. Developer Tools → YAML → Configuration validation → Check configuration
  2. Developer Tools → YAML → YAML configuration reloading → automations


EDIT5:
The latest update of HomeAssistant makes changes to the automation UI. check it out, might be relevant regarding the automation id’s.