Serial Projector control with ESPHome

I’m hearing you. My next project is to “smartify” my dehumidifiers. Crossing my fingers that the control board is 3.3V logic. :crossed_fingers:

A small breadboard, a couple resistors and you’re good to go - if you can find room to tuck it in there securely of course! Funny you mention the dehumidifier, I’ve been thinking of doing the same thing but on my humidifier (I live in a very arid climate) - and I know there is low voltage because it uses an LED light to light the tank, which is on by default unless toggled off, so bonus is I won’t have to toggle it off anymore when I fire up the humidifier.

I’ll solder it to Veroboard rather than using a breadboard - for vibration/shock security of the connections. Hoping I don’t have to use loads of optocouplers.

1 Like

Just set this up for a TV that can be controlled via RS232. Had the components already. Thanks for the good write up.

1 Like

I have a similar setup for an optoma projector using RS232 and smart power switch if this is useful to anyone…

1 Like

@tom_l
You got me thinking that mode: queued might be useful for your application (and wouldn’t need an input_boolean to serve as a “busy” flag).

If you create a script like this:

projector:
  mode: queued
  variables:
    commands:
      iris: "KEY A5\r\n"
      menu: "KEY 03\r\n"
  sequence:
    - service: esphome.projector_uart_write
      data:
        command: "{{ commands.get(command, 'ERROR\r\n') }}"
    - delay: 1

You can call it like this:

- service: script.projector
  data:
    command: 'iris'

Or like this if you want a non-blocking call:

    service: script.turn_on
    target:
      entity_id: script.projector
    data:
      variables:
        command: 'iris'

While the script is busy processing the ‘iris’ command, any subsequent calls to the same script are placed in a queue and will be processed in the order they’re received.

1 Like

Nice. I’ll do that. Thanks.

Though I don’t want to send anything in case the command is not found, so I’ll think of something for that.

Also this puts a spanner in the works:

projector_off:
  sequence:
  - condition: state
    entity_id: input_boolean.uart_busy
    state: 'off'
  - service: input_boolean.turn_on
    entity_id: input_boolean.uart_busy
  - service: esphome.projector_uart_write
    data:
      command: "PWR OFF\r\n"
  - delay: 10
  - service: input_boolean.turn_off
    entity_id: input_boolean.uart_busy

projector_on:
  sequence:
  - condition: state
    entity_id: input_boolean.uart_busy
    state: 'off'
  - service: input_boolean.turn_on
    entity_id: input_boolean.uart_busy
  - service: esphome.projector_uart_write
    data:
      command: "PWR ON\r\n"
  - delay: 40
  - service: input_boolean.turn_off
    entity_id: input_boolean.uart_busy

Theoretically I should not send another command after issuing the power command for 30 seconds, though in practice I’ve found that 10 works for off and 40 for on.

I’m going to move these posts to my project topic to prevent cluttering up this FR.

Improved version:

projector:
  mode: queued
  variables:
    commands:
      iris: 
        - "KEY A5\r\n"
        - 1
      menu:
        - "KEY 03\r\n"
        - 1
      on:
        - "PWR ON\r\n"
        - 40
      off:
        - "PWR OFF\r\n"
        - 10
    cmd: "{{ commands.get(command, none) }}"
  sequence:
    - condition: "{{ cmd is not none }}"
    - service: esphome.projector_uart_write
      data:
        command: "{{ cmd[0] }}"
    - delay: "{{ cmd[1] }}"
1 Like

Thanks for this writeup!

I’m going to try and adapt this to control my Samsung TV via its EXLink connector.

I am currently controlling it via ser2net, and a flask/rest container, Moving to a ESPHome device will help free up that RasPi.

I have been trying to get serial control to work with Home Assistant and I have somehow missed this post. Can a similar setup be used for RS485? And what would be the method to receive feedback?

You would need an RS485 to 3.3V TTL line driver / receiver. Then sending commands could be done the same way.

Not sure about the feedback. It would probably require a custom component.

1 Like

I’m unable to get this to work.

I dont care about the feedback and LED indicators at the moment. I just want to be able to send PWR ON for power on and PWR OFF for off, for the time being, preferably without any scripts etc if possible. Can someone help me simplify the esp code? I am unable to adapt the above for my simple use.

What strings to you have to send to your projector for the on and off commands?

Its an Epson EH-TW7100.

I found this document online https://files.support.epson.com/pdf/pltw1_/pltw1_cm.pdf

Based on that I think I need to send
PWR ON
PWR OFF

Then the simplest way would be with a template switch in ESPHome:

uart:
  tx_pin: GPIO12  # Change these settings as needed.
  rx_pin: GPIO32
  baud_rate: 9600
  id: projector_uart

switch:
  - platform: template
    name: "Projector Power"
    optimistic: true
    turn_on_action:
      - uart.write:
          id: projector_uart
          data: 'PWR ON\r\n'
    turn_off_action:
      - uart.write:
          id: projector_uart
          data: 'PWR OFF\r\n'
1 Like

Below is the uart section of my esphome

uart:
  tx_pin: GPIO17  
  rx_pin: GPIO16
  baud_rate: 9600
  id: projector_uart

switch:
  - platform: template
    name: "Projector Power"
    optimistic: true
    turn_on_action:
      - uart.write:
          id: projector_uart
          data: 'PWR ON\r\n'
    turn_off_action:
      - uart.write:
          id: projector_uart
          data: 'PWR OFF\r\n'

It creates a switch on the dashboard that I can turn on and off

My physical connections are as below. I even tried inverting the tx and rx connection on the 232 to TTL connector. But the projector does not respond to the commands :frowning:


Hook your rs232 converter up to a serial port on a PC, a USB to serial adaptor is fine if your PC does not have a physical serial port.

Open a terminal on your PC (e.g. Putty), connect to the comm port, 9600 baud 8/N/1.

Turn your switch on and off.

Do you see the commands printed in the terminal?

To anyone who tries this and fails (like I just did). You must use double quotes when you want ESPHome’s uart component to interpret special charaters in the data field correctly. This is explained here. And yes, you find this out using the method that tom_l suggested.

I have tested the code below and it works with an Epson EMP-TW700 projector. It should work with any ESP/VP21 protocol projector (as e.g. listed here)

uart:
  tx_pin: 39  # Change these settings as needed.
  rx_pin: 37
  baud_rate: 9600
  id: projector_uart

switch:
  - platform: template
    name: "Projector Power"
    assumed_state: True
    optimistic: True
    turn_on_action:
      - uart.write:
          id: projector_uart
          data: "PWR ON\r\n"
    turn_off_action:
      - uart.write:
          id: projector_uart
          data: "PWR OFF\r\n"

Also, I suggest adding assumed_state: True to the switch. This is the correct way of handling switches that do not have a feedback. The switch icon becomes a lightning bolt, and you can turn the projector on or off multiple times without having to toggle the switch (e.g. when you forget to switch on the mains or you use the remote as well).

Cheers, AndBu

2 Likes

I have feedback.

You might too. It comes from the screen trigger output.

With the code below, the LED on the MAX3232 flashes when I turn the switch on/ off from HA. But the projector (Epson Home Cinema 3200) does not respond. So I guess the communication upto the projector is ok? Unable to think of what to do next.

uart:
  tx_pin: GPIO1  # Change these settings as needed.
  rx_pin: GPIO3
  baud_rate: 9600
  id: projector_uart

switch:
  - platform: template
    name: "Projector Power"
    optimistic: true
    turn_on_action:
      - uart.write:
          id: projector_uart
          data: "PWR ON\r\n"
    turn_off_action:
      - uart.write:
          id: projector_uart
          data: "PWR OFF\r\n"

I also tried hooking my PC with Putty on it to the projector. I connected a USB TTL device to my laptop. Tx to the MAX3232 Rx and vice versa. Selected my COM port and opened the putty window but the blank putty window that opened wouldnt let me type anything into it.