Media Player Struggles: NAD Receiver

I’m trying to use the NAD integration with RS232 but I’m having a lot of troubles with it. Install and detect works perfectly fine, can switch the device on & off, but volume up & down is extremely sluggish (5sec delay) and selecting source doesn’t work at all. I do get some errors in my log (see below).
Serial commands are quite universal between NAD models, so at least these simple commands should work with any NAD receiver. Searching around for solutions (most info is TCP related, instead of RS232) doesn’t give me any clues.

Is there anyone who can help me with a solution ?

Home Assistant Core 2021.7.4
NAD M32 Receiver / RS232

Config:

# NAD Amp
- platform: nad
  name: NAD Amp
  serial_port: /dev/ttyS2
  min_volume: -60
  max_volume: -20
  sources:
    1: "TV"
    2: "KODI USB"
    3: "KODI HDMI"

Log:

2021-07-26 12:42:58 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140568163409056] can only concatenate str (not "int") to str

Traceback (most recent call last):

File "/opt/hass/lib/python3.9/site-packages/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service

await hass.services.async_call(

File "/opt/hass/lib/python3.9/site-packages/homeassistant/core.py", line 1491, in async_call

task.result()

File "/opt/hass/lib/python3.9/site-packages/homeassistant/core.py", line 1526, in _execute_service

await handler.job.target(service_call)

File "/opt/hass/lib/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 213, in handle_service

await self.hass.helpers.service.entity_service_call(

File "/opt/hass/lib/python3.9/site-packages/homeassistant/helpers/service.py", line 658, in entity_service_call

future.result() # pop exception if have

File "/opt/hass/lib/python3.9/site-packages/homeassistant/helpers/entity.py", line 811, in async_request_call

await coro

File "/opt/hass/lib/python3.9/site-packages/homeassistant/helpers/service.py", line 695, in _handle_entity_call

await result

File "/opt/hass/lib/python3.9/site-packages/homeassistant/components/media_player/__init__.py", line 701, in async_select_source

await self.hass.async_add_executor_job(self.select_source, source)

File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run

result = self.fn(*self.args, **self.kwargs)

File "/opt/hass/lib/python3.9/site-packages/homeassistant/components/nad/media_player.py", line 161, in select_source

self._nad_receiver.main_source("=", self._reverse_mapping.get(source))

File "/opt/hass/lib/python3.9/site-packages/nad_receiver/__init__.py", line 117, in main_source

source = self.exec_command('main', 'source', operator, value)

File "/opt/hass/lib/python3.9/site-packages/nad_receiver/__init__.py", line 46, in exec_command

cmd = cmd + value

TypeError: can only concatenate str (not "int") to str

having a similar issue with my T778, I can change the volume fine but I can’t switch sources, and I get the same TypeError: can only concatenate str (not "int") to str… following

Have you tried with the underlying library? GitHub - joopert/nad_receiver: python api to connect to NAD receivers

I’m having the same issue as well. It looks like the latest version of the library listed above (0.2.0) fixes the issue via this line of code in __init__.py:

source = self.exec_command('main', 'source', operator, str(value))

However, the latest version of HA (2021.7.4) is using an older version of this component, according to my error log entries:

source = self.exec_command('main', 'source', operator, value)

I think this has been broken since 2021.7, and it seems like it would be a simple fix.

2021.7.4 uses the 0.2.0 version of the library.

Yes, the manifest.json of the NAD component does say it is using 0.2.0, but the stack trace I’m seeing in the logs doesn’t match with the code in version 0.2.0. The log entries in my HA instance are missing the usage of the str() function to mitigate the can only concatenate str (not "int") to str errors.

Line 117 of nad_receiver/__init__.py for version 0.2.0 should be:

source = self.exec_command('main', 'source', operator, str(value))

However, the following log entries in my HA instance are showing otherwise:

  File "/usr/local/lib/python3.9/site-packages/nad_receiver/__init__.py", line 117, in main_source
    *source = self.exec_command('main', 'source', operator, value)
  File "/usr/local/lib/python3.9/site-packages/nad_receiver/__init__.py", line 46, in exec_command
    cmd = cmd + value
TypeError: can only concatenate str (not "int") to str

Pip will tell you what version of the library you have

pip list|grep nad_receiver

It does report 0.2.0…although I had to use:

pip list|grep nad-receiver

Note the dash instead of underscore.

I wonder why the stack trace in my logs do not match with the code in version 0.2.0 of nad-receiver? I’m very confused.

yes sorry…

Ahhhh…I now see the problem. After reexamining nad_receiver version 0.2.0, it was tagged on 12/22/2020 before the change to add str(), which was added on 12/29/2020:

My bad…sorry for the confusion folks! So it looks like was need a new tagged version of this to be integrated into HA.

I don’t have a nad so I can’t try it, but you can manually change the python in home assistant for testing.

weird, pip list or pip freeze don’t show that package for me at all (nad_receiver nor nad-receiver). Also tried searching in site-packages and can’t find it either. Yet the integration is installed and (mostly) working? Sorry, I’m new to Home Assistant, trying to piece everything together. Where can I find and edit the __init__.py file? Or should I manually install the python library parallel to the config.yaml change I did to enable the integration?

Thanks!

I looked into the reply of @uncle_sketchy and manually updated the integration from the (latest) git repo

Looks promising, the errors are gone, still some funky stuff going on, but that might be my receiver type, my config or my stupidity. I can now (for some inputs) change source, no complains from HA anymore.

sorry to be so pesky, but how do I manually update the integration from the python code? I couldn’t get it through HACS (as expected I guess). Did you originally set it up using these instructions? Still learning all of this so appreciate any help, thanks.

You have to manually dig into your filesystem somehow, so get a shell into your HA system and change the file/folder. As of uncle’s report, it’s just a single line in a single file. I didn’t look into it in detail, so I just dumped the complete “nad_receiver” folder from the github repo.

Do something like this to find your location of the integration in your filesytem:

find / -name "nad_receiver"

I think I’m having some weird python version management issue. When I run that code (or pip freeze for that matter) I don’t find anything. My error trace looks like this:

2021-08-04 22:45:21 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547743517184] can only concatenate str (not "int") to str
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1491, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1526, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 856, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 708, in async_select_source
    await self.hass.async_add_executor_job(self.select_source, source)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/nad/media_player.py", line 161, in select_source
    self._nad_receiver.main_source("=", self._reverse_mapping.get(source))
  File "/usr/local/lib/python3.9/site-packages/nad_receiver/__init__.py", line 117, in main_source
    source = self.exec_command('main', 'source', operator, value)
  File "/usr/local/lib/python3.9/site-packages/nad_receiver/__init__.py", line 46, in exec_command
    cmd = cmd + value
TypeError: can only concatenate str (not "int") to str

however when I SSH into home assistant I can only find python in /usr/lib/python3.9, not /usr/local/lib/python3.9 as in the log. So in other words I don’t seem to be able to access the python filesystem that is actually being used by the integration, when I SSH into home assistant. I know I’ve been in a similar python version hell before, but I don’t remember how to get out.

I know this is completely out of scope from the original question, but any suggestions are appreciated. thanks.

In the meantime I posted this issue Tag a new release? · Issue #51 · joopert/nad_receiver · GitHub

2 Likes

Thanks for posting that comment on the joopoert/nadreceiver git repo, @nickrout.

As a quick and dirty workaround for the past month, I’ve been using this really hacky solution to switch my TV input source on my NAD C388:

switch:
  - platform: telnet
    switches:
      nad_input_television:
        resource: 192.168.x.x
        port: 23
        command_on: "\r\nMain.Source=1\r\n"
        command_off: "\r\nMain.Sources?\r\n"

It’s basically using the telnet platform to send the command to switch to input 1 on my receiver. The command_off value doesn’t really do anything, but I added it anyway because it’s a required field.

1 Like

Thanks @uncle_sketchy that worked for me, I’ll use that until if an update happens!

Looks like there’s a new 0.3.0 version!