-
Notifications
You must be signed in to change notification settings - Fork 1
/
Inkbird_IHT_2PB.yaml
109 lines (102 loc) · 3.7 KB
/
Inkbird_IHT_2PB.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
ble_client:
- mac_address: !secret ble_mac_address
id: inkbird_IHT_2PB_ble
on_connect:
then:
- lambda: |-
ESP_LOGD("ble_client_lambda", "Connected to BLE device");
id(inkbird_IHT_2PB_connected).publish_state(true);
# on_connect is triggered before the device is fully connected see https://github.com/esphome/issues/issues/4153
# But even with a 10ms delay it doesn't seem to work. So the solution is to add a button that is pressed and start the script to activate
# the notifications. This also allows the user to force the notifications manually.
- button.press: inkbird_IHT_2PB_notification
on_disconnect:
then:
- lambda: |-
ESP_LOGD("ble_client_lambda", "Disconnected from BLE device");
id(inkbird_IHT_2PB_connected).publish_state(false);
script:
- id: activate_temperature_notifications
then:
- ble_client.ble_write:
id: inkbird_IHT_2PB_ble
service_uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
characteristic_uuid: 0000ffe9-0000-1000-8000-00805f9b34fb
value: [0x55, 0xAA, 0x19, 0x01, 0x00, 0x19]
- ble_client.ble_write:
id: inkbird_IHT_2PB_ble
service_uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
characteristic_uuid: 0000ffe4-0000-1000-8000-00805f9b34fb
value: [0x55, 0xAA, 0x1A, 0x01, 0x00, 0x1A]
# We get the error "Characteristic 0000FFE4-0000-1000-8000-00805F9B34FB does not allow writing"
# but this write is necessary to get temperature notifications
switch:
- platform: ble_client
ble_client_id: inkbird_IHT_2PB_ble
name: "Inkbird IHT-2PB enable"
button:
- platform: template
id: inkbird_IHT_2PB_notification
name: "Inkbird IHT-2PB notification"
on_press:
- script.execute: activate_temperature_notifications
binary_sensor:
- platform: template
name: "Inkbird IHT-2PB connected"
id: inkbird_IHT_2PB_connected
icon: mdi:bluetooth-connect
sensor:
- platform: template
name: "Inkbird IHT-2PB probe manual"
id: inkbird_IHT_2PB_probe0
icon: mdi:thermometer-probe
unit_of_measurement: "°C"
accuracy_decimals: 1
device_class: "temperature"
state_class: "measurement"
- platform: template
name: "Inkbird IHT-2PB probe 1"
id: inkbird_IHT_2PB_probe1
icon: mdi:thermometer-probe
unit_of_measurement: "°C"
accuracy_decimals: 1
device_class: "temperature"
state_class: "measurement"
- platform: template
name: "Inkbird IHT-2PB probe 2"
id: inkbird_IHT_2PB_probe2
icon: mdi:thermometer-probe
unit_of_measurement: "°C"
accuracy_decimals: 1
device_class: "temperature"
state_class: "measurement"
- platform: ble_client
ble_client_id: inkbird_IHT_2PB_ble
type: characteristic
name: "Inkbird IHT-2PB last probe data"
service_uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
characteristic_uuid: 0000ffe4-0000-1000-8000-00805f9b34fb
notify: true
lambda: |-
if (x[2] != 2 && x[2] != 4 && x[2] != 6) {
return -1.0;
}
uint8_t probeNr = x[2] / 2 - 1;
float temperature;
if (x[4] >= 254) {
// negative
temperature = (float) ((255 * (x[4] - 255)) + (x[5]-255)) / 10;
} else if (x[4] <= 11){
//positive
temperature = (float) ((255 * x[4]) + x[5]) / 10;
} else {
return -1.0;
}
if (probeNr == 0) {
id(inkbird_IHT_2PB_probe0).publish_state(temperature);
} else if (probeNr == 1) {
id(inkbird_IHT_2PB_probe1).publish_state(temperature);
} else if (probeNr == 2) {
id(inkbird_IHT_2PB_probe2).publish_state(temperature);
}
return (float)probeNr;