Tuya Convert Walk Through – February 2019

from – The Hook Up
with minor change due to error i was getting.

Compatible device list for Tuya-Convert

1. Before you begin you’ll need:

  1. One of the Linux machines listed below:
    1. raspberry pi model B with the latest version of Raspbian Stretch Lite (Recommended Method).
    2. raspberry pi model B+ with a USB wifi dongle and Kali Linux.
  2. A micro SD Card for your raspberry pi (at least 2gb, 8+ recommended).
  3. A wifi device that can connect to the SSID that will be generated by the raspberry pi and eventually the flashed tuya device.  This cannot be an iOS device, android devices will work.

2, Installing the OS on raspberry pi:

  1. Download and install Etcher
  2. Plug your microSD card into your PC using a microSD adapter
  3. Start Etcher.
  4. Select the disk image you downloaded and your microSD card from the etcher interface.
  5. Press Flash and wait.
  6. Add a blank file called “ssh” to the root of the raspberry pi to enable the SSH service on raspbian.
  7. Plug the SD card into your raspberry pi, connect power and ethernet and boot it up.

3. Connecting to your raspberry pi via SSH:

  1. Download and install Putty
  2. Start Putty.
  3. Enter the IP address of your raspberry pi in the box that says “Host Name”.  I recommend using an app like Fing to find the IP address of your raspberry pi.
  4. In the “Saved Sessions” input box, name your raspberry pi connection and then press “save”.
  5. Select your new saved session.
  6. Press “Open”

4. Setting up your Pi and updating the OS

  1. In the putty window login with user “pi” and password “raspberry”
  2. Expand the file system by typing “sudo raspi-config” then selecting “Advanced Options” and then “Expand Filesystem”, select “Finish” and then select “Yes” when it asks to reboot.
  3. Reconnect via putty using your saved session and login with username “pi” and password “raspberry” again.
  4. Type “sudo apt-get update” and wait for the updates to install
  5. Type “sudo apt-get dist-upgrade” and wait for the upgrades to install
    1. You may get a prompt for permission, just type “y” and press enter.
  6. Type “sudo apt-get install network-manager” and wait for it to install.
  7. Type “sudo apt install git” and wait for it to install.

5. Setup and Install Tuya-Convert

  1. In the putty window type “git clone https://github.com/ct-Open-Source/tuya-convert” press enter and wait.
  2. Type “cd tuya-convert” and press enter.
  3. Type “./install_prereq.sh” and wait.

6. Use Tuya-Convert to install Tasmota

  1. Type “cd tuya-convert” and press enter.
  2. Type “./start_flash.sh”.
  3. Types “yes” and press enter.
  4. Connect your separate WiFi device to the “vtrust-flash” SSID that is being broadcast by your Raspberry Pi. The Password is “flashmeifyoucan”.
  5. Plug in your Tuya plug, switch, dimmer, or bulb and put into pairing mode.
    1. Different models are put into pairing mode via different methods, check the curated product pages for information for putting your device in pairing mode.  The LED should flash rapidly if done successfully.
  6. Press enter on your putty window to start the flash process and wait.
  7. Once the process completes you can type ” curl″ to install tasmota, or look at the other options available.
  8. If it says that booting is already from userspace 2 then run following command ” curl″
  9. after this command you should see “Device should flash and restart”

7. Setup Tasmota

  1. On your secondary device, disconnect from vtrust-flash and connect to the new SSID called “sonoff-XXXX”
  2. Open in your browser and enter your WiFi’s SSID and password.
  3. Use Fing to find your new device on your WiFi network, it should be called “Sonoff-XXXX”
  4. Open the IP address of your new device in a browser.
  5. If using MQTT:
    1. Click “configuration”
    2. Click “configure MQTT”
    3. Enter your MQTT information
  6. If not using MQTT:
    1. Click “Console”
    2. Type “setoption3 0”
  7. To get the best compatability with Tuya products you should update to the most recent version of Tasmota.
    1. From the main tasmota screen click “Firmware Upgrade”
    2. In the top box change the URL to “http://thehackbox.org/tasmota/sonoff.bin”
    3. Press “Start Upgrade”
  8. Update the name of your device under “Configure Other” and then “Friendly Name”

7. Configure your specific device

  1. On the main tasmota screen click “Configuration”.
  2. Click “Configure Module”
  3. Consult the list of known devices to input the correct GPIO pins and chips for your device.
  4. Press “Save” and enjoy!

Posted in: Tutorials

How to Setup a Raspberry Pi Nextcloud Server

For this project, we will be showing you how to setup and configure a Raspberry Pi NextCloud Server, this can act as your own personal “cloud” storage system.

As time goes on the protection of your own privacy with 3rd party companies becomes harder and harder. This is where software like Nextcloud comes in hand, as it gives you full control over your files with no 3rd party controller.

It is important to remember that since your data will be stored on your local network you will end up using a lot of bandwidth when uploading and downloading files from outside your local network. If your internet connection is not great then you may not get the best experience if you plan on using it outside your local network.

If this looks familiar then that’s because it likely is, Nextcloud is an actively maintained fork of the owncloud software that I have previously covered. The longer it’s in development the more different these two software packages will likely become, I suggest looking into both and then deciding on which one to go with.

If you want to learn more about Nextcloud, you can check out the nextcloud website.

Note: The USB ports on a Raspberry Pi are typically unable to power an external hard drive. If you find this the case and your hard drive doesn’t use an external power supply then I recommend looking into buying a powered USB hub for the Pi.

Equipment List

You can find all the bits and pieces that I used/recommend for this Raspberry Pi nextcloud tutorial right below.


Raspberry Pi 2 or 3

Micro SD Card or a SD card if you’re using an old version of the Pi.

Ethernet Cord or Wifi dongle (Pi 3 has WiFi inbuilt)

External Hard drive or USB Drive


Raspberry Pi Case

USB Keyboard

USB Mouse

Installing Apache and PHP

To run Nextcloud on the Raspberry Pi we will first need to install and setup Apache and PHP. We won’t be going too in-depth into installing these as they are a minor components to this tutorial. If you want to learn more about setting up a Web Server, then be sure to follow our tutorial on how to do this.

For the best performance I recommend using Raspbian lite but just normal Raspbian will also work just as well. If you need information on how to set this all up check out the guide in the Pi operating systems section.

For this tutorial, we will only be utilizing PHP 5.

1. To get started let’s first update our package repositories with the following command:

sudo apt-get update
sudo apt-get upgrade

2. With that done, let’s now install apache with the following command:

sudo apt-get install apache2

You can check to make sure Apache2 is successfully up and running by going to your Pi’s IP address, this should load a default Apache Page. If you are unsure on what your Raspberry Pi’s local IP address is then type in hostname -I into the terminal.

3. With Apache2 now installed onto the Raspberry Pi we just need to install PHP and several of its packages, for this tutorial we will be just using PHP5 as PHP7 is not readily available for Raspbian, if you want to use PHP7 be sure to follow our Web Server tutorial.

To install PHP and the packages we need, run the following commands:

sudo apt-get install php5 php5-gd sqlite php5-sqlite php5-curl

4. With Apache and PHP now installed there is one final thing we need to do, and that is to restart Apache. You can do this with the following command:

sudo service apache2 restart 

Installing Nextcloud

Installing Nextcloud to the Raspberry Pi is quite simple, it mainly involves downloading the script from their website, extracting the zip and then going to your Raspberry Pi’s IP address.

1. To get started let’s first move to our html directory with the following command:

cd /var/www/html

2. Now we can run the following curl command so we can download and extract the latest version of Nextcloud in one go.

curl https://download.nextcloud.com/server/releases/nextcloud-11.0.2.tar.bz2 | sudo tar -jxv

3. Now for the next few steps we need to change directory into our newly unzipped folder, to do this run the following command.

cd /var/www/html/nextcloud

4. We now need to create a data directory for Nextcloud to operate in, for the initial setup of Nextcloud we must make this folder in our html/nextcloud directory. Do that with the following command:

sudo mkdir -p /var/www/html/nextcloud/data

5. Now let’s give the correct user and group control over the data folder by running the following command.

sudo chown www-data:www-data /var/www/html/nextcloud/data

6. Finally we need to give it the right permissions, again run the following command:

sudo chmod 750 /var/www/html/nextcloud/data

7. We are not quite done dealing with permissions, there is one final thing we must do and that is give the www-data group control over the config and apps folder. Run the following command to do this:

sudo chown www-data:www-data config apps

8. Now that we have finished with that we can now finally go to Nextcloud itself and begin its installation process. To begin go to your Raspberry Pi’s IP address plus /nextcloud. For example, the address I would go to is the following:

Remember to replace my IP Address with that of your Raspberry Pi’s .

9. You will now be greeted with the following screen, here you will need to type in the Username and Password that you intend to use for your admin account. If you plan on allowing your Nextcloud file service to be accessible from outside your network, make sure that you use a long and secure password.

Once you are happy with this, press the “Finish Setup” button, please note this can take some time to complete as it finalises your setup.

Nextcloud Login

10. After this you should now be greeted with the following welcome screen, this just lays out the various programs you can use to connect with your Nextcloud installation. Just press the X button in the top right corner to continue.

Nextcloud Welcome Screen

11. Now you can finally see the interface of the Raspberry Pi Nextcloud, you should take some time to familiarize yourself with all the functionality of Nextcloud’s interface.

We won’t go too in depth on how to use the Nextcloud interface, if you need more information then I recommend checking out the support section on nextcloud. We have however highlighted some of the key areas to check out in the screenshot below.

Nextcloud Files Screen

Moving Nextcloud’s data folder

With Nextcloud now safely installed we can now tweak the setup to both be more secure and a bit more useable, one of the first things we should do is move the data directory so it does not sit in our web accessible directory.

This is also the same way you would move your Nextcloud data directory onto a larger external hard drive rather than putting increased load onto the Raspberry Pi’s SD Card.

1. To get started let’s make our new directory for where we will store our data files, to make it easy we will make a new folder at /var/nextcloud and move our data folder into there.

Create the folder by running the following command:

sudo mkdir -p /var/nextcloud

2. With our new folder we created we will now move our data directory into it, this is easy to do thanks to the mv command. Please note that your Nextcloud system will be out of action while we move the file then adjust the configuration file.

To begin the move type in the following command:

sudo mv -v /var/www/html/nextcloud/data /var/nextcloud/data

3. Now with the files moved over we can now modify the datadirectory configuration to point to our new directory. First, let’s change to the config directory for Nextcloud with the following command.

cd /var/www/html/nextcloud/config

4. We can now copy the config file to make a backup of the file, we can do this with the following command:

sudo cp -p config.php config.php.bk

5. Finally let’s open up the config.php file for editing using nano.

sudo nano config.php

6. Within this file we need to change the following line:

'datadirectory' => '/var/www/html/nextcloud/data',


'datadirectory' => '/var/nextcloud/data',

7. Now we can save and quit out of the file by pressing Ctrl+X then Y and then Enter.

You should be able to now refresh your web browser and all your files should be showing exactly as they were previously.

Increasing Nextcloud’s max upload size

By default, PHP has a very low upload limit, so low it’s only 2 MB. To change this, we need to modify the php.ini file and increase the limit. A cloud storage system wouldn’t be very useful if you could only ever upload 2mb files.

1. To get started we need to begin editing the configuration file with the following command:

sudo nano /etc/php5/apache2/php.ini

2. Now we need to find and replace the following two lines.

post_max_size = 8M
upload_max_filesize = 2M


post_max_size = 1024M
upload_max_filesize = 1024M

Of course, you can set the file size limits to something that is much higher than 20M, so feel free to change that number to whatever you think is the maximum size file you will upload to your Nextcloud.

3. Now we can save and quit out of the file by pressing Ctrl +X then pressing Y and then Enter.

Now we need to restart Apache2 to force it to read in the updated configuration file. We can do that easily with the following command:

sudo service apache2 restart

4. You should now be able to restart your web browser and begin a new upload to see that the maximum upload size has been increased successfully.

Allowing the .htaccess override

Next, we need to deal with the .htaccess file for Nextcloud. Since we installed Nextcloud into the default Apache2 directory /var/www/html, we will need to change some settings in Apache2 to allow the .htaccess file to override settings.

1. To get started we can begin editing the file with the following command:

sudo nano /etc/apache2/apache2.conf

2. With the file now open we need to find the following block, you can also use Ctrl + W to help find the block.

<Directory /var/www/>        
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted


<Directory /var/www/>        
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

3. Now we can save and quit out of the file by pressing Ctrl +X then pressing Y and then Enter.

4. Now we need to restart Apache2 to force it to read in the updated configuration file. We can do that easily with the following command:

sudo service apache2 restart

5. You can check whether the changes have successfully worked by going into the settings page on Nextcloud. Any warning about the .htaccess file not working correctly should now be gone.

Setting up SSL for Nextcloud

Now we should really work on setting up your Raspberry Pi Nextcloud server so that it runs through HTTPS and not plain HTTP. For this tutorial, we will assume that you do not have a domain name, so we will be generating our own self signed certificate and not utilizing one from a free service such as Letsencrypt.

1. Before we go modifying our Apache2 configuration we will first generate the self-signed certificate, luckily, we can do this all in one command thanks to OpenSSL.

Remember that a self-signed certificate will throw errors in your web browser and is not as secure as a properly signed certificate but it is better than nothing. It is also the only option if you’re not utilizing a domain name.

Before we generate the certificate, let’s first make a directory to store it.

sudo mkdir -p /etc/apache2/ssl

2. Now let’s generate the certificate itself by running the following command in the terminal:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

If you want to know exactly what these command arguments do, then read our little description below.

req: This specifies a subcommand for X.509 certificate signing request (CSR) management.

-x509: This option specifies that we want to make a self-signed certificate file instead of generating a certificate request.

-nodes: This tells the openssl application that we don’t want to specify a passphrase, a passphrase will require us to enter it every time Apache is restarted which is painful to deal with.

-days 365: This specifies the amount of days we want the certificate to remain valid for, after this amount of days you will have to generate a new certificate.

-newkey rsa:4096: This will create the certificate request and a new private key at the same time. You will need to do this since we didn’t create a private key in advance. The rsa:2048 tells OpenSSL to generate an RSA key that is 2048 bits long.

-keyout: This parameter names the output file for the private key file that is being created.

-out: This option names the output file for the certificate that we are generating.

After pressing enter you will be presented with the following options to fill out.

Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

3. Once you have filled out all that information we can then proceed on with setting up Apache2 to run SSL and to also utilize our newly generated certificate. This is a simple process but an important one.

First let’s enable the SSL module for Apache with the following command:

sudo a2enmod ssl

4. Now we need to modify the default-ssl.conf file so it will utilize our new certificates and not the default ones that are generated by OpenSSL on installation.

To begin modifying this file run the following command:

sudo nano /etc/apache2/sites-available/default-ssl.conf

5. Within this file we need to change the two lines below to point to our new certificates we generated into our /etc/apache2/ssl folder.


SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key


SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

6. Now we can save and quit out of the file by pressing Ctrl+X then pressing Y and then Enter.

7. We can now enable the default-ssl configuration and restart Apache to load in our new configuration. We can do this with the following two commands.

sudo a2ensite default-ssl.conf
sudo service apache2 restart

8. You can test to make sure this is working by going to your Raspberry Pi’s IP address with https:// in front of it. It will give you a warning about it potentially being an invalid certificate. This is normal as it is an unsigned certificate.

For instance to make sure my own copy of Nextcloud is now running behind SSL I would go to the following:

9 (Optional). An extra step to ensure that you have the best security for your Nextcloud setup is to enforce SSL so no connection can be made over HTTP, if a connection is made it will redirect you to HTTPS.

We can do this by making some changes to our apache configuration, to begin let’s edit the default file with the following command:

sudo nano /etc/apache2/sites-available/000-default.conf

10 (Optional). Replace all the text in this file with the code below. This will basically redirect all HTTP traffic to its HTTPs equivalent.

<VirtualHost *:80>
   ServerAdmin example@example

   RewriteEngine On
   RewriteCond %{HTTPS} off
   RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

11 (Optional). Now we can save and quit out of the file by pressing Ctrl +X then pressing Y and then Enter.

12 (Optional). Now before this will work we need to enable the redirect module and restart apache. We can easily achieve this by running the following two commands:

sudo a2enmod rewrite
sudo service apache2 restart

Now going to your Raspberry Pi on HTTP should automatically redirect to the HTTPS version. For example, if I go to it will redirect to

Portforwarding Nextcloud

Finally, onto the section about port forwarding Nextcloud. We won’t go into too much depth on the ins and outs of port forwarding for your router but we will tell you what ports need forwarding. We will also mention what changes need to be made to Nextcloud for this to work.

Before we get started with this section you need to know that Nextcloud will only operate under specifically specified trusted domains. Which means you will need to either specify a domain name that you want to use for your connection or use your public IP address.

Since most home public IP addresses are dynamic you will need to look into setting up a dynamic DNS service, you will find our tutorial on how to setup a dynamic DNS service for your Raspberry Pi very handy.

1. To add your domain/IP we need to modify NextCloud’s configuration file, we can do that by running the following command:

sudo nano /var/www/html/nextcloud/config/config.php

2. Within this file you will see a block of text like below. This is an array of all trusted domains that you allow Nextcloud to operate through. For now, it should only include your Raspberry Pi’s local IP address. We will add our new domain/IP onto the end of this array.

'trusted_domains' =>
array (
    0 => '',

For our example, we will be adding nextcloud.pimylifeup.com to the array. This means we need to increment the array ID and add the domain name. Once you have added a new one it should look something like below. Repeat this procedure for any new IP’s or domains you want Nextcloud to be able to operate through.

'trusted_domains' =>
array (
    0 => '',
    1 => 'nextcloud.pimylifeup.com',

3. Now we can save and quit out of the file by pressing Ctrl+X then pressing Y and then Enter.

4. Finally you will need to port forward two ports to finally have Nextcloud up and running. These two ports being Port 80 and Port 443. The protocol required for these is TCP.

Hopefully by now you should have a fully operational Raspberry Pi Nextcloud Server. If you come across any issues or have some feedback related to this tutorial, then please don’t hesitate to leave a comment below.

Thanks: https://pimylifeup.com/raspberry-pi-nextcloud-server/

Happy smart-homing 🙂

Raspberry Pi Zero–VNC Server/Client Setup

Installing VNC

SSH (see http://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh/overview) is often all you need to control your Raspberry Pi, however sometimes it is useful to be able to remote control your Raspberry Pi using the mouse and seeing just what you would see on the screen of the Raspberry Pi. 

VNC (Virtual Network Connection) is a standard for doing just this. To use it, you have to install some software on your Pi. There are a number of VNC server applications, and the one we are going to use is called “tightvnc”.

We can install the VNC server software using the SSH connection that we established earlier.

Enter the following command into your SSH terminal:

Copy Code

  1. sudo apt-get update
  2. sudo apt-get install tightvncserver


You will be prompted to confirm installation by typing “Y’ and finally when installation is complete, you should see the following:


We now need to run the VNC Server, so enter the following command into your SSH window:

Copy Code

  1. vncserver :1


You will be prompted to enter and confirm a password. It would make sense to use “raspberry” for this, but passwords are limited to 8 characters, so I use “raspberr”. Note that this is the password that you will need to use to connect to the Raspberry Pi remotely.

You will also be asked if you want to create a separate “read-only” password – say no.

From now on, the only command that you need to type within your SSH to start the VNC server will be:

Copy Code

  1. vncserver :1

The VNC server is now running and so we can attempt to connect to it, but first we must switch to the computer from which we want to control the Pi and setup a VNC client to connect to the Pi.

Using a VNC Client

Again, there are many VNC clients, of which “VNCViewer” (http://www.realvnc.com) is available for most platforms and I have found it to work well with TightVNC.

When you first run VNCViewer, you will see the following:


Enter the IP address of your Raspberry Pi, append :1 (to indicate the port) and click on “Connect”. You will then get a warning message. Just click ‘Continue’.


The following window will then popup for you to enter your password (“raspberr”).


Finally, the VNC window itself should appear. You will be able to use the mouse and do everything as if you were using the Pi’s keyboard mouse and monitor, except through your other computer.

As with SSH, since this is working over your network, your Pi could be situated anywhere, as long as it is connected to your network.


Built in Screen Sharing

There’s also a built in VNC app for the Mac OS X that you may be able to use without installing any software
From the Finder, select Go -> Connect to Server… and typevnc:// (or whatever the IP is) to connect.

Running VNCServer at Startup

This method will only work if you have set your Pi to automatically log into the desktop environment. See Lesson 2.

Connecting to your Raspberry Pi remotely with VNC is fine as long as your Pi does not reboot. If it does, then you either have to connect with SSH and restart the VNC Server or arrange for the VNC Server to run automatically after the Raspberry Pi reboots.

There are several different methods of arranging for some code to be run as the Pi starts. The method described below is probably the easiest to use. You can adapt it to run other commands instead of starting the VNC server.

Step 1.

Open a Terminal session on the Pi, or connect using SSH. A new terminal or SSH session will automatically start you off in your home directory of /home/pi. If you are not in this directory, change to it by typing:

Copy Code

  1. $ cd /home/pi

Then cd to the .config directory by typing:

Copy Code

  1. $ cd .config

Note the ‘.’ at the start of the folder name. This makes it a hidden folder that will not show up when you type ‘ls’.

Step 2.

Issue the command below to create a new directory inside .config called ‘autostart’.

Copy Code

  1. $ mkdir autostart

cd into that new directory by typing:

Copy Code

  1. $ cd autostart


Step 3.

All that remains is to edit a new configuration file. So type the following command to open the nano editor on the new file:

Copy Code

  1. $ nano tightvnc.desktop

Edit the contents of the file with the following text.

Copy Code

  1. [Desktop Entry]
  2. Type=Application
  3. Name=TightVNC
  4. Exec=vncserver :1
  5. StartupNotify=false


Type ctrl-X and then Y to save the changes to the file.

Thats all there is to it. The next time you reboot the VNC server will restart automatically.

Source – https://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc/installing-vnc

Thanks to Simon Monk.

Happy Coding Smile