forked from SebastianHanz/ModBusGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuasarModbus.xaml
186 lines (178 loc) · 5.16 KB
/
QuasarModbus.xaml
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
modbus:
- name: "Quasar"
close_comm_on_error: true
type: tcp
host: 172.16.75.18
port: 502
timeout: 2
sensors:
- name: Quasar Registers 2xx
data_type: int16
address: 256
scan_interval: 5
slave: 1
unique_id: quasar_sn_2xx
slave_count: 4
count: 5
- name: "Quasar Status"
data_type: uint16
address: 537
scan_interval: 5
slave: 1
unique_id: quasar_sn_537
- name: "Quasar Battery State"
data_type: uint16
address: 538
slave: 1
unique_id: quasar_sn_538
state_class: measurement
unit_of_measurement: '%'
device_class: battery
- name: "Quasar Power"
address: 526
slave: 1
unique_id: quasar_sn_526
state_class: measurement
device_class: power
unit_of_measurement: W
- name: "Quasar Mains Voltage"
address: 522
slave: 1
unique_id: quasar_sn_522
state_class: measurement
unit_of_measurement: V
device_class: voltage
scan_interval: 60
- name: "Quasar Max Rate"
address: 512
slave: 1
unique_id: quasar_sn_512
unit_of_measurement: A
device_class: current
scan_interval: 3600
switch:
- platform: template
switches:
quasar_pause_resume:
friendly_name: "Quasar Pause/Resume"
availability_template: "{{ is_state('sensor.quasar_status', '4') or is_state('sensor.quasar_status', '1') or is_state('sensor.quasar_status', '11') or is_state('sensor.quasar_status', '2') }}"
value_template: "{{ is_state('sensor.quasar_status', '1') or is_state('sensor.quasar_status', '11') }}"
icon_template: mdi:ev-station
turn_on:
- service: modbus.write_register
data_template:
hub: "Quasar"
unit: 1
address: 81
value: 1
- service: modbus.write_register
data_template:
hub: "Quasar"
unit: 1
address: 257
value: 1
- service: modbus.write_register
data_template:
hub: "Quasar"
unit: 1
address: 81
value: 0
turn_off:
- service: modbus.write_register
data_template:
hub: "Quasar"
unit: 1
address: 81
value: 1
- service: modbus.write_register
data_template:
hub: "Quasar"
unit: 1
address: 257
value: 2
- service: modbus.write_register
data_template:
hub: "Quasar"
unit: 1
address: 81
value: 0
template:
- name: "Quasar Charging Current"
state: '{{states("sensor.quasar_registers_2xx_2")|int(default=0)}}'
unit_of_measurement: A
device_class: current
- name: "Quasar Status Description"
state: >
{% if is_state('sensor.quasar_status', '0') %}
Ready
{% elif is_state('sensor.quasar_status', '1') %}
Charging
{% elif is_state('sensor.quasar_status', '2') %}
Waiting for car demand
{% elif is_state('sensor.quasar_status', '4') %}
Paused
{% elif is_state('sensor.quasar_status', '11') %}
Discharging
{% else %}
Unknown {{states('sensor.quasar_status')}}
{% endif %}
icon: >
{% if is_state('sensor.quasar_status', '0') %}
mdi:power-plug-off
{% elif is_state('sensor.quasar_status', '4') %}
mdi:car
{% else %}
mdi:ev-station
{% endif %}
automations action example to set the charge rate (this could also be tied to a number helper that you set the value of and use that as a trigger to send the modbus commands:
alias: Quasar - set dynamic charger rate
description: ""
trigger:
- platform: state
entity_id:
- sensor.elec_quasar_demand_amps
for:
hours: 0
minutes: 0
seconds: 5
condition:
- condition: state
entity_id: sensor.quasar_status_description
state:
- Charging
- Discharging
- condition: state
entity_id: input_boolean.charge_car_now
state: "off"
action:
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: modbus.write_register
data_template:
hub: Quasar
unit: 1
address: 81
value: 1
- service: modbus.write_register
data_template:
hub: Quasar
unit: 1
address: 258
value: |-
{% if states('sensor.elec_quasar_demand_amps')|int < 0 %}
{{ 65536 + states('sensor.elec_quasar_demand_amps')|int }}
{% elif states('sensor.elec_quasar_demand_amps')|int > 0 %}
{{states('sensor.elec_quasar_demand_amps')|int }}
{% else %}
{{ 65536-3 }}
{% endif %}
- service: modbus.write_register
data_template:
hub: Quasar
unit: 1
address: 81
value: 0
mode: restart