but here it is not add the nettariff from eloverblik ?
You can keep your code to add the tariff… My point is about adding the key names to your namespace, so you will have those keys in your attributes to be used later by other senskrs/automations…
I can work in a better example tomorrow…
Mm okay.
i just thougt it was possible just to extract the values one by one from the
{{cheapest_price_list}}
like:
{% set cheapest_hour_1 = ..... %}
{% set cheapest_hour_2 = ..... %}
{% set cheapest_hour_3 = ..... %}
{% set cheapest_hour_4 = ..... %}
if the price is then one of those, it will trigger the charger to turn on,
make it very simple
or if the datetime, instead of the price.
That will work, but it would be harder to maintain your code and also reduce a bit the number of time conversions you are doing. But maybe this is not an issue…
You don’t have to store the 4 values on variables, as you can just look if the current price is less or equal than the 4 price (sorted).
Something like this:
{{ if current_price <= (cheapest_price_list | sort(1))[3] }}
Here is the code now with the time frame working.
{% set now_time = as_timestamp(now()) | timestamp_custom("%d %m %Y %H %M") %}
{% set now_time_unix = as_timestamp(now()) %}
Now Time
{{ now_time }} #string format datetime
{{ now_time_unix }} #unix format datetime
{% set time_connection = as_timestamp(states('input_datetime.datetime_charger_change')) | timestamp_custom('%d %m %Y %H:%M') %}
{% set time_connection_unix = ((as_timestamp(time_connection[6:10] ~ "-" ~ time_connection[3:5] ~ "-" ~ time_connection[0:2] ~ time_connection[10:16]))) | round(0) %}
Time Connection
{{ time_connection }} #string format datetime
{{ time_connection_unix }} #unix format datetime
{% set hour_morning_next_day = '06:00' %}
{% set next_day = as_timestamp(now()+timedelta(days=1)) | timestamp_custom("%d %m %Y") %}
{% set next_day_and_hour = next_day + " " + hour_morning_next_day %}
{% set next_day_and_hour_unix = ((as_timestamp(next_day_and_hour[6:10] ~ "-" ~ next_day_and_hour[3:5] ~ "-" ~ next_day_and_hour[0:2] ~ next_day_and_hour[10:16]))) | round(0) %}
Tomorrow Time
{{ next_day }} #string format date
{{ hour_morning_next_day }} #string format time
{{ next_day_and_hour }} #string format datetime
{{ next_day_and_hour_unix }} #unix format datetime
{% set hour_morning_next_day_old = '06:00' %}
{% set next_day_old = as_timestamp(now()) | timestamp_custom("%d %m %Y") %}
{% set next_day_and_hour_old = next_day_old + " " + hour_morning_next_day_old %}
{% set next_day_and_hour_unix_old = ((as_timestamp(next_day_and_hour_old[6:10] ~ "-" ~ next_day_and_hour_old[3:5] ~ "-" ~ next_day_and_hour_old[0:2] ~ next_day_and_hour_old[10:16]))) | round(0) %}
Tomorrow Time old
{{ next_day_old }} #string format date
{{ hour_morning_next_day_old }} #string format time
{{ next_day_and_hour_old }} #string format datetime
{{ next_day_and_hour_unix_old }} #unix format datetime
{% set price_today = state_attr('sensor.electricity_cost', 'today') %}
{% set price_tomorrow = state_attr('sensor.electricity_cost', 'tomorrow') %}
{% set price_list = price_today + price_tomorrow %}
{# {{ price_list }} #}
{% if now_time_unix < next_day_and_hour_unix_old %}
{% set cheapest_price_list = price_list|selectattr(0,'>=',time_connection_unix)|selectattr(0,'<=',next_day_and_hour_unix_old)|selectattr(1,'<=',3.5)|sort(attribute=1) %}
{% elif now_time_unix > next_day_and_hour_unix_old %}
{% set cheapest_price_list = price_list|selectattr(0,'>=',time_connection_unix)|selectattr(0,'<=',next_day_and_hour_unix)|selectattr(1,'<=',3.5)|sort(attribute=1) %}
{% endif %}
{{cheapest_price_list}}
thank you.
you just gave me the last thing to my code for now.
how do i get the price out of the bracket so only the price is showed not time stamp
i dont think the maintaining part will be a problem.
i will try it out, and after some day test i will return on this !
result:
[1676858400, 0.88728125]
By the way, this will give you tomorrow at 6:00 without all the string manipulation you are doing:
{{ today_at("06:00") + timedelta (hours=24) }}
Try this:
{{ [1676858400, 0.88728125][1] }}
Or this:
{{ your_variable_with_those_values[1] }}
thank you, that would help me alot
just tried to make it my own, to see some patterns.
but could you also give me the last:
how do i get the price out of the bracket so only the price is showed not time stamp
result now:
[1676858400, 0.88728125]
expected result:
[0.88728125]
{{ (cheapest_price_list | sort(1))[3][1] }}
WORKED !
i will create a sensor.
and then let it run for days and return ont this with my final solution
great help !
Just spotted a new custom integration that might help?