SpeakerCraft MZC Control

Just looking at code. Looks good. Not had chance to test.

On sending the command are you waiting for the command window on the serial hex 11 and sending before the window closes hex 13. If you send outside the window it is ignored. Maybe I’ve missed that bit.

Master off maybe a waste of time as can be done via script/automation

I can’t remember what is in this code vs mocropython.

I think the commands need to be queued in a fifo queue. And then only cleared when a confirmation is received so if the window is missed on thst cycle it’s able to reattempt… it needs queueing so then you can wait for 11 without locking system and receive multiple command quickly eg vol up.

I want to retain power target which controls a snart plug connected to device as the standby on speakercraft I don’t trust. So if all zones are off then it should wait a set time then power off smart plug. Also if the system is powered off it won’t recieve the command window so this is when to check if power target is powered on and if not seotch on

Hope that makes sense.

Treble should be renamed If I spelt it wrong

Sorry wish I was home to test properly and communicate with you.

Thanks for your big contribution. Hopefully we can get this to be a descent integration.

On 0x11 and 0x13, the reason that you can’t see that in the code is that implementing this is as simple as selecting xonoff when you open the serial connection (see line 304). See Software flow control - Wikipedia for the details of the protocol

In terms of the confirmations, the code you sent originally recognised them, but didn’t do anything special with them, I was wondering if we needed to do anything, but in testing so far, it hasn’t proved necessary. It may do under further testing, we shall see.

Your use of the plug makes sense, I’ll ponder how PartyMode switch can be created in a consistent way.

I’ll rename trebble->treble now.

Don’t sweat not being there, I’m away for next couple of weeks too.

Oh my I wish I had of known flow control earlier. Makes things so much easier. I’ve code a few integrations for speaker craft and always done it manually. Including in .net for home seer

Probably much more resource efficient this way. And less likely to miss the window as its much closer to hardware layer.

Feel stupid lol.

With regards to the power target probably best to drop it. But if its possible to have some way of triggering an automation when a command is received then I can do automation which is triggered by this component and then condition can be switch is off and then it can turn off the smart plug. When all zones are off an automation can turn the plug off. If that makes sense.

It’s speakercraft’s fault IMO, their docs describe the detail of the protocol without saying it’s a standard. I can’t recall how I worked this out.

On the power target, I think the way you envisage it is the right way to do it, I’ve updated the readme to describe it now. Let’s leave it in there as is and I will add Party Mode implementation as another switch that belongs to the speakercraft platform

hi not sure why that would be happening. most odd.

I’d suggest that the HA solution (in matts github) is probably the best way to go. Especially if your controller is located close to the HA. Just expect alot of changes, as we get it working efficiently.

Stu

I’m a few steps behind you (the TTL DB9 took forever to arrive) and am starting to look at how to upload the files to the ESP32. I’ve been using Arduino ide for other projects but it looks like I need something else for the micro python. What did you end up using? Any tips or details would be a big help. The HA Solution won’t work for me and I’d love to get the ESP32 route working.

sorry i havent given more instructions. I have literally only done it once and that was about 2 years ago.

I think i would of followeded these instructions. here

once its uploaded you can connect to a REPL prompt over serial and setup WebREPL which allows you to upload the 2 files over the web interface.

just out of interest why wont the HA solution work for you, is it due to location?

I was able to install Python, PIP and esptool then put micro python on the ESP32. There was some trial and error as some of the sites weren’t that clear and missing some steps. They probably figure if you’re trying to do this, you have a little bit of a clue. (they are wrong)

My next step is to load the boot.py and main.py files. I’m going to try ampy tonight but that may be hit or miss. I’m trying to take good notes and will post once I get it figured out. I like trying to figure this stuff out but some days I just want it to work the first time.

Regarding the HA Solution, my HA Pi is at the other end of the house so I’d need to relocate it to the MZC to make that work. I also have another MZC I was going to deploy for the garage/other side of the house so using another ESP32 (if that’s even possible with this setup) would be better.

A question for those that know more, once this is all dialed in, would it be possible to add to esphome so it would be easier for others to roll out? I’m not as savvy as most of the people here but it looks like they are using Python and C++. The first sensors I made were the Bru style and took me longer to deploy but after using ESPHome, it was way easier to build and even create new styles from the available components.

https://esphome.io/guides/contributing.html#contributing-to-esphome

let us know how you get on with the ESP32.

I think actually there is an error on it as now MQTT server requires a timeout, whereas the code i wrote at the time didnt. it will work with an older version of mosquitto.

ESPHome, would make things alot easier to deploy to be honest. But it was easy for me to write the code in python, rather then C.

I think at the moment, i will be mainly concentrating on the HA integration, as it doesnt require additional hardware. Eventually may integrate a new ESP version.

The ESP32 route isn’t going so well. I’ve uploaded the files to the ESP32 and put the mqtt_media folder with files in the custom_components folder in the HA config folder but even after multiple restarts, I’m not seeing mqtt_media anywhere which is preventing me from adding the zones in the configuration.yaml file. I’m running Mosquitto broker version: 6.0.1, could this not showing up be due to the “MQTT server requires a timeout” as @Sjeffrey mentioned? I looked through the logs and I’m not seeing anything about mqtt_media. Any thoughts? I really can’t check out the hardware side of things until it’s running in HA.

Some notes for others regarding my ESP32 experience:

In the boot.py file, make sure you change the file to put in your wifi details in line 13 before uploading.

sta_if.connect('Wifi', 'Pass')

In the main.py file, you may need to update MQTT Client address at line 106 before uploading.

client = MQTTClient("speakercraft", "192.168.0.100", 1883)

Another tip that took me a little bit to figure out, I DID NOT update the main.py file like I said above but once it was loaded, I wasn’t able to access the ESP32 with ampy. The put command should overwrite the file but it wasn’t working for me. Maybe the ESP32 was in some loop preventing it? Since I had trouble my first time, I’ll post what worked for me in case it will help others.

Launch a CMD window from the folder where the boot.py and main.py files are stored.
From the CMD window, use the following command to copy the main.py file to the ESP32:

ampy --port COM3 put main.py

I was on port 3 but change to whatever you are on. You can find this in the Device Manager>Ports.

I needed to remove the main.py file so I could upload the new version. I used this command:

ampy --port COM3 rm main.py

I hope that helps someone. Let me know if you need any other details, I’ll share what little I know.

Hi,

Sorry i have not given very good instructions. Really is because it was so long ago i did this, and just left it working.

have you added the configuration to configuration.yaml

That should allow the media player components to create in HA. Clicking on any buttons will then send a command to MQTT topic eg speakercraft/command/zone1

Its worth installing a MQTT client in windows so you can see what its doing. Obviously the device wont turn on, unless the ESP32 is turning it on and then reporting back that it is on.

If the ESP32 is reporting status it should be visible in the MQTT client. I think that the last version of mosquitto the current code works with is 2.0.11. Version 2.0.12 required a timeout parameter. Mosquitto is only up to version 2.0.14 so not sure what version 6 is?

I dont know about ampy.

I used WEBRPL MicroPython WebREPL to connect and this also shows the output of the ESP32 so you can view any errors.

Are you able to see what the ESP32 is outputting?

Im also wondering if the version of micropython installed might make a difference… I did it a long time ago, so it might be that something has changed here.

Clearly installing MP is not easy. - we need to come up with a better route for the ESP32.

I can’t get as far as having the configuration.yaml edits because it’s not seeing the custom integration when I try. Has anyone else got this running in HA?

Without this running, I can’t really troubleshoot anything ESP32 or even know if that part is working.

No worries on the level of the documentation. I do the same thing, make a project work and then forget about it. In fact, I’m trying to find my EZ Tools programs for the MZC to edit! If I can get the ESP32 up and running, I’ll send you install notes to add to the github. I do appreciate the work you’ve done on the project though.

Ah that might that you need ha to recognise the custom component before it will verify the yaml.

Remove the configuration and restart ha. In the log it should say it found the untested custom component.

Then add the config and restart again.

I’ve created an issue here to track the support of remote serials. Support for remote serial · Issue #22 · mattsaxon/HASS-SpeakercraftMediaPlayer · GitHub

I will be trying to get this working at some point using the same code base that myself and @Sjeffrey have created for local RS232 control. Though to set expectation, I haven’t done anything with an ESP32 yet

@bigscience , @Sjeffrey is correct in this assertion. For what it’s worth, I find this behaviour of HA very irritating when installing/developing custom components, and don’t believe it has always behaved this way.

I’ve tried restarting several times and it’s not working even without the other config zones. HA is showing no logs about errors for the component. It’s like it’s not eve seeing it.

Just to clarify, is this the correct location for the custom components, this is my first one:
image

Maybe it’s a permissions thing? Should I create in the file editor or from an explorer window? (grasping at straws now)

Thanks again for everyone’s help and input on this project. This community based approach is a perfect example of why Home Assistant is so awesome.

sorry cant see from your screenshot when you are located.

in the folder that your configuration.yaml file is, you should create a folder called “custom_components” then inside that the mqtt_media folder is located, with those files.

I suspect a manifest issue, for one thing the file should be manifest.json. Furthermore, if this hasn’t been touched for a while, there are more stringent requirements for the file, notable “version” is now required.

However issues like this should be in the logs, can you do a reboot and paste your error log.

good spot, with the manifest.json name.

im pretty sure it should work, as i was using this on latest version of HA prior to us resuming this component which talks direct.

@bigscience I’ve tried the MQTT component as is from @Sjeffrey repo.

I can get it recognised fine. You need to rename the .jason file to .json, but what is confusing me is how it got renamed in the first place as this is not the name in the original.

If you just copy across the repo, the component will be recognised and you will see an entry such as

2022-01-30 12:23:12 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration mqtt_media which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant'''

Absense of this warning occurs when the manifest is not there (or incorrectly named).

The configuration error you are receiving must mean you have something in your configuration.yaml such as

media_player:
  - platform: mqtt_media

If that wasn’t there there would be no configuration for the “Configuration validation” page to complain about.

So step are;

  1. remove entry from configuration.yaml
  2. correctly copy across repo (ensuring manifest.json is there and named correctly)
  3. restart HA (after successful configuration check)
  4. put entries back in configuration.yaml