-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjq300.yaml
128 lines (111 loc) · 2.9 KB
/
jq300.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
esphome:
name: jq300
friendly_name: jq300
on_boot:
- uart.write: "device_request_all_data\n"
esp8266:
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable logging
logger:
baud_rate: 115200
hardware_uart: uart1
# Enable Home Assistant API
api:
encryption:
key: !secret encryption_password
ota:
password: !secret api_password
external_components:
- source: github://grinco/esphome-stream-server/
uart:
id: uart_bus
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 115200
debug:
direction: BOTH
dummy_receiver: false
after:
timeout: 1s
delimiter: "\n"
sequence:
- lambda: |-
// Log the received data
uint8_t separator = ':';
UARTDebug::log_hex(direction, bytes, separator);
// Command received
if (bytes.size()==7) {
if(bytes[2]==0xF3) { ESP_LOGD("uart_bus","short press - doing nothing"); }
if(bytes[2]==0xF4) { ESP_LOGD("uart_bus","long press - doing nothing"); }
}
// Measurement received
if (bytes.size()==15) {
char buf[5];
std::string str;
// a is bytes[4-5]
sprintf(buf, "%02X", bytes[4]);
str = buf;
sprintf(buf, "%02X", bytes[5]);
str += buf;
id(a).publish_state(std::stoi(str));
// b is bytes[6-7]
sprintf(buf, "%02X", bytes[6]);
str = buf;
sprintf(buf, "%02X", bytes[7]);
str += buf;
id(b).publish_state(std::stoi(str));
// temp is bytes[8]
sprintf(buf, "%02X", bytes[8]);
id(temp).publish_state(std::atoi(buf));
// humidity is bytes[10]
sprintf(buf, "%02X", bytes[10]);
id(humidity).publish_state(std::atoi(buf));
// dust is bytes[12-13] uint16_t((bytes[12] << 8) | bytes[13] ))
sprintf(buf, "%02X", bytes[12]);
str = buf;
sprintf(buf, "%02X", bytes[13]);
str += buf;
id(pm25).publish_state(std::stoi(str));
}
stream_server:
uart_id: uart_bus
port: 10000
switch:
- platform: gpio
pin: GPIO0
name: "Blue Led"
- platform: gpio
pin: GPIO5
name: "Green Led"
sensor:
- platform: template
name: "Temperature"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 0
id: "temp"
- platform: template
name: "Humidity"
state_class: "measurement"
accuracy_decimals: 0
device_class: "humidity"
id: "humidity"
- platform: template
name: "PM2.5"
state_class: "measurement"
accuracy_decimals: 0
device_class: "pm25"
id: "pm25"
- platform: template
name: "A"
state_class: "measurement"
accuracy_decimals: 0
id: "a"
- platform: template
name: "B"
state_class: "measurement"
accuracy_decimals: 0
id: "b"