Domotron and Apple Shortcuts

Patrik Mojzis
3 min readJul 6, 2020

At the time of writing smart home system Domotron does not support Apple HomeKit integration. I emailed Domotron directly if they plan to integrate this feature, and the answer I received is that they do have it in their roadmap and expected date for it is the year 2021. Well, that is still a lot of time and if you are inpatient like me, you probably want it as soon as possible.

Here I am going to share a small tutorial about how I got Domotron working with Apple Shortcuts.

You might ask why just don’t use their native app or the website on the local network. Well, the reason for that is the loading time — it takes at least 30 seconds until everything loads and you find the right accessory which is very inconvenient.

I run this project on Raspberry Pi and the programming language I use is Python.

To explain the script simple, it loads Domotron website interface on your local network and when you send a command to it, it clicks on the elements. Since the website continually refreshes itself and cookies expire at the session you don’t need to worry about getting logged out the site.

from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport timeimport osfrom pyvirtualdisplay import Display
print("Starting display...")
display = Display(visible=0, size=(800, 600))display.start()print("Display ready")
print("Starting Chrome driver....")for i in range(10): #Sometimes Chrome does not load the first time try: driver = webdriver.Chrome() except: print("Error, trying again.”) time.sleep(4) continue breakprint("Chrome driver ready")
print("Opening domotron...")driver.get("http://192.168.1.10/login.xml")
print("Logging in to Domotron....")
time.sleep(6) #Wait for site to properly loaduser = driver.find_element_by_name("USER")user.send_keys("admin")pas = driver.find_element_by_name("PASS")pas.send_keys("admin")pas.send_keys(Keys.ENTER)print("Logged in to Domotron")
print("Loading blinds...")driver.get("http://192.168.1.10/TIENENI3.XML")print("Blinds loaded")
print("Waiting for commands...")while (True): taskFile = open("task.txt","r+") task = taskFile.read(); taskFile.close()
if("BLINDSUP" in task): print("New task: BLINDSUP") driver.find_element_by_id("INPUT58").click() open('task.txt', 'w').close()
if("BLINDSDOWN” in task):
print("New task: BLINDSDOWN”) driver.find_element_by_id("INPUT115").click() open('task.txt', 'w').close()
time.sleep(0.3)

Find ID of the element you want to click on by reading the source code of the website.

Source code of Domotron's local website.
Domotron local website source code

Also, you can adjust the code to be able to read the current state of the accessory by getting the style attribute and comparing it.

i = driver.find_element_by_id("INPUT44").get_attribute("style")

The Python script reads a text file where are commands being sent. After it completes the command, it deletes the content of the file and waits for the next command. You can create .sh script which writes to the text file and it can be called over SSH in Apple Shortcuts. Here is an example:

input.sh:

echo $1 >task.txt

Then run it by.

$ input.sh BLINDSUP
Apple Shortcuts set up example
Apple Shortcut example

After you done, make the script start at boot. I did not do it the smartest way so I am not going to share it. But here's a small tip: Don’t forget to set up autologin on Raspberry Pi. (sudo raspi-config and then click on boot options)

You can also try to control it by HomeBridge and Script2 plugin which allows running a script as a smart device. Even-though I got it working, for some reason the Script2 plugin wouldn’t synchronise with the actual Apple Homekit app. If you somehow found a way how to get Script2 plugin show up in HomeKit app, please share it in the comments.

--

--