-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprojector.yaml
164 lines (132 loc) · 3.94 KB
/
projector.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
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
esphome:
name: master-bedroom-projector
includes:
- uart_read_line_sensor.h
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable UART. Please select the pins you're using on your board.
uart:
id: projector
tx_pin: GPIO19
rx_pin: GPIO18
baud_rate: 9600
# Enable Home Assistant API
api:
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: !secret wifi_captive_ssid
password: !secret wifi_captive_password
captive_portal:
# This is our hub - it manages our connection to the projector.
text_sensor:
- platform: custom
lambda: |-
auto my_custom_sensor = new UartReadLineSensor(id(projector));
App.register_component(my_custom_sensor);
return {my_custom_sensor};
text_sensors:
id: "uart_readline"
on_value:
then:
- lambda: |-
// Clean up the end of the string
std::string str = x;
str = str.erase(str.size()-1, 1);
// Parse commands and values
std::string command = str.substr(1, str.find("=")-1);
std::string param = str.substr(str.find("=")+1, str.size());
if ((param == "?") || (param == "+") || (param == "-")){
return;
}
if (command == "VOL") {
id(projector_volume).publish_state(atoi(param.c_str()));
} else if (command == "LTIM") {
id(projector_ltim).publish_state(atoi(param.c_str()));
} else if (command == "POW") {
id(projector_power).publish_state(param == "ON");
} else if (command == "SOUR") {
id(projector_source).publish_state(param.c_str());
}
select:
- platform: template
name: Projector Source
id: projector_source
# Change this to the inputs your projector has
options:
- HDMI1
- HDMI2
- USBREADER
set_action:
then:
- lambda: |-
if ((x) != id(projector_source).state) {
std::string c = "\r*SOUR=" + x + "#\r";
id(projector).write_array((const uint8_t*)c.c_str(), c.size());
id(projector_source).publish_state(x);
}
number:
- platform: template
id: projector_volume
step: 1
min_value: 0
max_value: 50
name: "Projector Volume"
set_action:
then:
- lambda: |-
int target = round(x);
int current = id(projector_volume).state;
int delta = target - current;
for (int i=0; i<abs(delta);i++) {
std::string c = "";
if (delta < 0) {
c = "\r*vol=-#\r";
}
else if (delta > 0){
c = "\r*vol=+#\r";
}
else {
// nothing
}
if (c != "") {
id(projector).write_array((const uint8_t*)c.c_str(), c.size());
}
}
id(projector_volume).publish_state(target);
sensor:
- platform: template
name: "Projector Lamp Hours"
id: projector_ltim
switch:
- platform: template
name: "Projector Power Status"
id: projector_power
turn_on_action:
- uart.write: "\r*pow=on#\r"
turn_off_action:
- uart.write: "\r*pow=off#\r"
interval:
- interval: 10s # not pretty, but works
then:
- uart.write: "\r*pow=?#\r"
- delay: 1s
- if:
condition:
lambda: 'return id(projector_power).state;'
then:
- uart.write: "\r*sour=?#\r"
- delay: 1s
- uart.write: "\r*vol=?#\r"
- delay: 1s
- uart.write: "\r*ltim=?#\r"
else:
- logger.log: "Projector is OFF"