Utility meter condition based on time/day (3 tariffs weekday, 2 tariffs weekend)

In the docs for utility meter, it shows the following example:

utility_meter:
  daily_energy:
    source: sensor.energy
    cycle: daily
    tariffs:
      - peak
      - offpeak
  monthly_energy:
    source: sensor.energy
    cycle: monthly
    tariffs:
      - peak
      - offpeak

with the following automation to transition based on peak/offpeak:

automation:  
  trigger:
    - platform: time
      at: '09:00:00'
    - platform: time
      at: '21:00:00'
  action:
    - service: utility_meter.next_tariff
      entity_id: utility_meter.daily_energy
    - service: utility_meter.next_tariff
      entity_id: utility_meter.monthly_energy

I’m on a PG&E EV-A rate plan, which has 2 rates during the weekend, but 3 on the weekdays:

Weekdays:
Off-peak: 11pm-7am
Part-peak: 7AM-2PM & 9PM-11PM
PEAK: 2pm-9pm

Weekends:
Peak: 3pm-7pm
Off-peak: 7pm-3pm

For the weekends, I’ve got the following:

- alias: Change Utility Tariffs week
  trigger:
    - platform: time
      at: '15:00:00'
    - platform: time
      at: '19:00:00'
  condition:
    - condition: 'time'
      weekday:
        - sat
        - sun
  action:
    - service: utility_meter.next_tariff
      entity_id: utility_meter.daily_energy
    - service: utility_meter.next_tariff
      entity_id: utility_meter.monthly_energy

with the following config in utility_meter.yaml

daily_energy:
    source: sensor.total_meter_used
    cycle: daily
    tariffs:
      - peak
      - offpeak
  monthly_energy:
    source: sensor.total_meter_used
    cycle: monthly
    tariffs:
      - peak
      - offpeak

I can add a “partial-peak” tariff to this list, but I’m not sure how i can balance between weekday/weekend using this config?

Thanks!

ok i think I might have figured it out. I missed the “select tariff” option, so here’s what I came up with…can someone confirm if this is correct?

######################
### Change tariffs ###
######################
- alias: Change Utility Tariffs on Weekend
  trigger:
    - platform: time
      at: '15:00:00'
    - platform: time
      at: '19:00:00'
  condition:
    - condition: 'time'
      weekday:
        - sat
        - sun
  action:
    - service: utility_meter.next_tariff
      entity_id: utility_meter.daily_energy
    - service: utility_meter.next_tariff
      entity_id: utility_meter.monthly_energy

- alias: Change Utility Tariffs on Weekdays
  trigger:
    - platform: time
      at: '07:00:00'
    - platform: time
      at: '14:00:00'
    - platform: time
      at: '21:00:00'
    - platform: time
      at: '23:00:00'
  condition:
    - condition: 'time'
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
   action:
    - service: utility_meter.select_tariff
      entity_id: utility_meter.daily_energy
      entity_id: utility_meter.monthly_energy
      tariff: partialpeak
    - service: utility_meter.select_tariff
      entity_id: utility_meter.daily_energ
      entity_id: utility_meter.monthly_energy
      tariff: peak
    - service: utility_meter.select_tariff
      entity_id: utility_meter.daily_energy
      entity_id: utility_meter.monthly_energy
      tariff: partialpeak
    - service: utility_meter.select_tariff
      entity_id: utility_meter.daily_energy
      entity_id: utility_meter.monthly_energy
      tariff: offpeak

in my utility_meter.yaml file (included in configuration.yaml) I have this:

 daily_energy:
    source: sensor.total_meter_used
    cycle: daily
    tariffs:
      - peak
      - partialpeak
      - offpeak
  monthly_energy:
    source: sensor.total_meter_used
    cycle: monthly
    tariffs:
      - peak
      - partialpeak
      - offpeak

My assumption is that the “partialpeak” will not have any value during the weekend. Is this correct?

edit:

Didn’t seem to work. I get this error now:

Invalid config for [automation]: [tariff] is an invalid option for [automation]. Check: automation->action->0->tariff. (See /config/configuration.yaml, line 241). Please check the docs at https://home-assistant.io/components/automation/

ok think i figured it out…was missing “data”

- alias: Change Utility Tariffs on Weekends
  trigger:
    - platform: time
      at: '15:00:00'
    - platform: time
      at: '19:00:00'
  condition:
    - condition: 'time'
      weekday:
        - sat
        - sun
  action:
    - service: utility_meter.select_tariff
      data:
        entity_id:
          - utility_meter.daily_energy
          - utility_meter.monthly_energy
        tariff: peak
    - service: utility_meter.select_tariff
      data:
        entity_id:
          - utility_meter.daily_energy
          - utility_meter.monthly_energy
        tariff: offpeak

- alias: Change Utility Tariffs on Weekdays
  trigger:
    - platform: time
      at: '07:00:00'
    - platform: time
      at: '14:00:00'
    - platform: time
      at: '21:00:00'
    - platform: time
      at: '23:00:00'
  condition:
    - condition: 'time'
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
  action:
    - service: utility_meter.select_tariff
      data:
        entity_id:
          - utility_meter.daily_energy
          - utility_meter.monthly_energy
        tariff: partialpeak
    - service: utility_meter.select_tariff
      data:
        entity_id:
          - utility_meter.daily_energy
          - utility_meter.monthly_energy
        tariff: peak
    - service: utility_meter.select_tariff
      data:
        entity_id:
          - utility_meter.daily_energy
          - utility_meter.monthly_energy
        tariff: partialpeak
    - service: utility_meter.select_tariff
      data:
        entity_id:
          - utility_meter.daily_energy
          - utility_meter.monthly_energy

this validates, time to test.

1 Like

doesn’t seem to be working. I manually set the state last night to off-peak, it should now be partialpeak, but its not. I see this in the HA logs:

  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
2019-02-22 07:00:00 INFO (MainThread) [homeassistant.components.automation] Executing Change Utility Tariffs on Weekdays
2019-02-22 07:00:00 INFO (MainThread) [homeassistant.helpers.script] Script Change Utility Tariffs on Weekdays: Running script
2019-02-22 07:00:00 INFO (MainThread) [homeassistant.helpers.script] Script Change Utility Tariffs on Weekdays: Executing step call service
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
2019-02-22 07:00:00 INFO (MainThread) [homeassistant.helpers.script] Script Change Utility Tariffs on Weekdays: Executing step call service
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
2019-02-22 07:00:00 INFO (MainThread) [homeassistant.helpers.script] Script Change Utility Tariffs on Weekdays: Executing step call service
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
2019-02-22 07:00:00 INFO (MainThread) [homeassistant.helpers.script] Script Change Utility Tariffs on Weekdays: Executing step call service
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
  File "/usr/src/app/homeassistant/components/utility_meter/sensor.py", line 118, in async_tariff_change
2019-02-22 08:10:48 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Change Utility Tariffs on Weekdays
2019-02-22 08:10:48 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Change Utility Tariffs on Weekdays
2019-02-22 08:10:48 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Change Utility Tariffs on Weekdays
2019-02-22 08:10:48 INFO (MainThread) [homeassistant.components.automation] Initialized trigger Change Utility Tariffs on Weekdays```

This works breaking out into multiple actions. marking resolved.

How are you getting the data in? Gas? I only ask cause I have pge too!

Rainforest eagle, combined with a docker image I put together (https://cloud.docker.com/u/evanrich/repository/docker/evanrich/py-eagle-mqtt) that feeds the data into home asssistant. I don’t get Gas usage though, they don’t have a smart meter on that.

does that do gas?

where do you add your daily rates?

I’m a newbie on automations and conditions : can someone check my automation?
Thanks,

I’m on a 2 rates plan like this:
weekdays : 07:00:00 - 22:00:00 = peak
22:00:00 - 07:00:00 = offpeak
weekend : from Friday 22:00:00 to Monday 07:00:00 = offpeak

utility_meter:
  daily_energy:
    source: sensor.aeon_labs_zw095_home_energy_meter_gen5_energy
    cycle: daily
    tariffs:
      - peak
      - offpeak
  monthly_energy:
    source: sensor.aeon_labs_zw095_home_energy_meter_gen5_energy
    cycle: monthly
    tariffs:
      - peak
      - offpeak


automation:
  alias: utility meter week
  trigger:
    - platform: time
      at: '07:00:00'
    - platform: time
      at: '22:00:00'
  condition:
      - condition: time
        weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
 
  alias: utility meter weekend
  trigger:
    - platform: time
      at: ’22:00:00'
    - platform: time
      at: ’07:00:00'
  condition:
      - condition: time
        weekday:
        - fri
        - sat
        - sun
        - mon
  action:
    - service: utility_meter.next_tariff
      entity_id: utility_meter.daily_energy
    - service: utility_meter.next_tariff
      entity_id: utility_meter.monthly_energy

@ evanrich :What do you mean by breaking into multiple actions?
Can you share your working automation?
Thx

Yessir(or Ma’am):

- alias: Change Utility Tariffs to peak on Weekends
  trigger:
  - platform: time
    at: '15:00:00'
  condition:
  - condition: time
    weekday:
    - sat
    - sun
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id:
      - utility_meter.hourly_energy
      - utility_meter.daily_energy
      - utility_meter.monthly_energy
      - utility_meter.yearly_energy
      tariff: peak
  id: 63719d7055b04372b89875c33cc78448
- alias: Change Utility Tariffs to offpeak on Weekends
  trigger:
  - platform: time
    at: '19:00:00'
  condition:
  - condition: time
    weekday:
    - sat
    - sun
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id:
      - utility_meter.hourly_energy
      - utility_meter.daily_energy
      - utility_meter.monthly_energy
      - utility_meter.yearly_energy
      tariff: offpeak
  id: 2c7439db368f4bbe9dd88a47e39275bf
- alias: Change Utility Tariffs to partialpeak1 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.hourly_energy
      - utility_meter.daily_energy
      - utility_meter.monthly_energy
      - utility_meter.yearly_energy
      tariff: partialpeak
  id: d5235ec707a94edc9bf0c98704a041e4
- alias: Change Utility Tariffs to peak on Weekdays
  trigger:
  - platform: time
    at: '14:00:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id:
      - utility_meter.hourly_energy
      - utility_meter.daily_energy
      - utility_meter.monthly_energy
      - utility_meter.yearly_energy
      tariff: peak
  id: 3a79038f233b4facacc7c9caebd9e380
- alias: Change Utility Tariffs to partialpeak2 on Weekdays
  trigger:
  - platform: time
    at: '21:00:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id:
      - utility_meter.hourly_energy
      - utility_meter.daily_energy
      - utility_meter.monthly_energy
      - utility_meter.yearly_energy
      tariff: partialpeak
  id: 2a155e19ac03456c845445169f12b732
- alias: Change Utility Tariffs to offpeak on Weekdays
  trigger:
  - platform: time
    at: '23:00:00'
  condition:
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id:
      - utility_meter.hourly_energy
      - utility_meter.daily_energy
      - utility_meter.monthly_energy
      - utility_meter.yearly_energy
      tariff: offpeak
  id: 113a77a6a14b42978ce7de4bb2271def

basically what I had to do was for every period change, write a new automation. It would not work when I had it switch in the same automation. Breaking this out into like 6 different tariff changes works. I’m considering changing the trigger from time based to reading the meter’s tariff value, as my rainforest eagle sends that information (peak, partial peak, etc). Might save me one or two automation rules. I haven’t had time to get around to it though.

thanks for sharing!
Tought already I should make different automations. Just for curiousity : I live in Belgium and pay 0,30€ peak/ 1kWh and 0,25€ off-peak /1kWh. May I ask your rates?

offpeak: 0.12796$ (0,11 Euro/kWh)
partialpeak: 0.2053$ (0,18 Euro/kWh)
peak: 0.33524$ (0,30 Euro/kWh)

thats pretty expensive for here in california. Where my mother lives, they pay 0,11 Euro offpeak and 0,13 Euro for peak. I’m on an Electric Vehicle plan, but because I run servers, it was cheaper ultimately to do this than it was for the other opttion was a bucket system (you get a certain number of kWh/rate bucket. my bill ended up being almost 25% higher there because servers would suck up all the lower priced buckets. Now I have TOU (Time Of Use), where it fluctuates by hour of the day.

peak is same like here, offpeak is a big difference :grimacing:
Thanks again for the info and help for the automation ; I’m trying it out tonight

1 Like

Thanks evanrich, automations go smoothly.
Next challenge is to find the calculation cost

Also wondering about this??

No problem. Regarding cost, that should be easy enough to do. if you have fixed rates, just set automation for the hourly/daily/monthly rates to compute X kWh * X cost. If you’re doing it in grafana, it’s even easier.

Grafana:

If you’re doing it via automations, just have an automation that at like 11:59pm takes the daily usage from each rate (offpeak/peak), and then multiplies by your cost, and then store that in another metric.

Cost is also programmed and succeeded :smiley:
Grafana is something I will look later on.
Now I am fighting to get the states of my light switches, these are toggle switches that I can control in HA with Curl but the states do no work

Just for fun can we use this type of condition to keep value based on mounth ?

keep value for january, february, …for exemple ?