-
-
Save surt91/dde1e7986cda0177a7b790930edb7230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
esphome: | |
name: beamer_control | |
includes: | |
- uart_read_line_sensor.h | |
esp8266: | |
board: d1_mini | |
logger: | |
baud_rate: 0 | |
# Enable Home Assistant API | |
api: | |
password: "" | |
ota: | |
password: "" | |
wifi: | |
ssid: "Obi Wlan Kenobi" | |
password: "*****" | |
# Enable fallback hotspot (captive portal) in case wifi connection fails | |
ap: | |
ssid: "beamer_control" | |
password: "*****" | |
captive_portal: | |
uart: | |
id: uart_bus | |
tx_pin: 1 | |
rx_pin: 3 | |
baud_rate: 9600 | |
text_sensor: | |
- platform: custom | |
lambda: |- | |
auto my_custom_sensor = new UartReadLineSensor(id(uart_bus)); | |
App.register_component(my_custom_sensor); | |
return {my_custom_sensor}; | |
text_sensors: | |
id: "uart_readline" | |
sensor: | |
- platform: homeassistant | |
name: "AV Receiver Power sensor" | |
id: av_power | |
entity_id: sensor.tasmota_7_energy_power | |
# remote_receiver: | |
# - id: IR_Recv | |
# pin: | |
# number: D6 | |
# inverted: yes | |
# mode: INPUT_PULLUP | |
# dump: all | |
# - id: RF315_Recv | |
# pin: | |
# number: D5 | |
# inverted: yes | |
# mode: INPUT_PULLUP | |
# dump: all | |
remote_transmitter: | |
- id: RF315 | |
pin: D1 | |
carrier_duty_percent: 100% | |
- id: RF433 | |
pin: D3 | |
carrier_duty_percent: 100% | |
- id: IR | |
pin: D2 | |
# Infrared remotes use a 50% carrier signal | |
carrier_duty_percent: 50% | |
switch: | |
# beamer | |
- platform: template | |
name: "Projector Power" | |
icon: "mdi:projector" | |
lambda: |- | |
if (id(uart_readline).state == "*POW=ON#") { | |
return true; | |
} else if(id(uart_readline).state == "*POW=OFF#") { | |
return false; | |
} else { | |
return {}; | |
} | |
turn_on_action: | |
- uart.write: "\r*pow=on#\r" | |
turn_off_action: | |
- uart.write: "\r*pow=off#\r" | |
- platform: template | |
name: "Projector 3D" | |
icon: "mdi:video-3d" | |
optimistic: true | |
id: "switch3d" | |
lambda: |- | |
if(id(uart_readline).state == "*POW=OFF#") { | |
id(switch3d).publish_state(false); | |
return false; | |
} else { | |
return {}; | |
} | |
turn_on_action: | |
- uart.write: "\r*3d=tb#\r" | |
turn_off_action: | |
- uart.write: "\r*3d=off#\r" | |
# screen | |
- platform: template | |
name: Screen | |
icon: "mdi:projector-screen" | |
optimistic: true | |
turn_on_action: | |
- remote_transmitter.transmit_rc_switch_raw: | |
transmitter_id: RF315 | |
code: '000110110111100111000100' | |
protocol: 1 | |
repeat: | |
times: 10 | |
wait_time: 0s | |
- delay: 39.0s | |
- remote_transmitter.transmit_rc_switch_raw: | |
transmitter_id: RF315 | |
code: '000110110111100111001000' | |
protocol: 1 | |
repeat: | |
times: 10 | |
wait_time: 0s | |
turn_off_action: | |
- remote_transmitter.transmit_rc_switch_raw: | |
transmitter_id: RF315 | |
code: '000110110111100111000010' | |
protocol: 1 | |
repeat: | |
times: 10 | |
wait_time: 0s | |
- delay: 50s | |
- remote_transmitter.transmit_rc_switch_raw: | |
transmitter_id: RF315 | |
code: '000110110111100111001000' | |
protocol: 1 | |
repeat: | |
times: 10 | |
wait_time: 0s | |
# blinds | |
- platform: template | |
name: Wohnzimmer Jalusinen | |
icon: "mdi:roller-shade" | |
optimistic: true | |
turn_on_action: | |
- button.press: blinds_down | |
turn_off_action: | |
- button.press: blinds_up | |
# vsx531 | |
- platform: template | |
name: VSX531 Power | |
icon: "mdi:audio-video" | |
optimistic: true | |
lambda: |- | |
if (id(av_power).state > 15) { | |
return true; | |
} else if(id(av_power).state < 10) { | |
return false; | |
} else { | |
return {}; | |
} | |
turn_on_action: | |
- button.press: vsx531_on | |
turn_off_action: | |
- button.press: vsx531_off | |
button: | |
# Pioneer VSX531 | |
- platform: template | |
id: vsx531_on | |
name: VSX531 on | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA51A | |
repeat: | |
times: 2 | |
- platform: template | |
id: vsx531_off | |
name: VSX531 off | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA51B | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 BD | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA55C | |
rc_code_2: 0xA5C0 | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 CBL | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA510 | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 S.BOX | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA557 | |
rc_code_2: 0xF536 | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 Game | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA55C | |
rc_code_2: 0xA5C5 | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 CD | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA54C | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 TV | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA50C | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 Tuner | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA547 | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 USB | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA59E | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 BT | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA55C | |
rc_code_2: 0xA5C4 | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 AUX | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA54F | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 volume up | |
icon: "mdi:volume-plus" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA50A | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 volume down | |
icon: "mdi:volume-minus" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA50B | |
repeat: | |
times: 2 | |
- platform: template | |
name: VSX531 mute | |
icon: "mdi:audio-video" | |
on_press: | |
- remote_transmitter.transmit_pioneer: | |
transmitter_id: IR | |
rc_code_1: 0xA512 | |
repeat: | |
times: 2 | |
# blinds | |
- platform: output | |
id: blinds_up | |
name: Wohnzimmer Jalusinen hoch | |
icon: "mdi:roller-shade" | |
output: blinds_stube_up | |
duration: 300ms | |
- platform: output | |
id: blinds_down | |
name: Wohnzimmer Jalusinen runter | |
icon: "mdi:roller-shade" | |
output: blinds_stube_down | |
duration: 300ms | |
- platform: output | |
name: Wohnzimmer Jalusinen Kanal waehlen | |
output: blinds_stube_select_channel | |
icon: "mdi:roller-shade" | |
duration: 300ms | |
- platform: output | |
name: Wohnzimmer Jalusinen stop | |
icon: "mdi:roller-shade" | |
output: blinds_stube_stop | |
duration: 300ms | |
# screen | |
- platform: template | |
name: Screen stop | |
icon: "mdi:projector-screen" | |
on_press: | |
- remote_transmitter.transmit_rc_switch_raw: | |
transmitter_id: RF315 | |
code: '000110110111100111001000' | |
protocol: 1 | |
repeat: | |
times: 10 | |
wait_time: 0s | |
output: | |
- platform: gpio | |
id: blinds_stube_up | |
pin: D7 | |
- platform: gpio | |
id: blinds_stube_down | |
pin: D8 | |
- platform: gpio | |
id: blinds_stube_select_channel | |
pin: D5 | |
- platform: gpio | |
id: blinds_stube_stop | |
pin: D0 | |
interval: | |
- interval: 60s | |
then: | |
- uart.write: "\r*pow=?#\r" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see esphome documentation: https://esphome.io/cookbook/uart_text_sensor.html | |
#include "esphome.h" | |
class UartReadLineSensor : public Component, public UARTDevice, public TextSensor { | |
public: | |
UartReadLineSensor(UARTComponent *parent) : UARTDevice(parent) {} | |
void setup() override { | |
// nothing to do here | |
} | |
int readline(int readch, char *buffer, int len) | |
{ | |
static int pos = 0; | |
int rpos; | |
if (readch > 0) { | |
switch (readch) { | |
case '\n': // Ignore new-lines | |
break; | |
case '\r': // Return on CR | |
rpos = pos; | |
pos = 0; // Reset position index ready for next time | |
return rpos; | |
default: | |
if (pos < len-1) { | |
buffer[pos++] = readch; | |
buffer[pos] = 0; | |
} | |
} | |
} | |
// No end of line has been found, so return -1. | |
return -1; | |
} | |
void loop() override { | |
const int max_line_length = 80; | |
static char buffer[max_line_length]; | |
while (available()) { | |
if(readline(read(), buffer, max_line_length) > 0) { | |
publish_state(buffer); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment