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:
|
action:
|
||||||
- variables:
|
- variables:
|
||||||
start_time: "{{ now() }}"
|
start_ts: "{{ now().timestamp() | int }}"
|
||||||
start_power: "{{ states(power_sensor) | float(0) | round(1) }}"
|
start_power: "{{ states(power_sensor) | float(0) | round(1) }}"
|
||||||
start_energy_raw: "{{ states(energy_sensor) | float(0) }}"
|
|
||||||
start_energy_kwh: >
|
start_energy_kwh: >
|
||||||
{{ (states(energy_sensor) | float(0)) / 1000
|
{{ (states(energy_sensor) | float(0)) / 1000
|
||||||
if energy_unit == 'Wh'
|
if energy_unit == 'Wh'
|
||||||
|
|
@ -175,7 +174,7 @@ action:
|
||||||
title: "🔋 Laden gestartet – {{ device_name }}"
|
title: "🔋 Laden gestartet – {{ device_name }}"
|
||||||
message: >
|
message: >
|
||||||
Ladevorgang erkannt: {{ start_power }} W.
|
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:
|
- wait_for_trigger:
|
||||||
- platform: numeric_state
|
- platform: numeric_state
|
||||||
|
|
@ -189,11 +188,7 @@ action:
|
||||||
seconds: "{{ stop_debounce_seconds }}"
|
seconds: "{{ stop_debounce_seconds }}"
|
||||||
|
|
||||||
- variables:
|
- variables:
|
||||||
end_time: "{{ now() }}"
|
end_ts: "{{ now().timestamp() | int }}"
|
||||||
end_energy_kwh: >
|
|
||||||
{{ (states(energy_sensor) | float(0)) / 1000
|
|
||||||
if energy_unit == 'Wh'
|
|
||||||
else (states(energy_sensor) | float(0)) }}
|
|
||||||
charged_kwh: >
|
charged_kwh: >
|
||||||
{{ [((states(energy_sensor) | float(0)) / 1000
|
{{ [((states(energy_sensor) | float(0)) / 1000
|
||||||
if energy_unit == 'Wh'
|
if energy_unit == 'Wh'
|
||||||
|
|
@ -204,12 +199,10 @@ action:
|
||||||
if energy_unit == 'Wh'
|
if energy_unit == 'Wh'
|
||||||
else (states(energy_sensor) | float(0)))
|
else (states(energy_sensor) | float(0)))
|
||||||
- start_energy_kwh, 0] | max * electricity_price) | round(2) }}
|
- start_energy_kwh, 0] | max * electricity_price) | round(2) }}
|
||||||
duration_seconds: >
|
|
||||||
{{ (now() - start_time).total_seconds() | int }}
|
|
||||||
duration_text: >
|
duration_text: >
|
||||||
{% set s = (now() - start_time).total_seconds() | int %}
|
{% set s = (now().timestamp() | int) - start_ts %}
|
||||||
{% set h = (s // 3600) %}
|
{% set h = (s // 3600) | int %}
|
||||||
{% set m = ((s % 3600) // 60) %}
|
{% set m = ((s % 3600) // 60) | int %}
|
||||||
{% if h > 0 %}{{ h }} h {{ m }} min{% else %}{{ m }} min{% endif %}
|
{% if h > 0 %}{{ h }} h {{ m }} min{% else %}{{ m }} min{% endif %}
|
||||||
|
|
||||||
- if:
|
- if:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue