forked from nuttytree/ESPHome-Devices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master-bed.yaml
125 lines (118 loc) · 3.72 KB
/
master-bed.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
substitutions:
device_id: master-bed
device_name: Master Bed
board: nodemcuv2
ip_address: !secret master-bed-ip
ota_pwd: !secret master-bed-ota-pwd
api_key: !secret master-bed-key
ap_wifi_pwd: !secret master-bed-ap-pwd
packages:
device_base: !include ./packages/device_base_esp8266.yaml
esphome:
includes:
- ./custom/bed_sensor.h
binary_sensor:
- platform: template
name: "Melissa is in Bed"
id: melissa_in_bed
device_class: occupancy
on_state:
then:
- sensor.template.publish:
id: master_bed_count
state: !lambda 'return id(melissa_in_bed).state + id(chris_in_bed).state + id(someone_in_bed).state;'
- platform: template
name: "Chris is in Bed"
id: chris_in_bed
device_class: occupancy
on_state:
then:
- sensor.template.publish:
id: master_bed_count
state: !lambda 'return id(melissa_in_bed).state + id(chris_in_bed).state + id(someone_in_bed).state;'
- platform: template
name: "Someone is in Bed"
id: someone_in_bed
device_class: occupancy
on_state:
then:
- sensor.template.publish:
id: master_bed_count
state: !lambda 'return id(melissa_in_bed).state + id(chris_in_bed).state + id(someone_in_bed).state;'
sensor:
- platform: custom
lambda: |-
auto bedSensor = new BedSensor();
App.register_component(bedSensor);
return {bedSensor->melissaBedSensor, bedSensor->chrisBedSensor};
sensors:
- name: "Melissa Bed Sensor"
id: melissa_bed_sensor
on_value:
then:
- sensor.template.publish:
id: melissa_bed_percent
state: !lambda 'return (1024 - x) / 1024 * 100;'
- name: "Chris Bed Sensor"
id: chris_bed_sensor
on_value:
then:
- sensor.template.publish:
id: chris_bed_percent
state: !lambda 'return (1024 - x) / 1024 * 100;'
- platform: template
name: "Melissa Bed Percent"
id: melissa_bed_percent
icon: "mdi:bed"
unit_of_measurement: "%"
accuracy_decimals: 0
on_value:
then:
- binary_sensor.template.publish:
id: melissa_in_bed
state: !lambda 'return x > 75;'
- binary_sensor.template.publish:
id: someone_in_bed
state: !lambda 'return x <= 75 && !id(chris_in_bed).state && x > 40 && id(chris_bed_percent).state > 40;'
- platform: template
name: "Chris Bed Percent"
id: chris_bed_percent
icon: "mdi:bed"
unit_of_measurement: "%"
accuracy_decimals: 0
on_value:
then:
- binary_sensor.template.publish:
id: chris_in_bed
state: !lambda 'return x > 75;'
- binary_sensor.template.publish:
id: someone_in_bed
state: !lambda 'return !id(melissa_in_bed).state && x <= 75 && id(melissa_bed_percent).state > 40 && x > 40;'
- platform: template
name: "Master Bed Count"
id: master_bed_count
accuracy_decimals: 0
icon: "mdi:bed"
on_value:
then:
- text_sensor.template.publish:
id: master_bed_status
state: !lambda |-
if (x == 0) {
return "Empty";
} else if (x == 2) {
return "Melissa and Chris";
} else if (id(melissa_in_bed).state) {
return "Melissa";
} else if (id(chris_in_bed).state) {
return "Chris";
} else if (id(someone_in_bed).state) {
return "Someone";
} else {
return "Unknown";
}
text_sensor:
- platform: template
name: "Master Bed Status"
id: master_bed_status
icon: "mdi:bed"