Need help with ESPHome, Denon UART Control

Hi, right now I’m trying to integrate my denon rs232 control into esphome.
The current state is a custom arduino app with rest calls, and some additional home assistant config for a volume slider etc.

I’ve read for esphome i can use the uart platform for rs232 communication.
What I already have would be switching inputs via uart.

What I want to do is to create a light in esphome
Use On/Off for switching on/off my denon
and using the brightness slider of the light for writing volume values via uart
If that is somehow possible. (I guess this would be the only option for a custom slider control via esphome atm)
The light component in esphome has no uart. So I assume I would have to do something with an automation, when light is one eg write something to uart !?
Does anyone have any ideas how I could implement this?

Current Code

`esphome:
  name: denon
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

logger:

api:
  reboot_timeout: 0s
  password: !secret password

ota:
  password: !secret password
  

# Example configuration entry
uart:
  baud_rate: 9600
  tx_pin: D0

switch:
  - platform: uart
    name: "Power On"
    data: 'PWON\r'
  
  - platform: uart
    name: "Power Off"
    data: 'PWSTANDBY\r'
    
  - platform: uart
    name: "CD"
    data: 'SICD\r'
    
  - platform: uart
    name: "DVD"
    data: 'SIDVD\r'
    
  `

That one is the volume mapping in the old code

 httpServer.on("/Denon/Volume",HTTP_GET,[](){
    int message = 20;
    if(!(httpServer.arg("MV")== "")){  
      message = atoi(httpServer.arg("MV").c_str());     //Gets the value of the query parameter
      //Save value
      if((message >= 20)&&(message <=60)){
        Serial.print("MV"+String(message)+"\r");
      }
    }  
    httpServer.send(200, "text/plain", "OK");   
  });

Only the brightness slider for volume is missing now. However no idea how to do this

esphome:
  name: denon
  platform: ESP8266
  board: d1_mini_lite

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

api:
  reboot_timeout: 0s
  password: !secret password

logger:
  baud_rate: 0
  
ota:
  password: !secret password
  

# Example configuration entry
uart:
  baud_rate: 9600
  tx_pin: GPIO01

switch:
  - platform: uart
    name: "CD"
    data: "SICD\r"
    
  - platform: uart
    name: "DVD"
    data: "SIDVD\r"
    

output:
  - id: light_output
    platform: gpio
    pin: GPIO16

light:
    platform: binary
    output: light_output
    name: PowerSwitch
    on_turn_on:
      - uart.write: "PWON\r"
    on_turn_off:
      - uart.write: "PWSTANDBY\r"

I think you are looking for this Universal Media Player - Home Assistant

Thanks. That looks good for the next step. Right now I still struggle to get proper volume controls via uart. Basically I’m looking for some kind of interval mapping

Over Uart I have to send MV for the volume
In the example code above (old app, not esphome) I have set a custom range that goes from 20 to 60 where I set a value inbetween via rest call.

In Esphome I want something like:

When brightness of lightbulb changes, get the percentage e.g
50%
that would be (60-20)*0,5 + 20 = 40 as volume (so MV40 via uart)
when having e.g 60% volume → (60-20)*0,6 + 20 = 44 as volume
Then write the value I’ve got this way via uart.

Maybe this is somehow doable via custom light platform

It has nothing to do with ligjts.

I sadly didn’t get the lightbulb brightness slider working for volume controls, the functionality is now on simple switches. But yeah it works for use in automations.
In case anyone needs it, here’s the code

esphome:
  name: denon
  platform: ESP8266
  board: d1_mini_lite

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

api:
  reboot_timeout: 0s
  password: !secret password

logger:
  baud_rate: 0
  
ota:
  password: !secret password
  

# Example configuration entry
globals:
   - id: volume_value
     type: int
     restore_value: yes
     initial_value: '40'
     
uart:
  baud_rate: 9600
  tx_pin: GPIO01

switch:
  - platform: uart
    name: "CD"
    data: "SICD\r"
    
  - platform: uart
    name: "DVD"
    data: "SIDVD\r"
    
  - platform: template
    name: "Volume Up"
    turn_on_action:
      - uart.write: !lambda |-
            if (id(volume_value) < 60) {
              id(volume_value) += 4;
              if(id(volume_value) > 60)
                id(volume_value) = 60;
            }
            char buf[128];
            sprintf(buf, "MV%d\r", id(volume_value));
            std::string s = buf;
            return std::vector<unsigned char>( s.begin(), s.end() );
  - platform: template
    name: "Volume Down"
    turn_on_action:
      - uart.write: !lambda |-
            if (id(volume_value) > 20) {
              id(volume_value) -= 4;
              if(id(volume_value) < 20)
                id(volume_value) = 20;
            }
            char buf[128];
            sprintf(buf, "MV%d\r", id(volume_value));
            std::string s = buf;
            return std::vector<unsigned char>( s.begin(), s.end() );

output:
  - id: light_output
    platform: gpio
    pin: GPIO16

light:
    platform: binary
    output: light_output
    name: PowerSwitch
    on_turn_on:
      - uart.write: "PWON\r"
    on_turn_off:
      - uart.write: "PWSTANDBY\r"

1 Like

Get the device set up as a media_player and you will get your volume controls.

Can you give more details on how you have the AVR wired up. I can read status from a Denon AVR but cannot Write. I have read in places that pin one on the rs232 needs to be grounded to the chassis.

Think I got it sort for the PC just had to keep the rs232 plug in and unplug and plug the amp power in

Have you ever got it to work ? I currently have a raspberry pi with a usb to rs232 cable connected via node-RED and MQTT which works like a charm. But would be great to remove the complexity and only use a ESP32