Help with time and month automation

Hi all
I need to make an automation for my new utility meter tariffs. (until now I haven’t got peak-offpeak)
So here in Greece we have the following
Winter season:
1/11-30/4 : offpeak tarrif between 2:00-8:00 and 15:00-17:00
summer season:
1/5-31/10: offpeak tarrif between 23:00 - 7:00

I made the following 2 automation (1 for each season) I am sure that they could be more elegant, but this is what I manage. I am not sure if the times in Winter are ok. Can someone confirm please?

Winter = 1/11-30/4 : offpeak tarrif between 2:00-8:00 and 15:00-17:00

- id: Winter Deh Night Day 
  alias: Winter Deh Night Day 
  trigger:
    - platform: time
      at: "08:00:00"
      variables:
        tariff: "peak"
    - platform: time
      at: "15:00:00"
      variables:
        tariff: "offpeak"
    - platform: time
      at: "17:00:00"
      variables:
        tariff: "peak"
    - platform: time
      at: "02:00:00"
      variables:
        tariff: "offpeak"
  condition:
  - condition: template
    value_template: '{{ now().month >= 11 or now().month <= 04 }}'
  action:
    - service: select.select_option
      target:
        entity_id: select.daily_energy2
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.monthly_energy2
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.air_condtion_daily_energy2
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.air_condtion_monthly_energy2
      data:
        option: "{{ tariff }}"

Summer = 1/5-31/10: offpeak tarrif between 23:00 - 7:00

- id: Summer Deh Night Day 
  alias: Summer Deh Night Day 
  trigger:
    - platform: time
      at: "07:00:00"
      variables:
        tariff: "peak"
    - platform: time
      at: "23:00:00"
      variables:
        tariff: "offpeak"
  condition:
  - condition: template
    value_template: '{{ now().month >= 5 or now().month <= 10 }}'
  action:
    - service: select.select_option
      target:
        entity_id: select.daily_energy2
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.monthly_energy2
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.air_condtion_daily_energy2
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.air_condtion_monthly_energy2
      data:
        option: "{{ tariff }}"

I would probably make it a sensor instead of an automation.

You could if/else it to output peak or off peak, and then you could use that value in your automations/calculations.

Thanks but to be honest I don’t understand what you mean.
I followed the below. I am not sure how I could use the sensor. I thought that in order to declare the peak and the offpeak I need the automation

Utility Meter - Home Assistant (home-assistant.io)

automation:
  trigger:
    - platform: time
      at: "09:00:00"
      variables:
        tariff: "peak"
    - platform: time
      at: "21:00:00"
      variables:
        tariff: "offpeak"
  action:
    - service: select.select_option
      target:
        entity_id: select.daily_energy
      data:
        option: "{{ tariff }}"
    - service: select.select_option
      target:
        entity_id: select.monthly_energy
      data:
        option: "{{ tariff }}"

He means create a binary sensor like this one but with your times and months:

template:
  - binary_sensor:
      - name: "Peak Rate"
        icon: "mdi:power-plug"
        state: "{{ (now().weekday() < 5) and ( (6 < now().hour < 10) or (15 < now().hour < 21) ) }}"

Then you can automate like this:

- id: 841ae395-4646-4c95-8991-14cdd7e9c834
  alias: 'Set Peak or Off-peak Tariff'
  trigger:
  - platform: state
    entity_id: binary_sensor.peak_rate
  action:
  - service: select.select_option
    target:
      entity_id:
      - select.energy_upstairs_heat_pump_daily
      - select.energy_hot_water_daily
      - select.energy_from_grid_daily
    data:
      option: "{{ 'peak' if is_state('binary_sensor.peak_rate', 'on') else 'offpeak' }}"

Yes as Tom say a binary or just template sensor if that is preferred.

I can’t help today with it, but tomorrow or Sunday I can create the yaml for it.

@tom_l @Hellis81

thanks both of you.

Tom I see now what Hellis meant. I will try to understand the above and to implement it.
Hellis thanks for your offer. I will try it and I will give you a call in the weekend if I can’t manage it.

So, I found almost ready what I needed. I took the sensor from here, and changed toms automation and the sensors are working. At least for summer and for peak. I will see at night if it will change to offpeak.

However, there are now 2 sensors that I can not delete/remove although I have deleted them from the configuration file. No big deal, I think I will find a way to remove them at the end.

Thanks again

Hi,
Not trying to hijack, i’m replying to help people searching for similar solutions.
Living in Australia, we have some complex Time of use energy tariffs…

I’ve used the advice here to knock up the following which seems a little ‘clunky’ but seems to work
Is there any better way to do this?
(quite new to HA and YAML)

### https://www.energyaustralia.com.au/home/help-and-support/faqs/ausgridchanges for the TOU setup

### Summer Shoulder 7am-2pm & 8pm-10pm. Peak 2pm-8pm – 1st November to 31 March

### Winter Shoulder 7am-5pm & 9pm-10pm. Peak 5pm-9pm – 1st June to 31 August

### Others Shoulder 7am-10pm. April, May, September, October

### Off Peak always 10pm-7am

template:

 - binary_sensor:

    - name: "Shoulder Time"

      icon: "mdi:power-plug"

      state: "{{ (((now().month in [11,12,1,2,3])

      and (now().weekday() < 5)

      and (7 < now().hour < 14)

      or (20 < now().hour < 22))

      or ((now().month in [6,7,8])

      and (now().weekday() < 5)

      and ((7 < now().hour < 17)

      or (21 < now().hour < 22)))

      or (now().month in [4,5,9,10])

      and (7 < now().hour <22)) }}"

 - binary_sensor:

    - name: "Peak Time"

      icon: "mdi:power-plug"

      state: "{{ (((now().month in [11,12,1,2,3])

      and (now().weekday() < 5)

      and (14 < now().hour < 20))

      or ((now().month in [6,7,8])

      and (now().weekday() < 5)

      and (17 < now().hour < 21 ))) }}"

 - binary_sensor:

    - name: "Off Peak Time"

      icon: "mdi:power-plug"

      state: "{{ (( (now().weekday() < 5)

      and (22 < now().hour < 7))

      or ((now().weekday() > 5)

      and (22 < now().hour < 7))

      or ((now().month in [4,5,9,10])

      and (22 < now().hour < 7 ))) }}"

I’m using it currently to just show what energy rate is being charged in my dash, but will use it to figure out energy billing when i learn how.
I’ll tweak the dash to be a more elegant display once i figure that out

image

I had to add daylight savings adjustments to my template:

- name: "Peak Rate"
  icon: "mdi:power-plug"
  state: >
    {% if states('binary_sensor.is_dst')|bool(0) %}
      {{ (now().weekday() < 5) and ( (7 < now().hour < 11) or (16 < now().hour < 22) ) }}
    {% else %}
      {{ (now().weekday() < 5) and ( (6 < now().hour < 10) or (15 < now().hour < 21) ) }}
    {% endif %}

- name: "Is DST"
  state: "{{ now().timetuple().tm_isdst == 1 }}"

If it was not for this I would use a considerably simpler schedule helper that can be set from the UI.

1 Like