Siri + Zway + Homebridge = Engine Start

Good afternoon, dear community! The idea to control autorun was born quite spontaneously, it all started when I bought a car a couple of years ago and the question arose about installing an autostart system. Over the past two winters (and we have cold winters, because I live in conditions equated to the far north) I woke up in the morning, got out, started the car, went home, drank coffee, and drove to work. This winter, laziness took its toll, and I purchased a Starline sm32 autostart kit with gsm and gps module. Autostart is installed, the application is downloaded, everything works fine! And then I thought: “Why not connect autorun to your smart home system?”

The first thing that occurred to me was to find an API for the service, but the searches were unsuccessful. This topic was raised at the official forum, but there were no answers from support, I sent a request through an online consultant in the hope that they might answer me, and a week later they answered:

Yes there is an API. We provide it after the client:

* provides information about himself and his 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 in addition to the application, there is also a web service that opened this opportunity to me.

After asking queries, I got all the necessary information and wrote a small script in Python. I ask you not to scold much for the code itself and its design, this can be said my first experience in this matter:

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 to stop it, we change the value to 0. But how do we get Siri to run our script? With a long googling and walking around the forums, I found a solution: homebridge-script - this plugin allows you to run sh scripts, how to install homebridge I will not write on the Internet full of instructions, 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 files on.sh and off.sh in the same place. I did not find anything better how to add 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 you're done!

PS: I suffered for a long time with the selection of phrases, if siri does not like something, she immediately crawls on the Internet for a search. In general, use it, I hope this will be useful to someone!


Also popular now: