Recently I’ve been playing with Home Assistant (Hassio) to have a single pane of all my smart home devices (Zigbee, Z-Wave and IP devices) without having to switch apps to control different devices. One of the major advantages of using home assistant is the plethora of customizations available which can even extend to Google Home and Amazon Alexa. This post will assume you’re already familiar with Home Assistant and focuses on the Home Theater Direct (HTD) integration with the model MCA66. This should work similar with the Lync model by changing the hex codes which is available from HTD.
Most of the code seen here found on different GitHub repositories, but none were specific to my application. They either used Serial communication, or an additional web service and leverages REST api.
- https://github.com/whitingj/mca66
- https://github.com/steve28/mca66
For my use case, I only went as far as creating on/off and volume sliders for 4 zones. I use the home assistant Sonos integration for selecting music and sources. The code could be cleaned up as well but haven’t found the time yet.
Instructions
- Download mca66.py, htd.py, htdquery.py, zones_list.txt, and sources_list.txt and place them into the root of the /config directory of your HA server.
- Inside mca66.py, change the IP address to your GW-SL1 in two functions
- send_command
- send_command_returndetail
- Inside zones_list.txt and sources_list.txt; adjust the values accordingly
- Enter the following information into your configuration.yaml to create the on/off switches. Be sure the formatting is correct when copying and pasting.
platform: command_line
switches:
#Zone1 - Master Bedroom
#Zone2 - Garage
#Zone3 - 1st Floor
#Zone4 - 2nd Floor
htd_masterbedroom:
command_on: "python3 /config/htd.py pwr 1 1"
command_off: "python3 /config/htd.py pwr 1 0"
friendly_name: "Master Bedroom"
value_template: "{{ value == 'on' }}"
command_state: "python3 /config/htdquery.py querypwr 1 0"
htd_firstfloor:
command_on: "python3 /config/htd.py pwr 3 1"
command_off: "python3 /config/htd.py pwr 3 0"
friendly_name: "First Floor"
value_template: "{{ value == 'on' }}"
command_state: "python3 /config/htdquery.py querypwr 3 0"
htd_secondfloor:
command_on: "python3 /config/htd.py pwr 4 1"
command_off: "python3 /config/htd.py pwr 4 0"
friendly_name: "Second Floor"
value_template: "{{ value == 'on' }}"
command_state: "python3 /config/htdquery.py querypwr 4 0"
htd_garage:
command_on: "python3 /config/htd.py pwr 2 1"
command_off: "python3 /config/htd.py pwr 2 0"
friendly_name: "Garage"
value_template: "{{ value == 'on' }}"
command_state: "python3 /config/htdquery.py querypwr 2 0"
- If you want to customize the icons to match my screen shot, add the following homeassistant/customize section of configuration.yaml
switch.htd_garage:
icon: mdi:speaker
assumed_state: false
switch.htd_masterbedroom:
icon: mdi:speaker
assumed_state: false
switch.htd_secondfloor:
icon: mdi:speaker
assumed_state: false
switch.htd_firstfloor:
icon: mdi:speaker
assumed_state: false
- Download mca662.py and place it into /config/packages on your HA server.
- Add the following lines in the homeassistant/packages section of configuration.yaml. This configures the slider bars for volume and limits the volume to 60 (matching HTD).
pack_1: !include /config/packages/mca662.py
- Use the Check Config button to confirm syntax, restart your HA server.
- Create a new lovelace ui card and add the following:
entities:
- entity: switch.htd_firstfloor
- entity: input_number.slider3
- entity: switch.htd_masterbedroom
- entity: input_number.slider1
- entity: switch.htd_garage
- entity: input_number.slider2
- entity: switch.htd_secondfloor
- entity: input_number.slider4
show_header_toggle: false
title: Speakers
type: entities
This should be all you need. I will update this post if I find time to create source selection, mute, party mode or other functions.
Hi Brandon, I was excited to come across your post here as I have been try to figure out a way to integrate my MCA66 with Home Assistant. I’ve followed through everything you have posted here but all I can get going is to power on a zone. My states are not reporting and the volume sliders are not working. I’m going to keep troubleshooting through things but I was just curious to see if you see the same thing on your setup. Thanks a lot for posting this.
Hi Jared, no I’m not experiencing that issue. Have you taken a look at the logs to see if there is an error?
Yes, I’m getting these every 30 seconds or so:
019-09-11 11:53:38 ERROR (SyncWorker_1) [homeassistant.components.command_line.switch] Command failed: python3 /config/htdquery.py querypwr 2 0
2019-09-11 11:53:38 ERROR (SyncWorker_1) [homeassistant.components.command_line.switch] Command failed: python3 /config/htdquery.py querypwr 4 0
2019-09-11 11:53:38 ERROR (SyncWorker_7) [homeassistant.components.command_line.switch] Command failed: python3 /config/htdquery.py querypwr 3 0
Did you put the htdquery.py file in the root of the config directory? If so, you can put some python debug logging to console (print) inside the htdquery file to see what it might be hanging up on
Another option is to run that exact command through SSH or Terminal
Trying to run it from the command line I get python3: command not found so I am not really sure what I have going on. I’ll try debug logging and see what it can tell me. Thank you for the suggestions!
Are you using the HASSIO installation? If not, you may be missing python version 3.
Yes, I am running HASSIO on a VM in vsphere.
Running on a NUC in Docker. When running this command: python3 htdquery.py querypwr 3 0
Seeing this error message:
-----------------------
Called HTDQUERY python script
Argument 1: querypwr
Argument 2: 3
Argument 3: 0
CMD: bytearray(b'\x02\x00\x03\x06\x00')
Traceback (most recent call last):
File "htdquery.py", line 14, in
detail = htd.queryZone_returndetail(int(argv[2]))
File "/config/mca66.py", line 199, in queryZone_returndetail
self.send_command_returndetail(cmd, zone)
File "/config/mca66.py", line 238, in send_command_returndetail
self.parse_reply_returndetail(data, zone)
File "/config/mca66.py", line 113, in parse_reply_returndetail
self.zonelist[zone]['power'] = "on" if (i[4] & 1<>7 else "off"
KeyError: 0
Worth noting that I added the PRINTs from HTD to HTDQUERY, as well as print(cmd) in send_command in mca66.py to try to better see what was going on. I’ve also seen KeyError 63 errors, as well as:
Traceback (most recent call last):
File "htdquery.py", line 14, in
detail = htd.queryZone_returndetail(int(argv[2]))
File "/config/mca66.py", line 199, in queryZone_returndetail
self.send_command_returndetail(cmd, zone)
File "/config/mca66.py", line 238, in send_command_returndetail
self.parse_reply_returndetail(data, zone)
File "/config/mca66.py", line 115, in parse_reply_returndetail
self.zonelist[zone]['input_name'] = self.input_names[i[8]]
IndexError: list index out of range
All these errors occur where running the same command
My Source file has 5 sources and Zone file has 6 zone. Have 3x checked all files to ensure everything lines up, so HA config check errors, etc…
I’ve only tested this in hassio, but should be the same I would think. Looks like its not loading one of the lists. Try a print right after it pulls the list file to see if you’re having an issue reading the file.
Will do. Running it from the command line yields odd results. About 20% of the time it’ll success (showing both the correct Zone Name, Source, Volume level, etc.). The other time I’ll get the KeyError: 0, KeyError: 63, IndexError, etc.
Certainly odd to see different errors when running the same command – esp. since some of the time it runs successfully. Will certainly try this and see what appears.