📜 ⬆️ ⬇️

Siri + Zway + Homebridge = Start Engine

Good afternoon, dear community! The idea of ​​driving auto start was born quite spontaneously, it all started with how I bought a car a couple of years ago and the question arose of installing an autorun system. Over the past two winters (and our winters are cold, because I live in conditions equivalent to the far north) I woke up in the morning, went out, started the car, went home, drank coffee, and drove to work. This winter, laziness took over, and I purchased the Starline sm32 autorun set with gsm and gps module. Autorun is installed, the application is downloaded, everything works fine! And then I thought: “Why not connect the autorun to my smart home system?”.

The first thing that came to mind was finding the API for the service, but the searches were not successful. This topic was raised at the official forum, but there was no answer from the support, I left a request through the online consultant in the hope that maybe they would answer me, and a week later they answered:

Yes, there is an API. We provide it after customer:

* provides information about yourself and your company and the purpose of using our API
')
* signs a non-disclosure agreement (NDA)

With this, I did not bother and began to look for other ways. Yes, I forgot to say that besides the application there is also a web service, which opened this opportunity for me.

After receiving requests, I received all the necessary information, and wrote a small script in Python. Please do not scold too much for the code itself and its design; this can be said for my first experience in this case:

engine_on.py
import requests import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') logging.debug('This is a log message.') header = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest'} with requests.Session() as session: login = session.post('https://starline-online.ru/user/login', { 'LoginForm[login]': 'username', 'LoginForm[pass]': 'password', 'remember': 1,},headers=header) print (r.status_code,r.reason) r = session.post('https://starline-online.ru/device/_id_device/executeCommand',{ 'value':'1', 'action':'ign', 'password':''},headers=header) logout = session.post('https://starline-online.ru/user/logout', { '':''},) print (login.status_code,login.reason) print (login.cookies) print (logout.status_code,logout.reason) 


This is a script to start the engine, and in order for us to stop it, we change the value of value to 0. But how do we get Siri to run our script? With a long googling and browsing the forums, I found a solution: homebridge-script - this plugin allows you to run sh scripts, how to install homebridge I will not write full instructions on the Internet, put the plugin:

 sudo npm install -g file-exists sudo npm install -g homebridge-script 

After installation, we copy our scripts, I called them engine_on.py and engine_off.py:

 sudo cp engine_on.py engine_off.py /usr/local/lib/node_modules/homebridge-script/ 

There are two on.sh and off.sh files in the same place. I didn’t find anything better to add to them:

 sudo echo "python engine_on.py" > on.sh sudo echo "python engine_off.py" > off.sh 

Now it remains to add the following to our homebridge config:

  "accessories": [ { "accessory": "Script", "name": " ", "on": "sh ./on.sh", "off": "sh ./off.sh", "state": "sh ./state.sh", "fileState": "home/pi/script.flag", "on_value" : "true", "exact_match": true } ] ] 

Restart the service and everything is ready!

PS: I have been tormented for a long time with the selection of phrases, if siri does not like something, she immediately climbs into the Internet for a search. In general, use, I hope it will be useful to someone!

Source: https://habr.com/ru/post/315782/


All Articles