esphome:
name: mediaroom-bridge
includes:
- uart_read_line_sensor.h
logger:
level: DEBUG #makes uart stream available in esphome logstream
baud_rate: 0 #disable logging over uart
uart:
id: uart_bus
tx_pin: D4
rx_pin: RX
baud_rate: 19200
text_sensor:
- platform: custom
lambda: |-
auto uart_sensor = new UartReadLineSensor();
App.register_component(uart_sensor);
return {uart_sensor};
text_sensors:
- id: uart_readline
on_value:
then:
- lambda: |-
std::string value = x;
// 检查字符串是否以0xBE, 0xEF等开始,并根据最后一个字节确定状态
if (value.size() >= 26 && value.substr(0, 22) == "0xBE, 0xEF, 0x03, 0x06, 0x00, 0x19, 0xD3, 0x02, 0x00, 0x00, 0x60") {
uint8_t last_byte = strtol(value.substr(24, 2).c_str(), nullptr, 16);
if (last_byte == 0x01) {
id(projector_power).publish_state(true);
} else if (last_byte == 0x00 || last_byte == 0x02) {
id(projector_power).publish_state(false);
}
}
switch:
- platform: template
name: "HITACHI Projector"
id: projector_power
# assumed_state: True
turn_on_action:
- uart.write: [0xBE, 0xEF, 0x03, 0x06, 0x00, 0xBA, 0xD2, 0x01, 0x00, 0x00, 0x60, 0x01, 0x00]
turn_off_action:
- uart.write: [0xBE, 0xEF, 0x03, 0x06, 0x00, 0x2A, 0xD3, 0x01, 0x00, 0x00, 0x60, 0x00, 0x00]
interval:
- interval: 10s
then:
- uart.write: [0xBE, 0xEF, 0x03, 0x06, 0x00, 0x19, 0xD3, 0x02, 0x00, 0x00, 0x60, 0x00, 0x00]
esp8266:
board: d1_mini
web_server:
port: 80
# Enable Home Assistant API
api:
ota:
- platform: esphome
wifi:
ssid: "XXXX"
password: "XXXXXXXX"
fast_connect: True
manual_ip:
static_ip: 192.168.1.1
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Mediaroom-Bridge"
password: "XXXXXXXX"
captive_portal: