forked from aj-nagrom/esphome-modbus-server
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcharge_automation.yaml
193 lines (191 loc) · 8.66 KB
/
charge_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
alias: Chargepoint Current Regulation
description: ""
trigger:
- platform: time_pattern
seconds: /2
enabled: true
action:
- choose: # start of setting desired current based on charge_mode
- conditions:
- condition: state
entity_id: input_select.charge_mode
state: Max Speed
sequence:
- service: input_number.set_value
data:
value: >-
{% if states('sensor.shell3em_main_power_factor') | float() > 0 %}
{% set pf = 1 %}
{% else %}
{% set pf = -1 %}
{% endif %}
{% set newcurrent = states('input_number.main_maximal_current') | float() - states('sensor.shell3em_main_current') | float() * pf | float() + states('sensor.shelly3em_laadpaal_current') | float() %}
{% if newcurrent < states('input_number.chargepoint_minimal_current') | float() -%}
{{ states('input_number.chargepoint_minimal_current') | float() }}
{%- else -%}
{{ newcurrent }}
{%- endif %}
target:
entity_id: input_number.chargepoint_desired_current
- conditions:
- condition: state
entity_id: input_select.charge_mode
state: Avoid Power To Grid
sequence:
- service: input_number.set_value
data:
value: >-
{% if states('sensor.shell3em_main_power_factor') | float() > 0 %}
{% set pf = 1 %}
{% else %}
{% set pf = -1 %}
{% endif %}
{% set newcurrent = states('sensor.shelly3em_laadpaal_current') | float() - states('sensor.shell3em_main_current') | float() * pf | float() %}
{% if newcurrent < states('input_number.chargepoint_minimal_current') | float() -%}
{{ states('input_number.chargepoint_minimal_current') | float() }}
{%- else -%}
{{ newcurrent }}
{%- endif %}
target:
entity_id: input_number.chargepoint_desired_current
- conditions:
- condition: state
entity_id: input_select.charge_mode
state: 2A From Grid
sequence:
- service: input_number.set_value
data:
value: >-
{% if states('sensor.shell3em_main_power_factor') | float() > 0 %}
{% set pf = 1 %}
{% else %}
{% set pf = -1 %}
{% endif %}
{% set newcurrent = states('sensor.shelly3em_laadpaal_current') | float() - states('sensor.shell3em_main_current') | float() * pf | float() + 2 %}
{% if newcurrent < states('input_number.chargepoint_minimal_current') | float() -%}
{{ states('input_number.chargepoint_minimal_current') | float() }}
{%- else -%}
{{ newcurrent }}
{%- endif %}
target:
entity_id: input_number.chargepoint_desired_current
- conditions:
- condition: state
entity_id: input_select.charge_mode
state: Solar only
sequence:
- service: input_number.set_value
data:
value: >-
{% set newcurrent = states('sensor.sma_grid_phase_1_current') | float() %}
{% if newcurrent < states('input_number.chargepoint_minimal_current') | float() -%}
{{ states('input_number.chargepoint_minimal_current') | float() }}
{%- else -%}
{{ newcurrent }}
{%- endif %}
target:
entity_id: input_number.chargepoint_desired_current
- conditions:
- condition: state
entity_id: input_select.charge_mode
state: Manual Charge Speed
sequence:
- service: input_number.set_value
data:
value: >-
{% set newcurrent = states('input_number.chargepoint_manual_current') | float() %}
{% if newcurrent < states('input_number.chargepoint_minimal_current') | float() -%}
{{ states('input_number.chargepoint_minimal_current') | float() }}
{%- else -%}
{{ newcurrent }}
{%- endif %}
target:
entity_id: input_number.chargepoint_desired_current
- conditions:
- condition: state
entity_id: input_select.charge_mode
state: Manual Max Main
sequence:
- service: input_number.set_value
data:
value: >-
{% if states('sensor.shell3em_main_power_factor') | float() > 0 %}
{% set pf = 1 %}
{% else %}
{% set pf = -1 %}
{% endif %}
{% set newcurrent = states('input_number.main_manual_current') | float() - ( states('sensor.shell3em_main_current') | float() * pf | float() - states('sensor.shelly3em_laadpaal_current') | float() ) %}
{% if newcurrent < states('input_number.chargepoint_minimal_current') | float() -%}
{{ states('input_number.chargepoint_minimal_current') | float() }}
{%- else -%}
{{ newcurrent }}
{%- endif %}
target:
entity_id: input_number.chargepoint_desired_current
- conditions:
- condition: state
entity_id: input_select.charge_mode
state: Charging Off
sequence:
- service: input_number.set_value
data:
value: 0
target:
entity_id: input_number.chargepoint_desired_current
enabled: true
# End of setting desired current based on charge_mode
- choose: # start of check if not over-amping the main fuse
- conditions:
- condition: template
value_template: >- ## check if not over-amping the main fuse
{% if states('sensor.shell3em_main_power_factor') | float() > 0 %}
{% set pf = 1 %}
{% else %}
{% set pf = -1 %}
{% endif %}
{{states('input_number.chargepoint_desired_current') |float() - states('sensor.shelly3em_laadpaal_current') |float() + (states('sensor.shell3em_main_current') |float()) * pf | float() > states('input_number.main_maximal_current') |float() }}
sequence:
- service: input_number.set_value
data:
value: >-
{% if states('sensor.shell3em_main_power_factor') | float() > 0 %}
{% set pf = 1 %}
{% else %}
{% set pf = -1 %}
{% endif %}
{{ states('input_number.main_maximal_current') |float() - states('sensor.shell3em_main_current') |float() * pf | float() + states('sensor.shelly3em_laadpaal_current') |float() }}
target:
entity_id: input_number.chargepoint_desired_current
# - service: logbook.log
# data:
# name: chargepoint
# message: Desired current higher than main_maximal_current
# entity_id: input_number.main_maximal_current
enabled: true
# End of check if not over-amping the main fuse
- choose: # start of check if increasing or decreasing
- conditions:
- condition: template
value_template: >- ## if load should be increased
{{(states('input_number.chargepoint_desired_current') | float() - (states('sensor.shelly3em_laadpaal_current') |float() ) ) > 0 }}
sequence:
- service: number.set_value
data:
value: >-
{{ states('input_number.main_maximal_current') | float() - (states('input_number.chargepoint_desired_current') | float() - (states('sensor.shelly3em_laadpaal_current') |float() ) )}}
target:
entity_id: number.modbus_server_xemex_ct1current
- conditions:
- condition: template
value_template: >- ## if load should be decreased
{{(states('input_number.chargepoint_desired_current') | float() - (states('sensor.shelly3em_laadpaal_current') |float() ) ) <= 0 }}
sequence:
- service: number.set_value
data:
value: >-
{{ states('input_number.main_maximal_current') | float() - (states('input_number.chargepoint_desired_current') | float() - (states('sensor.shelly3em_laadpaal_current') |float() ) )/2}}
target:
entity_id: number.modbus_server_xemex_ct1current
enabled: true
# End of check if not over-amping the main fuse
mode: single