I have these sensors :
snsor.energi_data_service_today_min
Today Minimum Price {‘hour’: datetime.datetime(2023, 12, 12, 23, 0, tzinfo=<DstTzInfo ‘Europe/Copenhagen’ CET+1:00:00 STD>), ‘price’: 1.734} friendly_name: Today Minimum Price
[sensor.energi_data_service_tomorrow_min]
Tomorrow Minimum Price {‘hour’: datetime.datetime(2023, 12, 13, 3, 0, tzinfo=<DstTzInfo ‘Europe/Copenhagen’ CET+1:00:00 STD>), ‘price’: 1.677} friendly_name: Tomorrow Minimum Price
They update daily now I tried to make a script that takes the hour as this is the cheapest time to charge. YYYY, MM, DD, T,M = 03:00 is what I need out of this or 23:00
I tried something like this, but it just doesn’t give me the right time…
- id: '1702134129031'
alias: Select Best Time for Battery Charging
description: ''
trigger:
- platform: time
at: '14:00:00'
action:
- variables:
today_min_price_hour: '{{ states(''sensor.energi_data_service_today_min'').attributes.hour }}'
tomorrow_min_price_hour: '{{ states(''sensor.energi_data_service_tomorrow_min'').attributes.hour }}'
today_min_price_time: '{{ "%02d:00" | format(today_min_price_hour) }}'
tomorrow_min_price_time: '{{ "%02d:00" | format(tomorrow_min_price_hour) }}'
current_time: '{{ now().strftime(''%H:%M'') }}'
- choose:
- conditions: "{{ current_time <= today_min_price_time }}"
sequence:
- service: select.select_option
data_template:
entity_id: select.solax_charger_start_time_1
option: '{{ today_min_price_time }}'
- service: select.select_option
data:
entity_id: select.solax_selfuse_night_charge_enable
option: Enabled
- service: number.set_value
data:
entity_id: number.solax_selfuse_nightcharge_upper_soc
value: 100
- service: select.select_option
data_template:
entity_id: select.solax_charger_end_time_1
option: '{{ (today_min_price_time.split(":")[0] | int + 1) | string | pad(2, "0") }}:{{ today_min_price_time.split(":")[1] }}'
- conditions: "{{ current_time <= tomorrow_min_price_time }}"
sequence:
- service: select.select_option
data_template:
entity_id: select.solax_charger_start_time_1
option: '{{ tomorrow_min_price_time }}'
- service: select.select_option
data:
entity_id: select.solax_selfuse_night_charge_enable
option: Enabled
- service: number.set_value
data:
entity_id: number.solax_selfuse_nightcharge_upper_soc
value: 100
- service: select.select_option
data_template:
entity_id: select.solax_charger_end_time_1
option: '{{ (tomorrow_min_price_time.split(":")[0] | int + 1) | string | pad(2, "0") }}:{{ tomorrow_min_price_time.split(":")[1] }}'
- conditions: "{{ current_time > tomorrow_min_price_time }}"
sequence:
- service: select.select_option
data_template:
entity_id: select.solax_charger_start_time_1
option: '{{ tomorrow_min_price_time }}'
- service: number.set_value
data:
entity_id: number.solax_selfuse_nightcharge_upper_soc
value: 100
- service: select.select_option
data_template:
entity_id: select.solax_charger_end_time_1
option: '{{ (tomorrow_min_price_time.split(":")[0] | int + 1) | string | pad(2, "0") }}:{{ tomorrow_min_price_time.split(":")[1] }}'
PLEASE HELP!