Garage Door Opener with WiFi

20180811_214138I bought this switch from Amazon its listed as the wireless garage door opener remote WiFi switch universal. I connected terminals L and N to 110 volt AC power I connected this to twelve volts DC on the red and black wires and the black and green wire to a door magnetic contact sensor for an indicator to let me know if the door is open or closed. The light in the bottom center is the indicator for open or closed door. Light on door is open and off is closed.

20180811_215539The instructions are a bit weak so I’m unsure what that red wire is for, I’m just going to cap it off for now. Even the instructions on the back of the device seem a bit unclear. The paper that came inside the box had the usual small print that required a magnifying glass and just wasn’t clear. It turns out using the red and black wire connected to a 9-30V DC power supply this can be run without the AC connection I tested with.

20180811_210041A will be for the positive to the garage door opener and Com to the negative. You can use B and Com for a second door and C and Com for a third door or gate. However you only get one open and close indicator for all three. I’m going to use this to replace the wall switch for the garage door and give me the option to use WiFi to open and close the door as well as monitor the status of the door. I also ordered a type 86 wall junction box to put this in and mount it to the wall.

I used the Tuya Smart phone app for control and integrated this with my Home Assistant setup running on a Raspberry Pi. I chose Tuya Smart because I already have this setup for several other devices.

screenshot_20180811-224539_tuyasmart

screenshot_signal_strength

The device has lost the WiFi signal several times. I exchanged a couple of emails with the seller HeJue and that has proved pretty useless so far as the emails just seem to generate a couple of canned replies.

“Hi Jonathan Smith, Sorry for the inconvenience. First of all, we need to confirm a question with you, have you connected all the wires correctly? Can you control the opener by touch our switch button? If yes, it means that the wiring are correct. Then comes to check the WIFI. Pls kindly make sure that your WIFI router is 2.4G, attached is the FAQ list for your reference, pls kindly check it to make sure your WIFI meed the demands. Waiting for your reply. Regards, Hejue”

Since it does work but is dropping the WiFi connection randomly, I’ll guess the wiring is correct. I ended up setting up a cronjob with two pings every five minutes and this has kept the device online for about forty eight hours now. Rock solid for over a week now.

It looks like these are just a NodeMCU with momentary relays and the power supply built in. Below is what it looks like in Home Assistant. For some reason Home Assistant doesn’t see my renaming of Button A to Garage Door. With a restart of Home Assistant it eventually picked up on the renames.

Screenshot 2018-08-11 at 10.52.04 PM

Cable Modem Woes

I’ve since returned this modem and have basic modem with one ethernet port and phone jacks. I was using an Arris cable modem which is proving to be garbage.

System: ARRIS DOCSIS 3.0 / PacketCable 2.0 Touchstone Telephony Gateway
HW_REV: 5
VENDOR: Arris Interactive, L.L.C.
BOOTR: 1.2.1.61
SW_REV: 7.5.63C.SIP.PC20.TW
MODEL: TG862G
Battery Charger FW Rev: 02.10
 Firmware Build and Revisions
Firmware Name: TS070563C_032913_MODEL_862_GW_TW_SIP_PC20
Firmware Build Time: Fri Mar 29 11:42:55 EDT 2013
eSAFE 0 FW Revision: 2.0.40_0920E

I tried to do DHCP reservations and it seems these just fail with no error displayed.  I wanted to change the subnet it uses and that isn’t allowed either. Wireless seems to lock up randomly and requires a reboot. I have multiple AP’s and funnel DHCP back to the Arris so usually I just end up on an AP that is farther away that what is ideal for my setup.

I built a DHCP server on my Raspberry Pi as a work around to not being able to reserve an IP and have that working smoothly for a couple of days now. I’m considering getting a different modem with out wireless or the phone ports ( I don’t use the phone ports) and then maybe a Ubiquiti Networks UniFi AP Enterprise WiFi System UAP-3 and using that so all of my APs would be from one manufacturer and work together better. Currently I’m using a mish mash between the cable modem and other old AP’s that people have discarded. I just don’t want to spend the $180 or so that it costs to get this equipment and use Ubiquiti’s proprietary POE.

Upgrade Kankun Smart Plug

To preserve some changes and files I added. Add their path to sysupgrade.conf, in my case this is /www/ and /www/cgi-bin/.

# cat /etc/sysupgrade.conf

## This file contains files and directories that should
## be preserved during an upgrade.

# /etc/example.conf
# /etc/openvpn/
/www/
/www/cgi-bin/
root@cat:/rom/www/luci-static#

 

Download the upgrade to /tmp/

wget -O /tmp/openwrt-15.05.1-ar71xx-generic-tl-wr703n-v1-squashfs-sysupgrade.bin http://downloads.openwrt.org/chaos_calmer/15.05.1/ar71xx/generic/openwrt-15.05.1-ar71xx-generic-tl-wr703n-v1-squashfs-sysupgrade.bin

Run the upgrade and set back and wait. One site I found on the web said they had problems with wireless being disabled after running sysupgrade -c on one of three attempts. If that happens it means I’ll be opening the case and soldering pins to the headers to get wireless enabled again.

sysupgrade -c /tmp/openwrt-15.05.1-ar71xx-generic-tl-wr703n-v1-squashfs-sysupgrade.bin

BusyBox v1.23.2 (2016-01-02 18:01:44 CET) built-in shell (ash)

W I R E L E S S F R E E D O M
—————————————————–
CHAOS CALMER (15.05.1, r48532)
—————————————————–
* 1 1/2 oz Gin Shake with a glassful
* 1/4 oz Triple Sec of broken ice and pour
* 3/4 oz Lime Juice unstrained into a goblet.
* 1 1/2 oz Orange Juice
* 1 tsp. Grenadine Syrup
—————————————————–

root@cat:~#

Seems like it worked, the plug is sitting there with a blue light like it is still upgrading.

root@cat:~# cat /etc/openwrt_release
DISTRIB_ID=’OpenWrt’
DISTRIB_RELEASE=’15.05.1′
DISTRIB_REVISION=’r48532′
DISTRIB_CODENAME=’chaos_calmer’
DISTRIB_TARGET=’ar71xx/generic’
DISTRIB_DESCRIPTION=’OpenWrt Chaos Calmer 15.05.1′
DISTRIB_TAINTS=”
root@cat:~# cat /etc/openwrt_version
15.05.1
root@cat:~#

After the install finished I was good and logged back in using the password that I had set for root. The relay didn’t work to turn the switch on and off  but adding two lines to rc.local corrected this problem.

echo 26 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio26/direction

After doing that and testing with a couple of reboots I can run the commands below to turn the outlet on and off from the CLI or go to the web page that I build and do the same there. Just the line with the word echo in them.

#ON:
#echo 1 > /sys/devices/virtual/gpio/gpio26/value
#OFF:
#echo 0 > /sys/devices/virtual/gpio/gpio26/value

Space is at a premium on this device after the upgrade.

root@corner:~# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 1.0M 256.0K 768.0K 25% /
/dev/root 2.0M 2.0M 0 100% /rom
tmpfs 14.2M 68.0K 14.1M 0% /tmp
/dev/mtdblock3 1.0M 256.0K 768.0K 25% /overlay
overlayfs:/overlay 1.0M 256.0K 768.0K 25% /
tmpfs 512.0K 0 512.0K 0% /dev
root@corner:~# exit
root@cat:/~# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 512.0K 396.0K 116.0K 77% /
/dev/root 2.3M 2.3M 0 100% /rom
tmpfs 14.0M 64.0K 13.9M 0% /tmp
/dev/mtdblock3 512.0K 396.0K 116.0K 77% /overlay
overlayfs:/overlay 512.0K 396.0K 116.0K 77% /
tmpfs 512.0K 0 512.0K 0% /dev
root@cat:~#

Smartthings is broken now and I can’t use voice commands on Alexa for this plug either until I sort that out.

 

Wemo Lights

I wanted a way to control my Smart Home devices inside the house if I had no Internet connection. I have a mix of Wemo and Kankun plugs right now that I’m using to control various lamps and my outdoor light.

I built a small web page on my Raspberry Pi with buttons for each device. I need to do a lot of cleanup to get the buttons lined up but what I used for the Wemo devices had a lot of padding around each image that was used. The small red light indicates the switch is on, on the Driveway button no light indicates it is off.

pi-webpage

Below is an image from the Wemo pages that I replaced with the buttons shown above.

on-1

For Wemo’s I used the instructions found here. I had a fair amount of trouble getting this working correctly because of permission issues. First it wouldn’t build the database because of a missing line at the top of wemo_backend.py not sure if I deleted that or if it was just missing but I added “#!/usr/bin/python” and that ran. Then I had to create the logfile in “/var/log/wemo/switchlog”.

Samsung Smartthings Hub

To get Google Home to play with my WeMo switches I ordered one of these hubs. For about fifty dollars it added a bunch of other features like door and window sensors along with multi sensors that can detect water leaks and motion. I sent Google Home back as it wasn’t as well integrated with other devices  as the Echo Dot ,aka Alexa and cost $99.99 on sale compared to Alexa at $39.99 on sale.

This has been easy to setup but requires another app on my phone and a connection to the cloud to work.

I used the labs section and connected my WeMo devices immediately and they worked with no more problems. I went to the Google Home and said hey google, “turn on the Christmas lights”, and everything worked. With Alexa I didn’t need the smart hub to make this work as the plug for this was a WeMo and native to Alexa.

The hub did add other options though like motion, and temperature sensing. I can’t find a decent doorbell option though. I just want the doorbell to ring inside and record when it was used, no fancy video or two way communication needed.

Geofencing

Once I got my location set this seems to work pretty well.

I have eight devices setup with the hub now, Belkin Wemo, Amcrest SmartPlug, Samsung Multisensor, Aeon Multisensor, and a Samsung Door sensor. The Amcrest SmartPlug has been the most interesting so far, it is a re-branded Kankun plug that needed some slight tweaking to make it work but cost about ten dollars less than the Wemo switch that does the same thing.

Amcrest Connect Plug aka Kakun WiFi Smart Plug

More info on this plug here.
Android App to program these plugs WidgetKK for SmartPlug.
Default user root and password p9z34c. SSH is enabled by default. As it 
turns out Amcrest has someone else make this, KONKE Technology Co.
BusyBox v1.19.4 (2014-03-27 17:39:06 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _    _               _    _
 | | _-_| _____ _____  | | _-_| _____ ____
 |  -_-  |     ||     ||  -_-  |     ||    |
 | |-_   |  -  ||  |  || |-_   |  -__||   _|
 |  _ -_ |_____||__|__||  _ -_ |_____||__|  
 |_| -__|  S M A L L   |_| -__| S M A R T
 -----------------------------------------------------
 KONKE Technology Co., Ltd. All rights reserved.
 -----------------------------------------------------
  * www.konke.com            All other products and   
  * QQ:27412237              company names mentioned
  * 400-871-3766             may be the trademarks of
  * fae@konke.com            their respective owners.
 -----------------------------------------------------
root@koven:~# passwd
Changing password for root
New password: 
Retype password: 
Password for root changed by root
root@koven:/www/cgi-bin# cat /etc/openwrt_release
DISTRIB_ID="OpenWrt"
DISTRIB_RELEASE="Bleeding Edge"
DISTRIB_REVISION="r39365"
DISTRIB_CODENAME="barrier_breaker"
DISTRIB_TARGET="ar71xx/generic"
DISTRIB_DESCRIPTION="OpenWrt Barrier Breaker r39365"

I added an index.html in /www

I did find some information on building a web page to control this here.  I get an error as below. However if I grabbed the files from here and then upload them using WinSCP everything works fine. So this turns out to be caused by my cut and paste.

Unable to launch the requested CGI program:
  /www/cgi-bin/relay.cgi: Exec format error

My country was set to CN so I changed it to US.

To display current setting:
/sbin/uci get wireless.radio0.country

To set it (to US, for example):
/sbin/uci set wireless.radio0.country=US
/sbin/uci commit
reboot

I borrowed a script to test network connection and reboot if it drops. I’m using WidgetKK for some of the management its free on the ap store for android.

root@Modem:~# cat reboot.sh
#!/bin/sh
#This is the version 1 for WidgetKK reboot script
#This script will reboot the KK smartplug if it can’t ping the router.
#This script use arguments so you need to pass the router IP or Hostname
#Ex:
# Reboot.sh 192.168.1.1

ping -c5 $1

if [ $? -eq 0 ]; then
echo “ok”
else
reboot
fi
echo “rebootScript”>

chmod +x network_test

I added this to cron.

root@Modem:~# crontab -l
*/30 * * * * /root/reboot.sh 8.8.8.8

So if I can’t ping 8.8.8.8 in thirty minutes it power cycles my cable modem.

I then built a webpage on my Raspberry Pi where I can display multiple switches and turn them all off and on from one location. Since I only have one switch right now its the same switch three times.

nano /var/www/index.html

I bought  a second plug off Amazon this time it was branded as JTD WiFi SmartPlug. Its the same plug on the inside running OpenWRT. I also used WidgetKK to push json.cgi and set the cronjob to power cycle if it loses Internet connection.

jtd_plug

LivingRoom 
Repeat three times once for each switch.

amcrest_buttons

I need to make some labels and the little light at the top goes off when the switch is off on when it is on.I got a WeMo switch today and it is about twice the size of the Amcrest, but the WeMo App is better developed.november-29-2016-at-0656pmTurn the lights on and off from the cli. The advantage to this is there is no outside contact required, I can script the lights to run in a cron job and have the lights on and off on a timer without using the app or having any sort of outside control.

#lights off
echo 0 > /sys/class/leds/tp-link\:blue\:relay/brightness
#lights on 
echo 1 > /sys/class/leds/tp-link\:blue\:relay/brightness

Edit the host name with vi /etc/config/system and change it to whatever you like. I have six of these now so I’m using scp to push the scripts and index files around to new devices.

scp cgi-bin/*.cgi root@192.168.xxx.xxx:/www/cgi-bin