SpeakerCraft MZC Control

@Sjeffrey would you mind sharing your original HA custom component ( the once before you chose to add an ESP32 to buffer)? This will be an improvement on my current setup with NodeRed, and it will give me some breathing space whilst I learn the ESP approach as I haven’t used one before.

@mattsaxon i’ll have to find that code, it will take a ouple of days as i need to go into some backups at my office, and im not there for a couple of days. bare with me.

stu

I am brand new to home assistant… Literally yesterday I started tinkering. But a good few years ago I got a speakercraft mzc-66 and didn’t want to put the keypads in each zone nor buy the ers / web thingy.
I hooked it up to my HP micro server using a USB to rs232 cable and wrote a perl script to control it and get the zone statuses back, etc. Then put a simple HTML5 web page on an Apache web server to put a front end to the thing. It’s still working reasonably well but it’s many years behind ;). And I can see how much better it would be in home assistant… I have the technical specs and my hacky scripts if it’s useful to anyone. Unfortunately I only heard about node red yesterday so I have some catching up to do :slight_smile: but looking forward to assisting where I can and making use of this project!

1 Like

I used NodeRed in this case as I wanted to learn about it, it was my first project on it.

Having done that and worked out how to control the Speakercraft, I’m sure this is not the right approach despite it being a workable solution for me in the interim.

There’s a few options about how to proceed given the above set of prototypes using various technologies. I’m going to make progress along these paths as a background hobby project, but it likely wont be fast progress.

I’ll be exploring the ESP32 setup above and use of both custom and standard components from home assistant as I go. It will almost certainly all be done in Python.

I’m happy to collaborate with everyone on this thread to get us there.

One thing I feel we definitely need is a custom Python component that is abstract from HA or ESP32 and I’d plan to build this following the template laid down by nad-receiver · PyPI

That component is the one used by the Customer HA NAD component NAD - Home Assistant

However as it is abstract we could use it both in the ESP32 solution and in the HA native solution, giving both remote and local control of the device depending on our needs.

1 Like

@Sjeffrey it’s the first time I’m seeing any python code :stuck_out_tongue:… But it looks easy enough to follow and all looking very familiar wrt the speakercraft commands… I guess for me the difference will just be that I won’t be using the esp but an Ubuntu VM and I guess the rs232 part might be a little different for the connection but otherwise it looks simple enough. I presume you using the mqtt for the zone status updates message that updates all zones? Sorry for delay might be a stupid question but all this is new to me :smiley:. I will definitely have a go at getting this working and will also dust off my old perl script to see if there’s anything to add (but I doubt it).
Thanks!
Charles

@CharlesC i dont see why it wouldnt work on a platform other then esp32. its just python, maybe require a small amount of change from micropython. eg i cant remember if the MQTT library is mp specific, and also the serial, but the prinicipal is there.

i used mqtt as it meant that HA wasnt waiting on my code.

it would be interesting if we could get it to run in a docker container - which might be able to become an addin. Much like someone did with the texecom2mqtt addin.

However i might see again if i can get it to run directly with HA as a component, and python component as @mattsaxon says. This would probably be best. I havent got round to finding my old code which essentially does this in a HA component.

@mattsaxon i just looked at the NAD components, this appears to be a single zone controller, so not much good for comparison? probably monoprice or russound would be better? i was considering at one point to make a russound 2 speakercraft emulator at one point, so i could use the russound HA component, and it would talk to an arduino and that would translate to speakercraft.

i used to use homeseer, so also have old VB.net code for the speakercraft also.

i also didnt install any of the speakercraft controllers in the rooms and control it purely from HA dashboards and a few wireless buttons and automations. works really well. I also have a smart plug which turns it of when all zones are off and back on if i have a command queued for it. I can also control it from alexa.

@mattsaxon

ok i have found my code for the component. ive uploaded into github, here

ive not done any recent testing on this, and it was done purely for me, so i dont know how good it was. From what i remember the problem i had was that the serial would occasionally stop working after a week or so, but i think that might be because i was using virtual box.

quick look in the code, and it looks to have the serial port hard coded in it. probably due to testing.

there is a file exconf, which should show what to put in the configuration.

im going to be rebuilding my HA sometime onto an old I7, so i may well re-instate this rather then the esp. although the MQTT version with the ESP has been 100% reliable for me.

Thanks Stu. Do you have any intent to maintain this at this point? If so it probably best to split this component up into a separate repo as then it will be easier to submit PRs, version and use HACS to install.

If you don’t, I’ll split it into a separate repo on my account if you are fine with that.

@Sjeffrey I have managed to get it working on Ubuntu (on my microserver) using python as opposed to micropython. the changes were minor but still fairly challenging for me as it’s my first time working with python and with home assistant so lot’s of new concepts and language and so on.
The MQQT library is different and a few other differences with Time, etc. too. I am also running on a very old box with small amount of memory and thus I’m running an old version of Ubuntu (14.04) and therefore older version of python so had to work around some missing methods/etc.

I changed the flow somewhat to get the looping/checking/connecting working - I suspect this might have been necessitated by the difference in approach from esp32… I will clean up my python version so it can be shared.

It is almost working… the python is running well and based on the prompts I can see it’s following the flow as expected. It’s connecting to the MQQT broker and that is pulling through to the home assistant UI - as in changing volume/on-off/source/etc. on one of the zones (either using the keypads or my perl thingy) is updating in the home assistant. However I’m getting errors when trying to publish commands from home assistant using the media_player.py custom component.
I have probably done something stupid or incorrect but i am a bit puzzled for now… the error i’m getting is this:
Failed to call service media_player/turn_off. publish() missing 1 required positional argument: 'payload’

I have had a brief fiddle but as i mentioned the learning curve is maybe rather steep … will try get back to this later but thought i’d check in just in-case you might know what the likely issue is.

Regards
charles

I have no experience with Docker nor understand how it works with use use cases, but I would expect/wonder if the RS232 and physical need to connect to the control port would impact on the feasibility of this.

Hi Matt,

To be honest, not sure what my intention is at the moment. As you can probably tell, this has been developed initially purely for my own use. Im just figuring out github, and have just chucked the code up there initially, if people can use it.

If it can be turned into something that is easy for people to install and well documented then this makes sense.

But the question is whats the easiest way of doing this, the micropython is a pain to upload and configure and expliain. - but it works very reliably for me.

I’m wondering if its easier to resurrect the HA component, and attach the HA direct to the speakercraft serial, or if it is better to make the speakercraft wireless via the ESP32. The serial interface is very busy, so using the esp32 removes alot of processing from HA.

ive just purchased a serial 2 usb FTDI, so i’ll see if my origional code is any good, should be here in a day.

what are your thoughts/preferences?

Hi Charles

yes actually mine stopped working when i updated homeassistant, last night. - something must have changed here.

i have just uploaded the changes i made in the custom componenet to media_player.py - try that one.

glad youve managed to get the other bit working well. are you using a MQTT client to also see the changes.

stu

Ah great - will try that shortly! I was scratching my head over this last night and looking for something similar that’s working, etc. but i also needed sleep :wink: lol.

I wasn’t using an MQTT client to monitor it… will go there if things don’t work as expected. I think I saw somewhere in home assistant a feature to monitor or subscribe to topics to view traffic.

thx

It’s working :grin:… Very cool… Had to tweak the py for the different arguments to the call back and there was a small issue with byte vs string but it’s mostly working. I have a bug with zone power off that I think I know what’s happening but just need a bit of time to fiddle. Quite keen to add bass & trebble support but also looks like a different or maybe custom card design would be nice as the default media player one seems rather limited… Not sure what’s involved there though… haven’t looked yet tbh.
Thanks again!!
Charles

@Sjeffrey - found the issue - turning off a Zone from HA was issuing both a power off and a volume set command and the callback for the volume set was overriding the power off command before it had been sent to the Speakercraft - I changed it to ignore any new command while an unissued command is waiting and it’s working great now

ah yes, i set the default volume when the zone is powered off, so it turns back on at the right volume.

this should of already been in the code, where it doesnt get another command until it has had the previous one confirmed. although if youve re-written the mqtt part then that might be why. You maybe using callbacks on mqtt subscribe which would mean multiple could fire simultaneously i guess.

Hi Stu,

I’ve created a new repository here based on your code.

Since you are new to GitHub I’ve done this so you can get a feel for it, but if you wish to I’d be happy to transfer the repo back to you for you to be the main maintainer for it. If not, I’m happy to do so, it’s your call and we can decide this later too.

The reasons for having a separate repo is 2-fold. Firstly I needed to change the structure to make it compatible with HACS (which is my proposed journey for making install easy for others). Secondly, I think it is better approach for maintenance. Specifically rather than having detailed conversations on this forum about issues, we should use the issue list in GitHub as it is better to thread each discussion.

My immediate plan is to get the HA component working well and I’ve made initial steps to do that for me (and I hope for others as follows);

  1. I’ve changed the code to use the native xonxoff (software flow handshake). This tidies up the code and the treatment of 0x11 and 0x13 messages.
  2. Move to using SerialReader/SerialWriter from pyserial-asyncio to improve how to deal with split messages (before I was getting lots of messages split across data_received(), so I think the new approach is easier)
  3. I’ve replaced many of the print() statement with logger to debug messages so they can be seen in the HA log.
  4. I’ve removed the hexlify to improve the performance of the parsing and am processing the binary bytes arrays as opposed to strings. (I’m not sure this was necessary for performance reasons, but since you had issues with processing speed I felt it may help).
  5. I’ve added version to manifest.json which I think fixes one of the issues previously mentioned about it “not working with latest home assistant”

Overall the performance of this for me is very good (RPi 3B+)

There’s still more work to do here, which I will response on other thread here, and also link to issues that I will create to track on GitHub.

@charlesc I’ve not experienced this issue myself, but I wonder if my new code will have addressed it for you anyway. I’d be happy to accept any proposed changes you have to the shared code I propose we maintain via GitHub PullRequest (PR) if you are game

@CharlesC I have the same issue with masterpoweroff as you I think, I’ve raised a specific issue on it here to track masterpoweroff doesn't function · Issue #1 · mattsaxon/HASS-SpeakercraftMediaPlayer · GitHub

On the tone support, can I suggest you take a look here which may give some pointers Mini media player card layout. However before we get too many users on this, can I query the use of term “trebble”, should it not be “treble” as a name change is harder the more people are using it.

@mattsaxon this is great to see. I am currently away so won’t be able to look properly until later next week.

I started work on this component again last week looking for a way to handle the split messages but your way is much better. I’ll test it out when I’m back.

I agree with most your proposed work and can help when I’m back.

I’m sure the master off used to work. I don’t use party mode was so to turn off all zones at once. I don’t think there is a need to turn all on.

I was also using a smart power switch to turn on off the whole unit.

I’ve updated the GitHub issues about masterpoweroff, I’ve fixed the issue in the code which looks like you were in the middle of fixing a move from sync to async. It now will update the “external” switch entity, but I can’t see how you intended to use an external switch to do the power off. What was your external entity and did you have some automation attached to it, I’m using an input_boolean switch, which is just passive and reports the status of amplifiers zones at the moment.