-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.yaml
31 lines (28 loc) · 1.52 KB
/
configuration.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
sensor:
- platform: template
sensors:
car_fully_charged_time:
value_template: >-
{% if is_state('switch.sxxxxxxxxxxxxxxx', 'on') %}
{% set charging_time_left_str = states('sensor.xxxxxxxxxxxxxxx_charging_time_left') %}
{% set charging_time_left = charging_time_left_str.split(',')[0] | int(default=0) %}
{% set last_connected_time_str = states('sensor.xxxxxxxxxxxxxxx_last_connected') %}
{% if last_connected_time_str %}
{% set last_connected_time = as_timestamp(strptime(last_connected_time_str, '%Y-%m-%dT%H:%M:%S%z')) | int %}
{% else %}
{% set last_connected_time = now().timestamp() %}
{% endif %}
{% if charging_time_left != 0 %}
{% set fully_charged_time_seconds = last_connected_time + charging_time_left * 60 + 3600 %}
{% set fully_charged_time_seconds_with_extra_hour = fully_charged_time_seconds + 3600 %}
{% set hours = ((fully_charged_time_seconds_with_extra_hour % 86400) // 3600) %}
{% set minutes = ((fully_charged_time_seconds_with_extra_hour % 86400) % 3600) // 60 %}
Car will be fully charged at: {{ "%02d:%02d" | format(hours, minutes) }}
{% else %}
Data not available
{% endif %}
{% else %}
Not charging
{% endif %}
friendly_name: 'Car Fully Charged Time'
icon_template: mdi:car-electric