Open jayaarts opened 2 years ago
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)
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.
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.
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
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') }}"
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?
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.
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) }}
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)
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
Maybe you can use a 'Threshold sensor': https://www.home-assistant.io/integrations/threshold/. Create one in 'helpers'
Is it possible to create an automation to, for example, receive a notification if the price becomes the lowest (or highest) of the day?