forked from mk-maddin/wattpilot-HA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwattpilot_automation.yaml
63 lines (61 loc) · 2.71 KB
/
wattpilot_automation.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# version: 2022.03.03
# author: Martin Kraemer, [email protected]
# description: home assistant configuration file - yaml structure
# the topic this file handles is described by its filename
automation:
- id: wattpilot_sync_nexttrip
alias: wattpilot_sync_nexttrip
description: 'Sync next trip information of wattpilot to input_datetime'
mode: queued
trigger:
- id: 'set_value'
platform: state
entity_id: input_datetime.wattpilot_next_trip_timing
- id: 'get_value'
platform: event
event_type: 'wattpilot_property_message'
event_data:
# charger_id: "Wattpilot" #if you have multiple chargers you can define here which charger to hanlde with this input_datetime
property: "ftt" #ftt is the property name of nexttrip timing
action:
- variables:
input_dt: 'input_datetime.wattpilot_next_trip_timing'
device_id: 46685168f8c86080645840dd194e2f06 #PLEASE CHANGE: device_id of your charger
- choose:
- conditions:
- condition: trigger
id: 'set_value'
sequence:
- service: wattpilot.set_next_trip
data_template:
device_id: "{{ device_id }}"
trigger_time: "{{ states(input_dt) | string }}"
- conditions:
- condition: trigger
id: 'get_value'
sequence:
- choose:
- conditions:
- condition: template
value_template: >-
{# check if new and old value are already matching #}
{% set current = (as_timestamp(today_at(states(input_dt))) - as_timestamp(today_at('00:00'))) | int %}
{% set new = trigger.event.data.value %}
{{ not new == current }}
sequence:
- service: input_datetime.set_datetime
data_template:
entity_id: "{{ input_dt }}"
timestamp: "{{ trigger.event.data.value }}"
default:
- service: system_log.write
data_template:
message: "Values of input_datetime & wattpilot already match: {{ trigger.event.data.value }}"
logger: homeassistant.components.automation.wattpilot_sync_nexttrip
level: debug
default:
- service: system_log.write
data_template:
message: "Unhandled trigger: {{ trigger }}"
logger: homeassistant.components.automation.wattpilot_sync_nexttrip
level: error