-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdanfoss-pico.yml
282 lines (246 loc) · 7.37 KB
/
danfoss-pico.yml
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# Danfoss FC200 integration via Modbus using Raspberry PI Pico + SP3485 Transceiver
# https://files.danfoss.com/download/Drives/MG20O622.pdf
# https://www.waveshare.com/pico-2ch-rs485.htm
# https://www.anodas.lt/2-kanalu-rs485-2-kanalu-uart-rs485-modulis-sp3485-skirtas-raspberry-pi-pico-waveshare-19717
esphome:
name: "danfoss-pico"
friendly_name: "danfoss-pico"
rp2040:
board: rpipicow
framework:
# Required until https://github.com/platformio/platform-raspberrypi/pull/36 is merged
platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git
# Enable logging
logger:
# Enable Home Assistant API
# api:
# encryption:
# key: "xxx"
# ota:
# password: "xxx"
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot in case wifi connection fails
ap:
ssid: "Danfoss-Pico Fallback"
password: "xxx"
time:
- platform: homeassistant
id: homeassistant_time
on_time_sync:
then:
- script.execute: set_time
uart:
- id: modbus_uart0
baud_rate: 9600
rx_pin: 1
tx_pin: 0
parity: EVEN
stop_bits: 1
debug:
modbus:
- id: modbus0
uart_id: modbus_uart0
modbus_controller:
- id: modbus_device0
address: 0x1 # address of the Modbus slave device on the bus
modbus_id: modbus0
update_interval: 3s
binary_sensor:
# - platform: modbus_controller
# name: "Control ready"
# id: control_ready
# register_type: coil
# address: 0x20
# - platform: modbus_controller
# name: "Drive ready"
# id: drive_ready
# register_type: coil
# address: 0x21
# - platform: modbus_controller
# name: "Safety closed"
# id: safety_closed
# register_type: coil
# address: 0x22
- platform: modbus_controller
name: "Alarm"
id: alarm_set
register_type: coil
address: 0x23
- platform: modbus_controller
name: "Warning"
id: warning_set
register_type: coil
address: 0x27
# - platform: modbus_controller
# name: "At reference"
# id: at_reference
# register_type: coil
# address: 0x28
# - platform: modbus_controller
# name: "Auto mode"
# id: auto_mode
# register_type: coil
# address: 0x29
# - platform: modbus_controller
# name: "In frequency range"
# id: in_freq_range
# register_type: coil
# address: 0x2A
- platform: modbus_controller
name: "Running"
id: running
register_type: coil
address: 0x2B
- platform: modbus_controller
name: "Voltage warning"
id: voltage_warning
register_type: coil
address: 0x2D
- platform: modbus_controller
name: "Current limit"
id: current_limit
register_type: coil
address: 0x2E
- platform: modbus_controller
name: "Thermal warning"
id: thermal_warning
register_type: coil
address: 0x2F
sensor:
- platform: internal_temperature
name: "Internal Temperature"
- platform: uptime
name: "Uptime"
- platform: wifi_signal
name: "Wi-Fi Signal"
update_interval: 60s
- platform: modbus_controller
id: digital_input_27
name: "Digital input 27"
register_type: holding
address: 0x13FF # 5-12 param, 5120 - 1 = 5119 dec -> hex
value_type: U_WORD
- platform: modbus_controller
id: kwh_counter
name: "kWh counter"
register_type: holding
address: 0x3AAB # 15-02 param, 15020 - 1 = 15019 dec -> hex
value_type: U_DWORD
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: modbus_controller
id: number_of_starts
name: "Number of starts"
register_type: holding
address: 0x3AE7 # 15-08 param, 15080 - 1 = 15079 dec -> hex
value_type: U_DWORD
state_class: total_increasing
- platform: modbus_controller
id: power
name: "Power"
register_type: holding
address: 0x3EE3 # 16-10 param, 16100 - 1 = 16099 dec -> hex
value_type: S_DWORD
unit_of_measurement: kW
device_class: power
state_class: measurement
accuracy_decimals: 2
filters:
- multiply: 0.01
- platform: modbus_controller
id: heatsink_temp
name: "Heatsink temperature"
register_type: holding
address: 0x3FD3 # 16-34 param, 16340 - 1 = 16339 dec -> hex
value_type: U_WORD
unit_of_measurement: C
device_class: temperature
- platform: modbus_controller
id: analog_input_54
name: "Analog input 54"
register_type: holding
address: 0x40FF # 16-64 param, 16640 - 1 = 16639 dec -> hex
value_type: S_DWORD
accuracy_decimals: 3
filters:
- multiply: 0.001
state_class: measurement
# - platform: modbus_controller
# id: current_time
# register_type: holding
# address: 0x2BB # 0-70 param, 700 - 1 = 699 dec -> hex
# value_type: U_QWORD
# lambda: |-
# // danfoss timestamp consists of 6 bytes
# // first 4 bytes are milliseconds since midnight
# unsigned long milliseconds =
# ((unsigned long)data[0] << 24) |
# ((unsigned long)data[1] << 16) |
# ((unsigned long)data[2] << 8) |
# data[3];
# // last 2 bytes are days since 1984-01-01
# unsigned int days = ((unsigned int)data[4] << 8) | data[5];
# time_t unix_timestamp = (days + 5113) * 86400 + milliseconds / 1000;
# // ESP_LOGD("Modbus Sensor Lambda","Unix timestamp: %d", unix_timestamp);
# // ESP_LOGD("Modbus Sensor Lambda","Time: %s", ESPTime::from_epoch_utc(unix_timestamp).strftime("%Y-%m-%d %H:%M:%S").c_str());
# return unix_timestamp;
text_sensor:
- platform: modbus_controller
id: datetime_readout
name: "Date and time"
register_type: holding
address: 0x379 # 0-89 param, 890 - 1 = 889 dec -> hex
response_size: 20
device_class: timestamp
- platform: wifi_info
ip_address:
name: "IP Address"
ssid:
name: "Wi-Fi SSID"
bssid:
name: "Wi-Fi BSSID"
- platform: version
name: "ESPHome Version"
hide_timestamp: false
output:
- platform: gpio
pin:
number: LED
mode: output
id: onboard_led_output
light:
- platform: binary
id: onboard_led
output: onboard_led_output
name: "Board LED"
script:
- id: set_time
then:
- lambda: |-
if (!id(homeassistant_time).now().is_valid()) {
ESP_LOGW("ModbusLambda", "ESP Time is not synchronized");
return;
}
time_t now = id(homeassistant_time).now().timestamp + ESPTime::timezone_offset();
time_t seconds_since_1984 = now - 441763200; // 441763200 is the Unix timestamp for 1984-01-01
uint16_t days_since_1984 = static_cast<uint16_t>(seconds_since_1984 / 86400);
time_t seconds_since_midnight = fmod(seconds_since_1984, 86400);
uint32_t milliseconds_since_midnight = static_cast<uint32_t>(seconds_since_midnight * 1000);
std::vector<uint16_t> payload = {
static_cast<uint16_t>(milliseconds_since_midnight >> 16),
static_cast<uint16_t>(milliseconds_since_midnight & 0xFFFF),
days_since_1984
};
modbus_controller::ModbusController *controller = id(modbus_device0);
controller->queue_command(
modbus_controller::ModbusCommandItem::create_write_multiple_command(controller, 0x2BB, 3, payload)
);
ESP_LOGI("ModbusLambda", "Set time: %d", now);
interval:
- interval: 10min
then:
- script.execute: set_time