Fix: store start_time as Unix timestamp to avoid datetime/string subtraction error
This commit is contained in:
parent
c65826f12e
commit
5c48e1c2a5
1 changed files with 6 additions and 13 deletions
|
|
@ -156,9 +156,8 @@ trigger:
|
|||
|
||||
action:
|
||||
- variables:
|
||||
start_time: "{{ now() }}"
|
||||
start_ts: "{{ now().timestamp() | int }}"
|
||||
start_power: "{{ states(power_sensor) | float(0) | round(1) }}"
|
||||
start_energy_raw: "{{ states(energy_sensor) | float(0) }}"
|
||||
start_energy_kwh: >
|
||||
{{ (states(energy_sensor) | float(0)) / 1000
|
||||
if energy_unit == 'Wh'
|
||||
|
|
@ -175,7 +174,7 @@ action:
|
|||
title: "🔋 Laden gestartet – {{ device_name }}"
|
||||
message: >
|
||||
Ladevorgang erkannt: {{ start_power }} W.
|
||||
Gestartet um {{ start_time | as_timestamp | timestamp_custom('%H:%M Uhr') }}.
|
||||
Gestartet um {{ start_ts | timestamp_custom('%H:%M Uhr') }}.
|
||||
|
||||
- wait_for_trigger:
|
||||
- platform: numeric_state
|
||||
|
|
@ -189,11 +188,7 @@ action:
|
|||
seconds: "{{ stop_debounce_seconds }}"
|
||||
|
||||
- variables:
|
||||
end_time: "{{ now() }}"
|
||||
end_energy_kwh: >
|
||||
{{ (states(energy_sensor) | float(0)) / 1000
|
||||
if energy_unit == 'Wh'
|
||||
else (states(energy_sensor) | float(0)) }}
|
||||
end_ts: "{{ now().timestamp() | int }}"
|
||||
charged_kwh: >
|
||||
{{ [((states(energy_sensor) | float(0)) / 1000
|
||||
if energy_unit == 'Wh'
|
||||
|
|
@ -204,12 +199,10 @@ action:
|
|||
if energy_unit == 'Wh'
|
||||
else (states(energy_sensor) | float(0)))
|
||||
- start_energy_kwh, 0] | max * electricity_price) | round(2) }}
|
||||
duration_seconds: >
|
||||
{{ (now() - start_time).total_seconds() | int }}
|
||||
duration_text: >
|
||||
{% set s = (now() - start_time).total_seconds() | int %}
|
||||
{% set h = (s // 3600) %}
|
||||
{% set m = ((s % 3600) // 60) %}
|
||||
{% set s = (now().timestamp() | int) - start_ts %}
|
||||
{% set h = (s // 3600) | int %}
|
||||
{% set m = ((s % 3600) // 60) | int %}
|
||||
{% if h > 0 %}{{ h }} h {{ m }} min{% else %}{{ m }} min{% endif %}
|
||||
|
||||
- if:
|
||||
|
|
|
|||
Loading…
Reference in a new issue