My attempt at a Hassio add-on - please help?

Hi folks,

I’m attempting to create a Hassio add-on for the Qwikswitch USB Hub. It consists of a small webserver that communicates to a hub plugged into the USB port that, via RF, sends and receives signals to various relays, dimmers, switches, etc.

I followed the tutorial and created the Dockerfile and config.json file. The Dockerfile has lines to download the web server zip file and unzip it. It then needs to copy a file to /etc/udev/rules.d - and this is where it fails with a return code of 1.

Granted, I’m no Docker expert and not sure if I am going the right direction or or not. Can you please assist me to get this add-on up and running?

This is what my Dockerfile looks like:

ARG BUILD_FROM
FROM $BUILD_FROM

ENV LANG C.UTF-8

RUN apk --no-cache add
unzip
wget

RUN wget https://cdn.shopify.com/s/files/1/1883/0535/files/qsusb_pi_V1.91.zip
RUN unzip qsusb_pi_V1.91.zip
RUN cp z010_mchp_tools.rules /etc/udev/rules.d

WORKDIR /QSUSB

EXPOSE 2020

CMD [ “./QSUSB/qsusb” ]

config.json

{
“name”: “Qwikswitch USB Hub”,
“version”: “1”,
“slug”: “qwikswitch_usb_hub”,
“description”: “This add-on starts the Qwikswitch USB Hub middleware. Make sure that your USB Hub is connected to a USB port.”,
“startup”: “before”,
“boot”: “auto”,
“url”: “http://www.qwikswitch.co.za”,
“webui”: “http://[HOST]:[PORT:2020]/”,
“options”: {},
“schema”: {},
“ports”: {
“2020/tcp”: 2020
}
}

Note that I did try "RUN sudo cp … " as well and it returns a return code of 127.

Kind regards

Hi @frenck.

I am sure that you get a lot of queries regarding Hassio addons hence I try as much as I can referring to documentation, etc before I ask for help, but I’m at a loss here in getting this going. Can you please assist me in getting this add-on up and running?

I would greatly appreciate it very much.

@ipodmusicman, I do get a lot of queries. If you are interested in this development, please follow me on Twitch.
That’s the platform where I show and answer general add-on development stuff.

https://twitch.tv/internetofthings

About the code in here. There is so much wrong already with those couple of lines.
Like:

  • Those udev rules aren’t going to work, so you’ll have to find another way.
  • The unzipped thing is not marked as executable?
  • I expect some kind of architecture depended download of some sort? amd64? i386? armhf? aarch64?
  • sudo?
  • Leave out the expose, you don’t need it.
  • Setting a workdir, but the CMD uses a relative path? So you are trying to execute /QSUSB/QSUSB/qsusb?

By these things, I would strongly advise you to try building a more simple add-on, just to get the hang of how things are working. You are now stuck in a thing, that might not be fixable as well, while clearly missing a lot of basic knowledge about Docker and Hass.io.

Hi @frenk

Thanks so much for your reply and I’ll check out your Twitch channel.

I’m not surprised at all that there is so much wrong with the code. :slight_smile: I’m a complete novice on Docker and Hassio. I managed to create the “hello world” addon which worked great, so what I did was look at the Ubiquiti controller addon’s Dockerfile which is where I referenced from as a guide.

All I have was the README contained within that zip file to help me below. They do have a Windows, Raspberry Pi and Linux versions which one can download from their website (the addon is installing the Raspberry Pi version although the README says otherwise, so I’d imagine that the readme is incorrect in wording), but as a start, I wanted to get something going, but yeah I agree, the addon needs to be bit more smarter.

QSUSB on linux

Tested on Ubuntu 10.10 - 12.04 Server/Desktop

  1. Unzip files to a folder eg. /home/user/qsusb
  2. sudo copy z010_mchp_tools.rules to /etc/udev/rules.d
  3. Plug in QwikSwitch USB modem
  4. Run qssub bin file
  5. Open Web Browser to http://127.0.0.1:2020

I suspect that I bit off a lot more than I could chew.

You mentioned that the udef rules is not going to work at all which I guess means that having an addon is not going to be an option whatsoever. So, any light at the end of the tunnel perhaps, as an addon would be first prize. I really would prefer not to have to purchase another Raspberry Pi just to host this piece of software on.

That add-on is under development and is therefore not a great example to look at. Secondly, that add-on is pretty advanced. Better examples are:

  • Tor add-on (Alpine based)
  • Example add-on (Alpine based)
  • Control Panel add-on (Alpine based)
  • AirCast add-on (Ubuntu based)

Hi @frenck

Just to let you know that I managed to get the add-on running. Thanks for pointing me in the right direction.

Only problem is that the web server doesn’t recognize that the device is plugged into the USB port. :frowning: When I log in via SSH into Hassio and do a hassio hardware info, I see one entry “/dev/ttyAMA0”. I could not tell, even with extensive searching, whether this represents the USB ports on the Raspberry Pi or not.

If this does, I suspect that the QSUSB application itself doesn’t recognise “/dev/ttyAMA0” in which case I should consider mapping this to a different device in the config.json using the “devices” property. What is a typical device that a typical application requiring the use of a USB device would reference?

I hope I am making sense here.

This is my config.json below.

{
“name”: “QwikSwitch USB Hub”,
“version”: “1.0”,
“slug”: “qsusb”,
“description”: “Add-on to start the QwikSwitch USB Hub Web Server”,
“url”: “http://www.qwikswitch.co.za”,
“startup”: “services”,
“arch”: [
“aarch64”,
“amd64”,
“armhf”,
“i386”
],
“boot”: “auto”,
“host_network”: true,
“auto_uart”: true,
“options”: {
“port”: “2020”
},
“schema”: {
“port”: “int”
}
}

Also, there is a file called rules.d located in etc/udev folder which is copied into the container with the following contents. Not sure if this has an influence or not on the USB side.

2012.01.23 Changed SYSFS reference(s) to ATTR.

2011.12.15 Note: Reboot works on all systems to have rules file recognized.

2010.01.26 Add reference to “usb” for Ubuntu.

2010.01.22 Attempt to further simplify rules files requirements.

2009.08.18 Rules file simplified.

2009.07.15 Rules file created.

ENV{hotplugscript}="/etc/.mplab_ide/mchplinusbdevice"

ACTION!=“add”, GOTO=“check_remove”
SUBSYSTEM==“usb_device”, GOTO=“check_add”
SUBSYSTEM!=“usb”, GOTO=“rules_end”

LABEL=“check_add”

ATTR{idVendor}==“04d8”, MODE=“666”, RUN+="%E{hotplugscript} add"
GOTO=“rules_end”

LABEL=“check_remove”

ACTION==“remove”, RUN+="%E{hotplugscript} remove %E{PRODUCT}"

LABEL=“rules_end”

Hi @frenck

Just to let you know that the add-on is now working 100% after I re-installed my Pi with HassOS. There is another guy who also worked on an add-on for Qwikswitch so I’m trying to get hold of him to hopefully consolidate our efforts.

What does it take to add this as part of the community add-ons?

Would you share how you set up a docker container for the Qwikswitch USB Hub?

Hi Fezile,

We created a Hassio add-on which works very well. Find it at https://github.com/nardusleroux/hassio-qsusb

Thank you.

Hi Getting the following error not sure how to fix this (Proxmox running HA)

[s6-init] making user provided files available at /var/run/s6/etc…exited 0.
[s6-init] ensuring user provided files have correct perms…exited 0.
[fix-attrs.d] applying ownership & permissions fixes…
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts…
[cont-init.d] 00-banner.sh: executing…

parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:27+0200] ERROR ----> Unknown HTTP error occured
parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:27+0200] ERROR ----> Unknown HTTP error occured
Hass.io Add-on: v
parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:27+0200] ERROR ----> Unknown HTTP error occured

parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:27+0200] ERROR ----> Unknown HTTP error occured
parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:27+0200] ERROR ----> Unknown HTTP error occured
From:
parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:28+0200] ERROR ----> Unknown HTTP error occured
parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:28+0200] ERROR ----> Unknown HTTP error occured
By:

[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing…
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] 02-updates.sh: executing…
parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:28+0200] ERROR ----> Unknown HTTP error occured
parse error: Expected string key before ‘:’ at line 1, column 4
[17:34:28+0200] ERROR ----> Unknown HTTP error occured
[17:34:28+0200] INFO ----> You are running the latest version of this add-on
[cont-init.d] 02-updates.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
Starting
/run.sh: line 22: /qsusb/QSUSB/qsusb: cannot execute binary file: Exec format error
[cmd] /run.sh exited 126
[cont-finish.d] executing container finish scripts…
[cont-finish.d] 99-message.sh: executing…

            Oops! Something went wrong.

We are so sorry, but something went terribly wrong when
starting or running this add-on.

Be sure to check the log above, line by line, for hints.

[cont-finish.d] 99-message.sh: exited 0.
[cont-finish.d] done.
[s6-finish] syncing disks.
[s6-finish] sending all processes the TERM signal.

Hi Christopher,

Are you using the latest version (0.8) of the HASSIO addon?

Regarding this error:
Parse error: Expected string key before ‘:’ at line 1, column 4
[13:02:22] ERROR: Unknown HTTP error occured

I am getting it too, but unable to figure out why it is happening, but it does not influence the functionality of the plugin.

I’ve only tested this on a Raspberry Pi 3b, so not sure how it will run on Proxmox.

Hi ipodmusicman

tried 0.7 and 0.8 with no luck, it does not start at all.
I’ve moved from Pi3 (where it was working) to proxmox.
I have the usb plugged into the host and just use the host ip xx:2020 working for now.

Thanks

I wonder if it has something to do with the actual qsusb binary from Qwikswitch. The addon can install a Linux or Rpi version depending on the platform. I assume that we are at the mercy of QS in terms of if they support Proxmox. I don’t know much about Proxmox at all.

@ipodmusicman I hope you are still around…

I’m having difficulty installing the add-on.

19-06-22 10:52:36 ERROR (SyncWorker_9) [hassio.docker.addon] Can't build local/armv7-addon-qsusb:0.8: The command '/bin/bash -o pipefail -c FILE="qsusb_pi_V1.91.zip"     && if [ "${BUILD_ARCH}" = "armhf" ]         || [ "${BUILD_ARCH}" = "armv7" ]         || [ "${BUILD_ARCH}" = "aarch64" ]; then         FILE="qsusb_pi_V1.91.zip";     fi     && if [ "${BUILD_ARCH}" = "i386" ]         || [ "${BUILD_ARCH}" = "amd64" ]; then         FILE="QSUSB_linux.zip";     fi     && apt-get update         && apt-get install -y --no-install-recommends         libusb-1.0         unzip         wget         jq         && wget https://cdn.shopify.com/s/files/1/1883/0535/files/${FILE}         && unzip ${FILE}' returned a non-zero code: 127

From what I could find is that wget might not be installed on the ubuntu image you are using. However I can see that you are installing it together with unzip and the other requirements.

I cut and pasted the the contents of the Docker, config.json and run.sh files from your GitHub repository.

My hass.io installation is running on a raspberry pi b3.

Any pointers on what I should try?

Thanks
Paul

I got this to work by using the test branch as suggested by nardusleroux.

@nleroux Can you please look at this test branch that @PollieKrismis is referring to and perhaps look at what needs to be done to the master to allow this to work for him?

Also, I created a pull request whereby I packaged v1.65 of the www folder from the Windows package into the add-on? I have informed QS of this to request them to update the Pi and Linux versions which they don’t seem to have at high priority at all, so I went ahead and added them. This will allow us to put relays into link mode remotely.

@ipodmusicman Test branch is my original starting point before additions. I am not in position to test on other hardware except RPI at the moment so guess some of the additions to attempt to make the addon multi hardware supported causes some issues. If there is a need for the addon to be supported on other hardware suggest a fork/new project.