Closed FSHelgeland closed 3 months ago
Sorry the BBQ lasted a bit longer than expected. 🥩
You indeed now have to create some template sensors to base your automations on. The tricky thing here is that your values cross midnight, which means todays data won't be available anymore after midnight, and that will change the output,
There are some ways to work around this, as you are using Tibber the easiest might be to use the core Tibber integration and then create the template sensor described here.
Tibber example
You can paste that code directly in your configuration.yaml (unless you are using something like a templates.yaml
file which you included allready).
After a Home Assistant restart you will then have a template sensor which has an attribute with the prices of yesterday, today and tomorrow (if available). This will make it a lot easier to create template sensors which cross midnight.
After all that is done, you can create a GUI template binary sensor helper, using the following template:
{% set start = today_at('22:00') %}
{% set end = today_at('06:00') %}
{% set hours = 3 %}
{% set morning = now() < end %}
{% set start = start - timedelta(days=morning | int) %}
{% set end = end + timedelta(days=(not morning) | int) %}
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{{ cheapest_energy_hours('sensor.tibber_prices', time_key='start_time', start=start, end=end, hours=hours, split=true, mode='is_now') }}
I havent tried to save the template sensor from the example yet, I have pasted it into developer tools and get the error: 'prices' is undefined. Thats why I did not proceed with it yesterday. I will try now to save it as a template sensor and then do a restart and see what happens.
Yes, it doesn't work in devtools > templates because it relies on a response from a service call.
Ok, I have made it. Also updated to 5.5.2 and I am doing a restart now.
Hmm I got two, have to check if I did something yesterday.
sensor.tibber_pricesTibber prices | unavailable | restored: true friendly_name: Tibber prices supported_features: 0 |
---|---|---|
sensor.tibber_prices_2Tibber prices | 0.246 | friendly_name: Tibber prices prices: - start_time: '2024-08-12T00:00:00+02:00' price: 0.0294 - start_time: '2024-08-12T01:00:00+02:00' price: 0.0284 - start_time: '2024-08-12T02:00:00+02:00' price: 0.0278 |
sensor.tibber_prices Tibber prices unavailable restored: true friendly_name: Tibber prices supported_features: 0 sensor.tibber_prices_2 Tibber prices 0.246 friendly_name: Tibber prices prices:
I think you tried to create the tibber prices sensor in the GUI yesterday.
Remove that one, you should be able to delete it, and then rename the other one in the GUI to sensor.tibber_prices
After all that is done, you can create a GUI template binary sensor helper, using the following template:
I dont think I have ever set up a sensor like this.
Got it, it states false now. As it is set up for the three cheapest hours between 22 and 06. I guess it will show true when it is actually true. If I want to use this in an automation then I can use the binary helper directly in my automation I assume. And if I need an automation to run in a cluster of the three cheapest hours, then I just add another binary helper without the split and give it another name?
so this is then a part of the heat water automation that I made
alias: VVB Adjust Temperature based on Consumption and Price
description: ""
trigger:
- platform: time_pattern
minutes: 3
action:
- choose:
- conditions:
- condition: and
conditions:
- condition: time
after: "22:00:00"
before: "06:00:00"
- condition: numeric_state
entity_id: sensor.accumulated_consumption_current_hour_hjemme
below: 6
- condition: or
conditions:
- condition: state
entity_id: sensor.prisniva_strom
state: CHEAP
- condition: state
entity_id: sensor.prisniva_strom
state: VERY_CHEAP
- condition: state
entity_id: sensor.tibber_pris_laveste_timer
state: "true"
sequence:
- data:
temperature: 86
target:
entity_id: climate.vvb_thermostat
action: climate.set_temperature
So I guess this is ok, and you can probably close this issue. Thank you for all help, you are a legend.
I would advice to create a template binary sensor (which will be either on
or off
) instead of a sensor.
Why not trigger on the (binary) sensor changing state instead of a time pattern trigger? You are making this automation a lot more complicated than it has so be
alias: VVB Adjust Temperature based on Consumption and Price
description: ""
trigger:
- platform: state
entity_id: binary_sensor.tibber_pris_laveste_timer
to: "on"
condition:
- condition: state
entity_id: sensor.prisniva_strom
state:
- CHEAP
- VERY CHEAP
- condition: numeric_state
entity_id: sensor.accumulated_consumption_current_hour_hjemme
below: 6
action:
- action: climate.set_temperature
target:
entity_id: climate.vvb_thermostat
data:
temperature: 86
The binary sensor tibber_pris_laveste_timer is the binary sensor. Could probably made the automation easier, this is only a part of a big automation and it have worked rock steady for more than a year. This was only the first choose block out of four-
Seems to work just fine :-)
Glad to see you have it working!
I was not implying the sensor
would not work, but a binary_sensor
is intended to represent a state which can only have two values (true
or false
, on
or off
, 1
or 0
, online
or offline
, etc).
That's why I would advice to use a binary sensor instead of a (normal) sensor, but whatever floats your boat :)
Regarding your automation, you know this triggers every hour, at 00:03, 01:03, 02:03, etc right? If you intended to trigger every three minutes, you need to use minutes: "/3"
. Just checking here, it could be that the current trigger is how you intended it.
Closing this issue as you seem to have the solution you were looking for :)
Ok, so I have installed this through HACS and I have this sensor:
update.cheapest_energy_hours_update
it has these attributes: auto_update: false installed_version: v5.5.1 in_progress: false latest_version: v5.5.1 release_summary: null release_url: https://github.com/TheFes/cheapest-energy-hours/releases/v5.5.1 skipped_version: null title: null friendly_name: Cheapest Energy Hours update supported_features: 23
and current status is off:
I have Tibber and my sensor with the price information is:
sensor.energy_price_elsa_laulas_veg_20 This sensor have the info for raw_today raw_tomorrow tomorrow_valid
I believe I now have to make one template sensor or more?
That where I stand for now. My goal is to start an input boolean or something on the cheapest hours between 22 and 06, they dont have to be in a cluster. Hope someone can help me.