Skip to content

Instantly share code, notes, and snippets.

@fredrike
Last active April 16, 2021 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrike/ac758adad1360b74180194a0428a34dd to your computer and use it in GitHub Desktop.
Save fredrike/ac758adad1360b74180194a0428a34dd to your computer and use it in GitHub Desktop.
blueprint:
name: Notify when car is charging
description: Send push notification when the car is plugged in and have started charging
domain: automation
input:
battery_charging:
name: Car battery charging sensor
selector:
entity:
domain: binary_sensor
device_class: plug
battery_range:
name: Car battery range sensor
selector:
entity:
domain: sensor
battery_level:
name: Car battery level
selector:
entity:
domain: sensor
time_to_fully_charged:
name: Time until battery is fully charged
selector:
entity:
domain: sensor
notify_device:
name: Device to notify
description: Device needs to run the official Home Assistant app to receive notifications.
selector:
device:
integration: mobile_app
trigger:
- entity_id: !input battery_charging
platform: state
for: 00:00:05
from: 'off'
to: 'on'
- entity_id: !input battery_charging
from: 'on'
platform: state
to: 'off'
variables:
ch_time: !input time_to_fully_charged
charging_time: "{{ states(ch_time) }}"
b_range: !input battery_range
battery_state: "{{ states(b_range) }}"
b_level: !input battery_level
battery_level: "{{ states(b_level) }}"
action:
domain: mobile_app
type: notify
device_id: !input notify_device
message: >-
{% if trigger and (trigger.to_state.state == 'on') %}
The car is currently charging, will finish at
{{- (now() | as_timestamp() + (charging_time|int * 60)) | timestamp_custom(" %H:%M", True) }}
{{- (-3600 + (charging_time|int * 60)) | timestamp_custom(" (%-H h %-M min).", True) }}
{%- else %}
Finished charging, battery at {{ battery_level }}%, ({{ battery_state }} km).
{%- endif %}
title: Car charging time
@fredrike
Copy link
Author

Work in progress, the message needs some magical formatting..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment