Tuya-mqtt-docker installation by a unexperienced user

I am working on a kubuntu system, with some docker containers which were installed with the help of jimtng:
https://community.openhab.org/t/howto-beginners-guide-to-installing-openhab-mosquitto-etc-with-docker-on-debian-ubuntu-tips-on-backup-and-more/163776/31

I have tried to install tuya-mqtt-docker
[GitHub - mwinters-stuff/tuya-mqtt-docker: Docker image for tuya-mqtt*
Simple

  1. create a directory for the config files to go into, this is mounted into a volume /config (eg $(pwd)/config)

  2. inital run to create the default config files
    docker run -it --rm -v $(pwd)/config:/config ghcr.io/mwinters-stuff/tuya-mqtt-docker:latest

  3. Stop the docker image with ctrl-c

  4. Edit the config/config.json file to point to your mqtt server

  5. Edit the config/devices.conf to add your devices.

  6. Run again in background

docker-run -v $(pwd)/config:/config Package tuya-mqtt-docker · GitHub

Docker-compose

Repeat steps 1 to 5 above, then use the following docker-compose entry

tuya-mqtt: image: Package tuya-mqtt-docker · GitHub restart: “always” volumes: - “./config:/config”

Customise as required and start.

This is my first try to install a docker image or container on my own.

For the first step (1) I understood that I had to provide a working folder which I named
/home/fl/tuya-mqtt/ within wich there should already be a config subfolder.
Then:
cd /home/fl/tuya-mqtt/ I could issue the command:

docker run -it --rm -v $(pwd)/config:/config ghcr.io/mwinters-stuff/tuya-mqtt-docker:latest

Things did not went well and many error messages came out.

How do I clean this docker container and install it properly?

Thanks.

One of the advantages of Docker is the containers don’t save anything. Every time you update the image or change the arguments pass while starting the container results in a brand-new container with nothing from any other containers you may have created.

The way to store data to be reused by new containers (e.g. configuration, data, etc) one mounts volumes into the container. When the container writes to a given folder (e.g. /config) that gets saved to a volume so if you start a new container with the same volume mounted it starts with all the data you need to save.

Therefore, to start a new fresh container, just mount a new fresh volume.

Trying to reinstall tuya-mqtt-docker, here is what I get:

fl@Satellite-Z930:~/tuya-mqtt$ docker run -it --rm -v $(pwd)/config:/config Package tuya-mqtt-docker · GitHub
Devices file not found!
tuya-mqtt:error SyntaxError: JSON5: invalid end of input at 1:1
tuya-mqtt:error at syntaxError (/home/node/tuya-mqtt/node_modules/json5/lib/parse.js:1083:17)
tuya-mqtt:error at invalidEOF (/home/node/tuya-mqtt/node_modules/json5/lib/parse.js:1032:12)
tuya-mqtt:error at Object.start (/home/node/tuya-mqtt/node_modules/json5/lib/parse.js:821:19)
tuya-mqtt:error at Object.parse (/home/node/tuya-mqtt/node_modules/json5/lib/parse.js:32:32)
tuya-mqtt:error at main (/home/node/tuya-mqtt/tuya-mqtt.js:95:31)
tuya-mqtt:error at Object. (/home/node/tuya-mqtt/tuya-mqtt.js:177:1)
tuya-mqtt:error at Module._compile (internal/modules/cjs/loader.js:1063:30)
tuya-mqtt:error at Object.Module._extensions…js (internal/modules/cjs/loader.js:1092:10)
tuya-mqtt:error at Module.load (internal/modules/cjs/loader.js:928:32)
tuya-mqtt:error at Function.Module._load (internal/modules/cjs/loader.js:769:14) +0ms
tuya-mqtt:info Exit code: 1 +0ms
fl@Satellite-Z930:~/tuya-mqtt$

Any cue appreciated.

Thanks.

It’s trying to load a JSON file from somewhere (config?) that doesn’t exist.

As I have other container with their config folder in
/home/fl/
examples:
/home/fl/openhab/
/home/fl/zigbee2mqtt/
/home/fl/mosquitto/

This new container installation would be in:
/home/fl/tuya-mqtt/

Here is an example that I found on the net:
docker run --mount type=volume,src=myvolume,dst=/data,ro,volume-subpath=/foo

So I think I need:

fl@Satellite-Z930:~/tuya-mqtt/config$ docker run --mount type=volume,src=/home/fl/tuya-mqtt/,dst=/data,ro,volume-subpath=/config
/home/fl/tuya-mqtt/

Will this accomodate for:

  1. create a directory for the config files to go into, this is mounted into a volume /config (eg $(pwd)/config)

Then I would place myself in the ~/tuya-mqtt folder to issue the installation command, is it?

fl@Satellite-Z930:~/tuya-mqtt/config$ cd /home/fl/tuya-mqtt
fl@Satellite-Z930:~/tuya-mqtt$ 
fl@Satellite-Z930:~/tuya-mqtt$docker run -it --rm -v $(pwd)/config:/config ghcr.io/mwinters-stuff/tuya-mqtt-docker:latest

You might need to step back a bit and make sure you really understand docker and containers. There is no “installation” with containers. You pull the image. You run an instance of that image with a certain configuration, i.e. the container.

I know nothing about this tuya2mqtt container but usually the first time a container starts with an empty volume mounted to the right place, it will populate that folder with the files it needs to run. When that fails that is usually because of permission problems. The user stuff is running as inside the container doesn’t have permission to write to the volume mounted into the container.

Beyond that :person_shrugging:. Again I don’t know anything about this image.

Maybe irrelevant for your case, but if you are trying to integrate Tuya in OpenHAB, you could also try to install the SmartHome/J Tuya Binding instead messing up with Docker.

Smarthomej tuya binding has been merged into the main openhab distro in 5.0. I’d suggest using 5.0 milestone 2 for this reason. Installing smarthomej binding wasn’t straight forward for me.

I can see that 5.0 milestone 2 is available as a docker installation
https://hub.docker.com/r/openhab/openhab/

As I have already an docker openhab installation, how can I install a separate container of openhab 5.0 milestone 2 to use tuya integration?

Is it:
docker run --name openhab --net=host openhab/openhab/openhab:milestone-5.0.0.M2

Each time that I use milestone-5.0.0.M2, should I stop my other container openhab container?

Whilst you could do this, you would need to specify different port numbers (http, https, ssh, lsp). and separate conf/userdata/addons mounts. Might be a bit trickier.

It might be easier to:

  • Duplicate/backup your conf/userdata/addons, e.g.
cd ~/openhab
mkdir oh4
rsync -a conf userdata addons oh4

Then update your existing docker image (in your compose.yml) to image: openhab/openhab:snapshot
Then do docker compose up -d - it will automatically pull the latest snapshot and upgrade your installation.

IMO, it’s fine to use snapshot instead of M2. That’s what I use.

Done

fl@Satellite-Z930:~/openhab$ docker compose up -d
[+] Running 5/8
...


...
[+] Running 3/3
 ✔ Container mosquitto    Running                                          0.0s 
 ✔ Container openhab      Started                                         10.8s 
 ✔ Container zigbee2mqtt  Started                                          0.0s 
fl@Satellite-Z930:~/openhab$ 

Thanks.

Now that I have Smarthomej tuya binding. How do I find my tuya devices?

What should I read? Command line would be my preference.

Thanks.

Thanks for sharing your experience! I also found the SmartHome/J Tuya Binding integrated into openHAB 5.0 to be a more straightforward solution compared to setting up tuya-mqtt in Docker. The discovery process was smoother, and it reduced the complexity of managing multiple containers. For anyone using Docker, running openHAB with the --net=host option helped with device discovery in my setup.