Sunday 25 October 2020

Unlock and Configure Tuya Lightbulbs

Procedure to install Tasmota FOSS firmware on Tuya lightbulbs, configure them and set them up for use with FHEM

  • Flash Tasmota firmware to lightbulb using this procedure.
  • If something goes wrong during the flashing process, and lightbulb presents a "vtrust-recovery" WiFi access point, follow this procedure (connect to AP and then surf to http://10.42.42.42/undo)
  • After flash is complete and lightbulb has rebooted, the bulb will present a WiFi AP named "tasmota-XXXX" or similar.  Connect to the AP and surf to http://192.168.4.1 to connect to the Tasmota web interface of the bulb.
  • On the web interface, click on "Configuration", then "Configure WiFi" - enter AP details of the router.  Bulb restarts and connect to the router AP
  • Look for the bulb's IP number in the list of DHCP leases on the router's web interface
  • Surf to the bulb IP in a web browser (using http://) and continue configuration.
    • Apply Template:
      • Go to this page and find the type of lightbulb
      • In the web interface, click on "Configuration", then "Configure Other" - copy the configuration string found in the previous step into the "Template" field, check "Activate" and save.  See here for details of the procedure.
    • Configure MQTT: In the web interface, click on "Configuration", then "Configure MQTT"
      • Enter the local hostname of the server running FHEM (or other MQTT application). Enter port number 1883.
      • Copy and paste string from "Client" to "Topic" as described here and here
      • The bulb will be added by FHEM as a a device automatically
    • Set Default On: In the bulb's web interface, go to the Main Menu, then  "Console". Enter the following PowerOnState command: "PowerOnState 1"
      This will make the lightbulb switch on by default when powered on. This allows for normal manual on/off operation of the bulb with a mechanical switch
    • Also enter "SetOption0 0" - this stops the bulb from saving the power state when restarting (bulb will always be in "off" state after a restart)

Saturday 15 October 2016

Install VirtualBox headless on CentOS

This is a basic outline of the actions to install VirtualBox headless on CentOS. It is mostly for my own notes, but I share it here.
This log is based on CentOS 6.8 and VirtualBox 5.1. It may need to be modified for other versions.

1. Add the Virtual Box yum repository from Oracle website


$ cd /etc/yum.repos.d
$ sudo wget http://yum.oracle.com/public-yum-ol6.repo


2. Edit public-yum-ol6.repo


$ sudo nano public-yum-ol6.repo

Remove everything except the Oracle Linux addons from the repo, so it looks like this:

[ol6_addons]
name=Oracle Linux $releasever Add ons ($basearch)
baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/addons/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1


3. Download and import Oracle GPG keys


Instructions at Oracle website

$ wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
$ gpg --quiet --with-fingerprint ./RPM-GPG-KEY-oracle-0l6

If the fingerprint matches with the published Oracle fingerprint, import the key:
$ sudo rpm --import ./RPM-GPG-KEY-oracle-ol6

4. Install Dependencies


$ sudo yum install gcc make
$ sudo yum install kernel-devel


You may need to replace kernel-devel with a substitute, such as vzkernel-devel, depending on your set up. If unsure, do not install this dependency for now and see the error message that comes up during the installation of VirtualBox

5. Install VirtualBox


Since this is a headless installation, we do not want to pull in the X/Qt/Mesa etc. dependencies. Yum does not have functionality to omit dependencies, so we need to use rpm directly.
$ sudo rpm -Uvh --nodeps $(repoquery --enablerepo ol6_addons --location VirtualBox-5.1)

6. Add users to vboxusers group


$ sudo usermod -a -G vboxusers username

7. Install VirtualBox extension pack


$ wget http://download.virtualbox.org/virtualbox/5.1.6/Oracle_VM_VirtualBox_Extension_Pack-5.1.6-110634.vbox-extpack
$ sudo VBoxManage extpack install ./Oracle_VM_VirtualBox_Extension_Pack-5.1.6-110634.vbox-extpack


7. Create and run Virtual machines with headless frontend


follow instructions in the VirtualBox manual

Wednesday 22 June 2016

Aktuelle Lindenstraße Folgen automatisch hernunterladen.

Seitdem die Website der Lindenstraße im November 2015 erneuert wurde, ist es schwieriger geworden, die Lindenstraße Folgen als video herunterzuladen. Früher konnte man die URL direkt zu den Videodateien im .flv Format rein aus der Nummer der Folge ermitteln. Nun geht das nicht mehr, und statt dessen muß man mehrere Webseiten und ein Java Skript parsen, um an die URL der Videodatei (nun im .mp4 Format) zu gelangen.

Das folgende shell script (POSIX compliant) dient dem automatischen Herunterladen der Lindenstraße Folgen, die von der ARD zum Download bereitgestellt werden.  Wenn Ihr es einmal wöchentlich von einer crontab aufruft, bekommt Ihr immer die letzte auf der Lindenstraße Website aktuelle Folge heruntergeladen.

Dieses Shell Script ist für Linux und andere Un*x-like Betriebssysteme.  Für Windoof User: Neuerdings gibt es unter Windows 10 eine Linux Bash Shell.  Das Shell Script läuft womöglich damit auch unter Windows, allerdings wurde dies bislang noch nicht getestet.  Ansonsten kann man das Skript auch unter cygwin laufen lassen.

Das Skript kann mit folgenden Argumenten aufgerufen werden:

[-q] [--res=N] [Folge]

Alle Argumente sind optional.

Wird keine Folgennummer als Argument mitgegeben, so lädt das Skript die neueste Folge herunter. Wenn eine Folgennummer angegeben wird, wird die entsprechende Folge, soweit auf der ARD Website vorhanden, heruntergeladen.

Mit der Option --res kann die Videoauflösung gewählt werden. Als Argument kann eine Zahl zwischen 1 und 3 angegeben werden, wobei 1 die höchste und 3 die niedrigste Auflösung ist.  Wird keine --res Option angegeben, so wird die Folge in der höchsten Auflösung heruntergeladen.

Die Option -q oder --quiet unterdrückt die Ausgabe (sinnvoll für Aufrufe aus einer crontab)

Die "savepath" variable könnt Ihr nach Bedarf anpassen (insbesondere bei Aufruf aus einer crontab). Ansonsten wird die Folge ins aktuelle Verzeichnis mit dem Prefix "lindenstrasse" gespeichert.

#!/bin/sh

base_url="http://www1.wdr.de"
path_url=$base_url"/daserste/lindenstrasse/"
videos=$path_url"videos/"
liste=$videos"videos-der-folgen-100.html"
index=$path_url"index.html"
savepath="lindenstrasse"

# Set resolution default value (first resolution in url)
resol=1
folge=""

usage () {
echo "Usage: $0 [-q] [--res=N] [Folge]" >&2
exit 1;
}

err () {
echo "wget or parse error" >&2
exit 1;
}

# NDP used as a counter to catch more than one non-option argument
NDP=0

while [ "$1" != "" ]; do
    PARAM=`echo $1 | awk -F= '{print $1}'`
    VALUE=`echo $1 | awk -F= '{print $2}'`
    case $PARAM in
 -h | --help)
     usage
     ;;
 -q | --quiet)
     qarg="-q"
     ;;
 --res)
     resol=$VALUE
     case $resol in
        ''|*[!1-3])
   echo "ERROR: Resolution must be a number between 1 and 3"
   usage
   ;;
     esac
     ;;
 *)
     case $NDP in
  0)
      NDP=$((NDP+1))
      folge=$PARAM
      ;;
  *)
      # if we are not here for the first time, there are too many non-option arguments
      usage
      ;;
            esac
            ;;
    esac
    shift
done

# no folge set - download latest
if [ -z "$folge" ]; then
 if ! [ "$qarg" == "-q" ]; then  echo "Downloading latest episode."; fi 
 href_tag=$(wget $qarg -O - $index | grep -B1 -m1 "zur aktuellen Folge" | tr -d "\n") || err
 folge=$(echo $href_tag | sed 's/.*Folge \([0-9]*\).*/\1/') || err
fi

case $folge in
    [1-9][0-9][0-9][0-9])
 href_tag=$(wget $qarg -O - $liste | grep -B9 -m1 "Folge ${folge}" | tr -d "\n") || err
 ;;
    *)
 echo "ERROR: Folge must be a number between 1000-9999"
 usage
 ;;
esac


# Test if $href_tag contains data
if [ -z "$href_tag" ]; then 
   if ! [ "$qarg" == "-q" ]; then
      echo "Folge ${folge} not found"
   fi
   exit 1;
fi

url=$base_url$(echo $href_tag | sed "s/.*<a href=\"\(.*html\).*/\1/") || err

#echo $url; exit


url=$(wget $qarg -O - $url | grep -o -m1 'data-extension.*}}' | grep -o 'http:.*\.js') || err


#url=$(wget $qarg -O - $url | grep -o '"alt":{"videoURL".*}' | grep -o 'http:.*\.mp4') || err

resol=$(expr ${resol} + 1 )

url=$(wget $qarg -O - $url | grep -o '"dflt":{"videoURL".*}' | grep -o -m1 'http:.*\.f4m' | cut -d',' -f1,${resol},5) || err

# need to translate like this
#http://adaptiv.wdr.de/z/medstdp/ww/fsk0/89/891425/,891425_9779266,.mp4.csmil/manifest.f4m
#http://ondemand-ww.wdr.de/medstdp/fsk0/89/891425/891425_9779266.mp4

url=$(echo ${url} | grep -o 'http:.*\.mp4' | tr -d ',' | sed 's/adaptiv/ondemand-ww/' | sed 's#z/##' | sed 's#ww/##') || err

if ! [ "$qarg" == "-q" ]; then
   echo "Downloading Folge: $folge"
fi

wget $qarg -O ${savepath}${folge}.mp4 $url || err

Saturday 12 December 2015

"Lindenstraße vor 15 Jahren" videos automatisch herunterladen

Seitdem die Website der Lindenstraße im November 2015 erneuert wurde, ist es schwieriger geworden, die Lindenstraße Folgen als video herunterzuladen. Früher konnte man die URL direkt zu den Videodateien im .flv Format rein aus der Nummer der Folge ermitteln. Nun geht das nicht mehr, und statt dessen muß man mehrere Websseiten und ein Java Skript parsen, um an die URL der Videodatei (nun im .mp4 Format) zu gelangen.

Das folgende Sell Script (POSIX compliant) dient dem automatischen Herunterladen der aktuellen "Lindenstraße vor 15 Jahren" Folge. Wenn Ihr es einmal wöchentlich von einer crontab aufruft, bekommt Ihr immer die letzte auf der Lindenstraße Website aktuelle Folge heruntergeladen.

Dieses Shell Script is für Linux und andere Un*x-like Betriebssysteme.  Für Windoof User: Neuerdings gibt es unter Windows 10 eine Linux Bash Shell.  Das Shell Script läuft womöglich damit auch unter Windows, allerdings wurde dies bislang noch nicht getestet.  Ansonsten kann man das Skript auch unter cygwin laufen lassen.

Die "savepath" variable könnt Ihr nach Bedarf anpassen (insbesondere bei Aufruf aus einer crontab). Ansonsten wird die Folge ins aktuelle Verzeichnis mit dem Prefix "lindenstrasse" gespeichert.  

Die Option -q oder --quiet unterdrückt die Ausgabe (sinnvol für Aufrufe aus einer crontab)

#!/bin/sh

base_url="http://www1.wdr.de"
index=$base_url"/daserste/lindenstrasse/videos/index.html"
savepath="lindenstrasse"

# Set resolution default value (first resolution in url)
resol=1

usage () {
echo "Usage: $0 [-q] [--res=N]" >&2
exit 1;
}

err () {
echo "wget or parse error" >&2
exit 1;
}

while [ "$1" != "" ]; do
    PARAM=`echo $1 | awk -F= '{print $1}'`
    VALUE=`echo $1 | awk -F= '{print $2}'`
    case $PARAM in
-h | --help)
   usage
   ;;
-q | --quiet)
   qarg="-q"
   ;;
--res)
   resol=$VALUE
   case $resol in
      ''|*[!1-3])
echo "ERROR: Resolution must be a number between 1 and 3"
usage
;;
   esac
   ;;
*)
   usage
            ;;
    esac
    shift
done

href_tag=$(wget $qarg -O - $index | grep -A8 -m1 "vor 15 Jahren" | tr -d "\n") || err
url=$base_url$(echo $href_tag | sed 's/.*<a href="\(.*html\).*/\1/') || err

href_tag=$(wget $qarg -O - $url | grep -C0 -m1 "Folge " | tr -d "\n") || err
folge=$(echo $href_tag | sed 's/.*Folge \([0-9]*\).*/\1/') || err

url=$(wget $qarg -O - $url | grep -o 'data-extension.*}}' | grep -o 'http:.*\.js') || err

resol=$(expr ${resol} + 1 )

url=$(wget $qarg -O - $url | grep -o '"dflt":{"videoURL".*}' | grep -o 'http:.*\.mp4' | cut -d',' -f1,1,${resol},6) || err

url=$(echo ${url} | grep -o 'http:.*\.mp4' | tr -d ',' | sed 's/adaptiv/ondemand-ww/' | sed 's#z/##' | sed 's#ww/##') || err

if ! [ "$qarg" == "-q" ]; then
   echo "Downloading Folge $folge"
fi

wget $qarg -O ${savepath}${folge}.mp4 $url || err