Utility meter with automation for tariff change

Hello
I have implemented the bellow utility meters

  daily_energy_serverroom:
    source: sensor.efergy_789069
    cycle: daily
  monthly_energy_serverroom:
    source: sensor.efergy_789069
    cycle: monthly
  daily_energy_home:
    source: sensor.efergy_788325
    cycle: daily
  monthly_energy_home:
    source: sensor.efergy_788325
    cycle: monthly

I want to change tariff on different time between differnet periods of the year.
So I want from 1 May to 31 October the changes to happen on 23:00 and on 07:00 and from 1 November to 30 April changes to happen on 02:00 , 08:00 , 15:30 and 17:30

I have created automation

automation:
trigger:
    - platform: time
      at: "07:00:00"
    - platform: time
      at: "23:00:00"
  action:
    - service: utility_meter.next_tariff
      target:
        entity_id: utility_meter.daily_energy_serverroom
    - service: utility_meter.next_tariff
      target:
        entity_id: utility_meter.monthly_energy_serverroom
    - service: utility_meter.next_tariff
      target:
        entity_id: utility_meter.daily_energy_home
    - service: utility_meter.next_tariff
      target:
        entity_id: utility_meter.monthly_energy_home

how could I add and the above logic according to date?

thank you

You haven’t configured any tariffs.
e.g.

  daily_energy_serverroom:
    source: sensor.efergy_789069
    cycle: daily
    tariffs:
      - peak
      - offpeak

Only once you have done that can you use the next.tariff service.

For being conditional on dates, see this example:

condition:
  - condition: template # Only between December 1 and January 6.
    value_template: >
      {% set n = now() %}
      {{ n.month == 12 or ( n.month == 1 and ( 1 <= n.day <= 5 )) }}

I think I did it
From 1/5 to 31/10 and from 23:00 to 07:00 should be offpeak
From 1/11 to 30/4 and from 02:00 to 08:00 and 15:30 to 17:30 should also be offpeak
all other timeframe should be peak

Automations that I created

- id: '1622836530021'
  alias: Utility meter summer period (offpeak)
  description: Set night power for summer period
  trigger:
  - platform: time
    at: '23:01:00'
  condition:
  - condition: and
    conditions:
    - condition: time
      after: '23:00:00'
      before: 07:00:00
    - condition: template
      value_template: '{% set n = now() %} {{ n.month >= 5 or n.month < 11 }}'
  action:
  - service: utility_meter.select_tariff
    target:
      entity_id: utility_meter.daily_energy_serverroom
    data:
      tariff: offpeak
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id: utility_meter.monthly_energy_serverroom
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id: utility_meter.daily_energy_home
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id: utility_meter.monthly_energy_home
  mode: single
- id: UtilitySummerPeak
  alias: Utility meter summer period (peak)
  description: Set day power for summer period
  trigger:
  - platform: time
    at: 07:01:00
  condition:
  - condition: and
    conditions:
    - condition: time
      after: 07:00:00
      before: '23:00:00'
    - condition: template
      value_template: '{% set n = now() %} {{ n.month >= 5 or n.month < 11 }}'
  action:
  - service: utility_meter.select_tariff
    target:
      entity_id: utility_meter.daily_energy_serverroom
    data:
      tariff: peak
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id: utility_meter.monthly_energy_serverroom
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id: utility_meter.daily_energy_home
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id: utility_meter.monthly_energy_home
  mode: single
- id: UtilityWinterPeak1
  alias: Utility meter winter period (peak)
  description: Set day power for winter period
  trigger:
  - platform: time
    at: 08:01:00
  - platform: time
    at: '17:31:00'
  condition:
  - condition: and
    conditions:
    - condition: or
      conditions:
      - condition: time
        after: 08:00:00
        before: '15:30:00'
      - condition: time
        after: '17:30:00'
        before: 02:00:00
    - condition: template
      value_template: '{% set n = now() %} {{ n.month >= 11 or n.month < 5 }}'
  action:
  - service: utility_meter.select_tariff
    target:
      entity_id: utility_meter.daily_energy_serverroom
    data:
      tariff: peak
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id: utility_meter.monthly_energy_serverroom
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id: utility_meter.daily_energy_home
  - service: utility_meter.select_tariff
    data:
      tariff: peak
    target:
      entity_id: utility_meter.monthly_energy_home
  mode: single
- id: UtilityWinterOffpeak1
  alias: Utility meter winter period (offpeak)
  description: Set nightpower for winter period
  trigger:
  - platform: time
    at: 02:01:00
  - platform: time
    at: '15:31:00'
  condition:
  - condition: and
    conditions:
    - condition: or
      conditions:
      - condition: time
        after: 02:00:00
        before: 08:00:00
      - condition: time
        after: '15:30:00'
        before: '17:30:00'
    - condition: template
      value_template: '{% set n = now() %} {{ n.month >= 11 or n.month < 5 }}'
  action:
  - service: utility_meter.select_tariff
    target:
      entity_id: utility_meter.daily_energy_serverroom
    data:
      tariff: offpeak
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id: utility_meter.monthly_energy_serverroom
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id: utility_meter.daily_energy_home
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id: utility_meter.monthly_energy_home
  mode: single

I’m at the same stage trying to configure the various peak/offpeak times in automation.

Does this look right?

You see I have only specified the start time for the next tariff assumed the 2nd automation will change the tariff from the From time

PEAK 7pm-11pm - weekdays only

- id: '1630809302390'
  alias: UTE Peak
  description: ''
  trigger:
  - platform: time
    at: '19:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  action:
  - service: utility_meter.next_tariff
    target:
      entity_id: utility_meter.daily_energy
  - service: utility_meter.next_tariff
    target:
      entity_id: utility_meter.monthly_energy
  mode: single

OFF PEAK weekdays and OFF PEAK all weekend.

 id: '1630809394572'
  alias: UTE Off Peak
  description: ''
  trigger:
  - platform: time
    at: '23:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  - condition: time
    weekday:
    - sat
    - sun
    after: 00:00
    before: '23:59'
  action:
  - service: utility_meter.next_tariff
    target:
      entity_id: utility_meter.daily_energy
  - service: utility_meter.next_tariff
    target:
      entity_id: utility_meter.monthly_energy
  mode: single

Many thanks

I’m confused and stuck.

Attributes still says collecting for a peak time when the automation I think should be running off peak now at 3pm. Only after 7pm - 11pm should be ‘collecting’ for peak.

image

Changed next tariff to select tariff:
Lets see if this works

- id: '1630809302390'
  alias: UTE Peak
  description: ''
  trigger:
  - platform: time
    at: '19:00'
  - platform: time
    at: '23:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
    after: '19:00'
    before: '23:00'
  action:
  - service: utility_meter.select_tariff
    target:
      entity_id:
      - utility_meter.monthly_energy
      - utility_meter.daily_energy
    data:
      tariff: peak
  mode: single
- id: '1630809394572'
  alias: UTE Off Peak
  description: ''
  trigger:
  - platform: time
    at: '23:00'
  - platform: time
    at: '19:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
    after: '23:00'
    before: '19:00'
  - condition: time
    weekday:
    - sat
    - sun
    after: 00:00
    before: '23:59'
  action:
  - service: utility_meter.select_tariff
    data:
      tariff: offpeak
    target:
      entity_id:
      - utility_meter.monthly_energy
      - utility_meter.daily_energy
  mode: single

Nope still collecting on ‘peak’ no matter what I put in offpeak

Got it!!
Had to add all of the entities into the call service automation for the different tariffs.

can you please explain how you got this to work. Call service?