If you are a smart home fan, you have probably heard of Tasmota. It has gained popularity in the DIY home automation community. This open-source firmware controls and automates devices like light switches and sensors. Most of the smart home plug on the market requires you to use their closed-source API. It implies no easy means to build your own Python script to control your smart home devices. With the open-source Tasmota, the former issues can easily be solved. You will know how to auto on/off your smart home devices using Tasmota’s built-in timer. The smart plug model I use is Sonoff S20 flashed with Tasmota firmware.
You can refer to the Tasmota official website for its complete commands.
The most useful commands will be explained below:
WifiConfig: If you have 2 wireless SSIDs, Option 4 (retry other AP without rebooting) will be fine for you. However, I only need my smart plug to connect to 1 WiFi network, so I change it to 5.
Timers: You need to set it to ON in order to use the built-in Timers.
Timezone: You must change your Timezone to make the Timers function correctly. If you leave it alone, your device may start/shut down at the wrong time.
Sleep: If you want to control your smart plug via other devices. You must set this to 0. Otherwise, your smart plug will enter sleep mode after some time, and you cannot modify your smart plug settings again.
SetOption65: “Device recovery using fast power cycle detection.” If your devices are on/off too frequently, it will factory reset your smart plug. The best choice is to turn it off.
PowerOnState: You may think this is similar to the BIOS on Power Loss option. I will set it to 1 to power on after power loss.
IPAddress1: 0.0.0.0 -> Auto DHCP. x.x.x.x -> static
IPAddress2: Gateway IP address
IPAddress3: Subnet mask
You may change your smart plug value by entering the following links to your browser. You may need to find out your smart plug IP after it connects to your router.
Replace your_device_ip with your smart plug IP.
http://your_device_ip/cm?cmnd=WifiConfig%205
http://your_device_ip/cm?cmnd=Timers%20ON
http://your_device_ip/cm?cmnd=Timezone%20+8
http://your_device_ip/cm?cmnd=Status%207
http://your_device_ip/cm?cmnd=Sleep%200
http://your_device_ip/cm?cmnd=SetOption65%201
http://your_device_ip/cm?cmnd=PowerOnState%201
Tasmota provides 16 Timers by default. Let’s say you want it to power on at 7pm and power off at 11 pm every day. You may enter the following links to the browser.
http://your_device_ip/cm?cmnd=Timer13 {"Enable":1,"Time":"19:00","Window":0,"Days":"-M-----","Repeat":1,"Output":1,"Action":0}
http://your_device_ip/cm?cmnd=Timer14 {"Enable":1,"Time":"23:00","Window":0,"Days":"-M-----","Repeat":1,"Output":1,"Action":1}
http://your_device_ip/cm?cmnd=Timer1 {"Enable":1,"Time":"19:00","Window":0,"Days":"--T----","Repeat":1,"Output":1,"Action":0}
http://your_device_ip/cm?cmnd=Timer2 {"Enable":1,"Time":"23:00","Window":0,"Days":"--T----","Repeat":1,"Output":1,"Action":1}
http://your_device_ip/cm?cmnd=Timer3 {"Enable":1,"Time":"19:00","Window":0,"Days":"---W---","Repeat":1,"Output":1,"Action":0}
http://your_device_ip/cm?cmnd=Timer4 {"Enable":1,"Time":"23:00","Window":0,"Days":"---W---","Repeat":1,"Output":1,"Action":1}
http://your_device_ip/cm?cmnd=Timer5 {"Enable":1,"Time":"19:00","Window":0,"Days":"----T--","Repeat":1,"Output":1,"Action":0}
http://your_device_ip/cm?cmnd=Timer6 {"Enable":1,"Time":"23:00","Window":0,"Days":"----T--","Repeat":1,"Output":1,"Action":1}
http://your_device_ip/cm?cmnd=Timer7 {"Enable":1,"Time":"19:00","Window":0,"Days":"-----F-","Repeat":1,"Output":1,"Action":0}
http://your_device_ip/cm?cmnd=Timer8 {"Enable":1,"Time":"23:00","Window":0,"Days":"-----F-","Repeat":1,"Output":1,"Action":1}
http://your_device_ip/cm?cmnd=Timer9 {"Enable":1,"Time":"19:00","Window":0,"Days":"------S","Repeat":1,"Output":1,"Action":0}
http://your_device_ip/cm?cmnd=Timer10 {"Enable":1,"Time":"23:00","Window":0,"Days":"------S","Repeat":1,"Output":1,"Action":1}
http://your_device_ip/cm?cmnd=Timer11 {"Enable":1,"Time":"19:00","Window":0,"Days":"S------","Repeat":1,"Output":1,"Action":0}
http://your_device_ip/cm?cmnd=Timer12 {"Enable":1,"Time":"23:00","Window":0,"Days":"S------","Repeat":1,"Output":1,"Action":1}
Enter the following links to the browser if you want to set up a static IP for it.
Replace your_device_final_ip with your desired static IP address and your_device_gateway_ip with the gateway IP address.
Check out this article if you want to share WiFi on Ubuntu 22.04. Your gateway IP address will be 10.42.0.1 if you use my method.
Check out this article if you want to share WiFi on Windows 10. Your gateway IP address will be 192.168.5.1 if you use my method.
#ubuntu 10.42.0.2
# 10.42.0.1
#ipc (windows) 192.168.5.2
# 192.168.5.1
http://your_device_ip/cm?cmnd=IPAddress1%20your_device_final_ip
http://your_device_ip/cm?cmnd=IPAddress2%20your_device_gateway_ip
http://your_device_ip/cm?cmnd=IPAddress3%20255.255.255.0
You may use the following Python script to set up your Tasmota smart plug. You must first install the requests package on Python (pip install requests).
import requests
ip = '10.42.0.3'
final_ip = '10.42.0.2'
print(requests.get('http://'+ip+'/cm?cmnd=Timer13 {"Enable":1,"Time":"19:00","Window":0,"Days":"-M-----","Repeat":1,"Output":1,"Action":0}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer14 {"Enable":1,"Time":"23:00","Window":0,"Days":"-M-----","Repeat":1,"Output":1,"Action":1}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer1 {"Enable":1,"Time":"19:00","Window":0,"Days":"--T----","Repeat":1,"Output":1,"Action":0}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer2 {"Enable":1,"Time":"23:00","Window":0,"Days":"--T----","Repeat":1,"Output":1,"Action":1}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer3 {"Enable":1,"Time":"19:00","Window":0,"Days":"---W---","Repeat":1,"Output":1,"Action":0}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer4 {"Enable":1,"Time":"23:00","Window":0,"Days":"---W---","Repeat":1,"Output":1,"Action":1}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer5 {"Enable":1,"Time":"19:00","Window":0,"Days":"----T--","Repeat":1,"Output":1,"Action":0}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer6 {"Enable":1,"Time":"23:00","Window":0,"Days":"----T--","Repeat":1,"Output":1,"Action":1}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer7 {"Enable":1,"Time":"19:00","Window":0,"Days":"-----F-","Repeat":1,"Output":1,"Action":0}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer8 {"Enable":1,"Time":"23:00","Window":0,"Days":"-----F-","Repeat":1,"Output":1,"Action":1}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer9 {"Enable":1,"Time":"19:00","Window":0,"Days":"------S","Repeat":1,"Output":1,"Action":0}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer10 {"Enable":1,"Time":"23:00","Window":0,"Days":"------S","Repeat":1,"Output":1,"Action":1}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer11 {"Enable":1,"Time":"19:00","Window":0,"Days":"S------","Repeat":1,"Output":1,"Action":0}'))
print(requests.get('http://'+ip+'/cm?cmnd=Timer12 {"Enable":1,"Time":"23:00","Window":0,"Days":"S------","Repeat":1,"Output":1,"Action":1}'))
print(requests.get('http://'+ip+'/cm?cmnd=WifiConfig%205'))
print(requests.get('http://'+ip+'/cm?cmnd=Timers%20ON'))
print(requests.get('http://'+ip+'/cm?cmnd=Timezone%20+8'))
print(requests.get('http://'+ip+'/cm?cmnd=Status%207'))
print(requests.get('http://'+ip+'/cm?cmnd=Sleep%200'))
print(requests.get('http://'+ip+'/cm?cmnd=SetOption65%201'))
print(requests.get('http://'+ip+'/cm?cmnd=PowerOnState%201'))
print(requests.get('http://'+ip+'/cm?cmnd=IPAddress1%20'+final_ip))
print(requests.get('http://'+ip+'/cm?cmnd=IPAddress2%20'+final_ip[:-1]+'1'))
print(requests.get('http://'+ip+'/cm?cmnd=IPAddress3%20255.255.255.0'))
The following article will teach you how to auto-restart your router daily if the connection is lost. Check it out if you are interested.