Utility_meter.select_tariff seems to not work

Given the following config:

- 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

HA does not switch tariffs:

  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

It always stays on “offpeak”. I looked at utility_meter/sensor.py, but it doesn’t help much.

You can’t call 2 services that do opposite actions at once…

I’ve started a library to assist complex tariff plans such as your own:

which I then use with a work in progress custom component:

I currently only support Portuguese operators/tariffs, maybe you might make a PR :slight_smile: ?

1 Like

It’s not doing two things at once though. The original documentation calls out the follwing:

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

so it seems that at 09:00, it switches to “next tariff”, which would be your “peak”, then at 2100 it switches back to “offpeak”

the problem is that since I flip a few times a day, i can’t use next_tariff, so I use

SERVICE UTILITY_METER.SELECT_TARIFF

Change the current tariff to the given tariff. This service must be called by the user for the tariff switching logic to occur (e.g. using an automation)

which should allow me using the same multi-hour break down to flip… or do I need to write each hour as a seperate automation…i.e: 1st flip to one at say…9am. Then a seperate automation to flip at the next hour, etc?

Edit: it seems like this way works. breaking automation out into 6 different ones fixes it so far.

Let me take a look at your code and see, but I’d be happy to submit a PR to start adding PG&E rates for california.

In your original post, you are calling the select_tariff twice for the same utility_meter’s. Since one changes to peak and the other to offpeak, the end result is that nothing is changed, because both services will be called for all triggers. You therefore need to split that automation into several ones.

But I guess you already figured that out :slight_smile:

Complex tariff plans such as your own and mine (EDP) are very complex and take way too many automations, that’s why I started the custom component.

Yup. Again the docs aren’t exactly written well, I was taking the “next tariff” action and applying the logic to “select_tariff” which doesn’t work, since next tariff flips to next available, but select doesn’t. was a miss-understanding on my part.

There is a link in the top right end of the documentation, please use it to help improve the documentation :slight_smile:

sorry for raising old thread… did’t see a conclusion in here though… so here goes as I thin I have it working (no configuration errors)

- id: utility_tariff_offpeak
  alias: Utility Tariff offpeak
  initial_state: 'on'
  trigger:
  - platform: time
    at: '00:00:00'
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id: utility_meter.monthly_energy
      tariff: offpeak
  - service: utility_meter.select_tariff
    data:
      entity_id: utility_meter.monthly_energy
      tariff: offpeak

- id: utility_tariff_peak
  alias: Utility Tariff Peak
  initial_state: 'on'
  trigger:
  - platform: time
    at: '07:00:00'
  action:
  - service: utility_meter.select_tariff
    data:
      entity_id: utility_meter.monthly_energy
      tariff: peak
  - service: utility_meter.select_tariff
    data:
      entity_id: utility_meter.monthly_energy
      tariff: peak
1 Like

Hi

I have a issue. I have create two traiffs “peak” and “offpeak”. Boths has the same attributes in HA, but I can only select the “peak” in energy board. Why?