Tibber electricity price threshold trigger

For Tibber users.

Perform actions when Tibber electricity prices go above or below a selected threshold.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Tibber price control
  description: Perform actions when electricity prices go above or below a selected threshold.
  domain: automation
  input:
    tibber_price_sensor:
      name: Tibber price sensor
      selector:
        entity:
          domain: sensor
    threshold:
      name: Threshold
      description: When to consider prices low.
      default: "CHEAP"
      selector:
        select:
          options:
            - label: Very expensive
              value: VERY_EXPENSIVE
            - label: Expensive
              value: EXPENSIVE
            - label: Normal
              value: NORMAL
            - label: Cheap
              value: CHEAP
            - label: Very cheap
              value: VERY_CHEAP
    below_actions:
      name: Low prices
      description: Actions to perform when prices become low.
      default: []
      selector:
        action: {}
    above_actions:
      name: High prices
      description: Actions to perform when prices become high.
      default: []
      selector:
        action: {}
mode: restart
max_exceeded: silent
trigger:
  - platform: state
    entity_id: !input tibber_price_sensor
    attribute: price_level
action:
- variables:
    levels: "{{ ['VERY_CHEAP','CHEAP','NORMAL','EXPENSIVE','VERY_EXPENSIVE'] }}"
    old_level: "{{ trigger.from_state.attributes.price_level }}"
    new_level: "{{ trigger.to_state.attributes.price_level }}"
    threshold: !input threshold
- choose:
  - conditions:
    - "{{ levels.index(new_level) <=  levels.index(threshold) and levels.index(old_level) >  levels.index(threshold)}}"
    sequence: !input below_actions
  - conditions:
    - "{{ levels.index(old_level) <=  levels.index(threshold) and levels.index(new_level) >  levels.index(threshold)}}"
    sequence: !input above_actions
5 Likes

See also: Tibber price and thermostat control

Hey nice work!!

I think you did your import button wrong because it’s not working to import. I think you need to add the link to this post in the URL for the button not to the github gist.

Thanks! Button fixed.

1 Like

This blueprint is just what I’m looking for if only I can get it to work!

The thing is that I can’t seem to get my automations working. My tibber price sensor is sensor.electricity_price_house. (wich is my senor that hold all the attributes and check the actual price).`

What am I missing?

Hi @magpet!

In what way does it not work?

Test with a simple configuration like:

alias: Tibber price control
description: ""
use_blueprint:
  path: komakino/tibber-electricity-price-threshold-trigger.yaml
  input:
    tibber_price_sensor: sensor.electricity_price_house
    below_actions:
      - service: notify.tibber
        data:
          message: Cheap!
    above_actions:
      - service: notify.tibber
        data:
          message: Expensive!

And then go to Developer Tools > States, find your tibber sensor and manually change the state attribute(price_level) to VERY_CHEAP and then to VERY_EXPENSIVE. Do the notifications not trigger? (The attribute will revert back to the actual value in a couple of seconds.)

This is excactly what im lookibg for ! Thanks! Unfortunately I can’t get it to work . I am no expert, but I was able to find out , it looks like it passes right by the action part, even though it’s triggered? I will try to change the threshold and a few other things to see if I can get it working . I would be very glad if you could have a look at the screenshot, maybe it’s a very obvious mistake?

Hej! Snyggt jobb!

Vad är det som styr vad som är billigt och dyrt?
Alltså vad kostar elen när man har på “normal” är det ett uträknat genomsnitt per vecka typ? Mvh

Thanks, exactly what I’m looking for. Though I get an error as shown below - any ideas?

Edit: OK, sorry about this - as a newbie I triggered the automation from the UI which apparently doesn’t attach the trigger… Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘to_state’ - Configuration - Home Assistant Community (home-assistant.io)

1 Like

I am new to Home Assistant and I am trying to get my water heater to turn off when the price is normal and high, based on Tibber price.
The attributes used here are based on a 3 day average, which can mean a day can go by without hot water if the average price that day is “expensive” after 3 days with cheap prices.
So my question is, can’t this instead use PriceRatingLevel instead? That way, if I read Tibber developer correctly, the price will vary between low, normal and high every day.

Or am I misunderstanding? As I said, I am very new to HA and “programming”.

Hej Emil. Det styrs av Tibbers “PriceLevel”.

Hi, PriceRatingLevel is not available in the current implementation of the Tibber price sensor in Home Assistant AFAIK.

Hello and thank you for a nice blueprint. I just have probleme with it and it’s because it takes the prices for the last three days and uses that as a reference. So the problem is that when I want the water heatup at least once a day it won’t trigger if the prices got very high the last days. I therfore try to use a template for calculate the “level” last 24 hours. But the value from the template is not a attribute but a “state” How can I modiy you blueprint som it reads states and not attributes or how can I remodel the template so it changes the “attribute” and not the state. I would be very thankfull for you help.

template:
  sensor:
    - name: Electricity price - Price level (1-day)
      icon: mdi:currency-usd
      state: >-
        {% set price_cur = states('sensor.electricity_price') | float(0) %}
        {% set price_avg = state_attr('sensor.electricity_price', 'avg_price') | float(0) %}
        {% if price_cur == 0 or price_avg == 0 %}
          unknown
        {% else %}
          {% set price_ratio = (price_cur / price_avg) %}
          {% if price_ratio >= 1.4 %}
            VERY_EXPENSIVE
          {% elif price_ratio >= 1.15 %}
            EXPENSIVE
          {% elif price_ratio <= 0.6 %}
            VERY_CHEAP
          {% elif price_ratio <= 0.9 %}
            CHEAP
          {% else %}
            NORMAL
          {% endif %}
        {% endif %}

Sorry @Christer84 but what is that screenshot? Is a visual representation of the automation?

Hi, I’m a beginner trying to figure out how this works as I want to control my water heater and boiler using Tibber’s price levels. I wonder if anyone has the answer why I also get the error:

Error: UndefinedError: ‘dict object’ has no attribute ‘from_state’

when I use the above blueprint in automation.

Would be very grateful if I could get this started. hope for your answers
Greetings
Niclas

Hi Niclas. As mentioned above, you can’t manually trigger this automation from the UI. If you want to trigger it manually you can play with the price level attribute in the Tibber entity.

1 Like

What entity should I use for the Tibber Price Sensor?
Is it the Electricity Price for my Home address?

Im also getting the same error as the user above.

I played around with the different price levels but can’t get the automation to run.

Hello,

Sorry for bumping this old thread, but just found this being quite new to Home Assistant and with the winter coming electricity prices gets more intresting. :smiley:

Trying the blueprint and getting the same error:
"Error: UndefinedError: ‘dict object’ has no attribute ‘from_state’

Understood that I cannot manually trigger the automation, but does that mean I cannot manually start it?
E.g, currently the price level is VERY_CHEAP.
What I am planning to use it for is to run a heater in my garage, and to start when price falls below CHEAP.
Can´t I test it by turning off the heater, then run the automation to start the heater (since current price should activate the heater)?
Or do I need to start it manually and wait and see when price level change to NORMAL and check then if it turns off my heater?

Automation running like a champ for some days now. But every time I want to change the threshold I have to go into the automation and change it there. Especially a dealbreaker for my wife. Would really love a card in our dashboard in which we can see the state and change it from there but have not the skills to accomplish this myself tbh.

The blueprint would be a perfect fit for me. So I tried to use it. I have no glue why the automation jumps over the action. May somebody could help me?

image

choose:
  - conditions:
      - >-
        {{ levels.index(new_level) <=  levels.index(threshold) and
        levels.index(old_level) >  levels.index(threshold)}}
    sequence:
      - service: climate.set_temperature
        metadata: {}
        data:
          temperature: 20
        target:
          entity_id: climate.stiebel_eltron_isg_heat_circuit_1
      - service: notify.mobile_app_m2002j9g
        metadata: {}
        data:
          message: Tibber Preis gesunken. LWZ Temperatur angepasst.
          title: Tibber/LWZ
  - conditions:
      - >-
        {{ levels.index(old_level) <=  levels.index(threshold) and
        levels.index(new_level) >  levels.index(threshold)}}
    sequence:
      - service: climate.set_temperature
        metadata: {}
        data:
          temperature: 17.5
        target:
          entity_id: climate.stiebel_eltron_isg_heat_circuit_1
      - service: notify.mobile_app_m2002j9g
        metadata: {}
        data:
          message: Hoher Tibber Preis. LWZ Temperatur reduziert.
          title: Tibber/LWZ

I verified that the price level was “expensive” at that time.