home-assistant-frank_energie icon indicating copy to clipboard operation
home-assistant-frank_energie copied to clipboard

Automation trigger lowest price or highest price of the day

Open jayaarts opened this issue 2 years ago • 11 comments

Is it possible to create an automation to, for example, receive a notification if the price becomes the lowest (or highest) of the day?

jayaarts avatar Aug 02 '22 22:08 jayaarts

You can do that with the build HA automation. You can compare current price with lowest and highest. As an action you can then send a notification. (sorry no example)

Tazzios avatar Aug 07 '22 15:08 Tazzios

When I try to do this: {{ states('sensor.current_electricity_price_all_in') | float == states('sensor.lowest_energy_price_today') | float }}

I get an error: template value should be a string for dictionary value @ data['value_template']. Got None

Sorry, I'm new and helpless knowledge; trying to learn.

jayaarts avatar Aug 09 '22 12:08 jayaarts

The described template should work and it should also work without the casts to float. The lowest_energy_price_today value is retrieved from the same array as the current all-in price so the values should also be an exact match.

For me, the template {{ states('sensor.current_electricity_price_all_in') == states('sensor.lowest_energy_price_today') }} returns true or false as expected. Maybe the error occurs when the values have not yet been instantiated, such as when Home Assistant has just started.

bajansen avatar Oct 09 '22 17:10 bajansen

I have created a binary sensor for this in configuraton.yaml

  - binary_sensor:
      - name: Happy hour
        device_class: running
        state: >
          {{ (states('sensor.current_electricity_price_all_in') | round(4,default=0) == states('sensor.lowest_energy_price_today') | round(4,default=1)) | default('off') }}

For my plugs (eg charging phone) I use this automation. It also plays a message on all my speakers

- id: '1651974863090'
  alias: Philips plug aan bij laagste tarief
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.happy_hour
    from: 'off'
    to: 'on'
  condition: []
  action:
  - type: turn_on
    device_id: d7ea19752753e08adbc9baa5128b75fa
    entity_id: switch.philips
    domain: switch
  - service: tts.zeg
    data:
      entity_id: media_player.huis
      message: De elektriciteitprijs is nu het laagst
      cache: true
  mode: single

HiDiHo01 avatar Oct 18 '22 15:10 HiDiHo01

For me the binary sensor mentioned above did not work in my configuration.yaml. This one did:

- platform: template
  sensors:
    happy_hour:
      unique_id: happyhour
      value_template: "{{ (states('sensor.current_electricity_price_all_in') | round(4,default=0) == states('sensor.lowest_energy_price_today') | round(4,default=1)) | default('off') }}"

TFhdKi95ae8L avatar Dec 23 '22 21:12 TFhdKi95ae8L

The code mentioned above works, but only for today. Now is the cheapest hour for today (2300), but in a few hours it'll be tomorrow and the prices are even lower (0300). Any tips on how to account for that?

TFhdKi95ae8L avatar Dec 23 '22 22:12 TFhdKi95ae8L

I think it's better to do something with the prices attributes:

{% set endtime = (state_attr('sensor.current_electricity_price_all_in', 'prices') | 
    selectattr('till', 'gt', now()) | 
    min(attribute='price')
  ).get('till') %}
{{ timedelta(hours=0) < endtime - now() < timedelta(hours=1)  }}

This should be true when the end time (till-datetime) of the hour with the lowest prices is within one hour, so we're currently at the lowest price.

corneyl avatar Dec 28 '22 21:12 corneyl

I think it's better to do something with the prices attributes:

{% set endtime = (state_attr('sensor.current_electricity_price_all_in', 'prices') | 
    selectattr('till', 'gt', now()) | 
    min(attribute='price')
  ).get('till') %}
{{ timedelta(hours=0) < endtime - now() < timedelta(hours=1)  }}

This should be true when the end time (till-datetime) of the hour with the lowest prices is within one hour, so we're currently at the lowest price.

Dit werkt niet bij mij....geeft altijd True aan Zo werkt ie wel

{% set endtime = (state_attr('sensor.current_electricity_price_all_in', 'prices') | min(attribute='price') ).get('till') %} {{ timedelta(hours=0) < endtime - now() < timedelta(hours=1) }}

HiDiHo01 avatar May 26 '23 11:05 HiDiHo01

For me the binary sensor mentioned above did not work in my configuration.yaml. This one did:

- platform: template
  sensors:
    happy_hour:
      unique_id: happyhour
      value_template: "{{ (states('sensor.current_electricity_price_all_in') | round(4,default=0) == states('sensor.lowest_energy_price_today') | round(4,default=1)) | default('off') }}"

Works for me Tnx! State is “False” or “True”. (Spelling incl. caps is crucial for proper functioning)

  • CONFIG - Core v2024.6.4 Supervisor v2024.06.2 Operating System v12.4 Frontend v20240610.1 Frank Energie v3.0.0

macdivernl avatar Jun 29 '24 18:06 macdivernl

How would you create an extra binary sensor called e.g. “below zero” to have a longer period available in which interesting rates can be used? In my condig “Happy Hour” is one hour only

macdivernl avatar Jul 04 '24 09:07 macdivernl

Maybe you can use a 'Threshold sensor': https://www.home-assistant.io/integrations/threshold/. Create one in 'helpers'

image

DCSBL avatar Jul 04 '24 09:07 DCSBL