0ربط SmartThings إلى Windows PC وكودي

لدي العديد من النوافذ أجهزة الكمبيوتر في بيتي التي تعمل كودي. أردت أن ربطها SmartThings لمجموعة من الأغراض. هناك العديد من الأشياء التي يمكن القيام به اعتمادا على الوظيفة التي تريدها.


أولا أردت أن تكون قادرة على وضع بلدي أجهزة الكمبيوتر to sleep and wake them up again via a but­ton in SmartTh­ings. لقد حقق هذا, although the pro­cess is quite a long one to set up. وسوف أكون التفاصيل أدناه.

Next I wanted to be able to con­trol Kodi remotely via smartth­ings. This is reas­on­ably straight-for­ward to set up, مرة أخرى أنا بالتفصيل كيف أدناه

أخيرا, I wanted to get the status of a PC in SmartTh­ings. This is so that when a PC goes to sleep I can use a routine in smartth­ings to turn off a power adapter with the home cinema amp­li­fi­ers plugged in. I ori­gin­ally looked at doing this with an energy sav­ing “smart” sock­et, but most of these have been dis­con­tin­ued and the reviews of them are mixed at best. Using SmartTh­ings seemed a more reli­able way to achieve the same thing, with the added bene­fit that I can over­ride the beha­viour at any time from the con­veni­ent of my phone.

PART A: السيطرة على النوم لPC

I fol­lowed the (ليس في العمق) art­icle on the SmartTh­ings for­um writ­ten by ront­al­ley. This took a bit of time to fig­ure out as many of the things required I hadn’t used before, لكنه لم يكن صعبة كما كنت تتوقع. I’ll give a more detailed ver­sion below.

Note — you will need the tar­get PC to have a fixed loc­al IP عنوان (usu­ally in the format 192.168.x.x) and you will also need to know the MAC address of the net­work con­nec­tion it uses. If you don’t know how to find these then you’re not really the kind of user this guide is aimed at — you do need a bit of tech­nic­al know­ledge to do this kind of tinker­ing with SmartTh­ings.

1. تكوين PC مع WOL

  • Hold the win­dows key and R to open the run menu
  • اكتب devmgmt.msc ثم اضغط على Enter
  • Expand ‘net­work adapters’
  • Double click on the net­work adapter yo use to con­nect to your net­work — this will need to be either a wired eth­er­net con­nec­tion or a wire­less card built in (ليس USB بطاقة واي فاي). In my case this was “Real­tek بكيي GB Eth­er­net Con­nec­tion” on 1 PC and “Intel Eth­er­net Con­nec­tion” on anoth­er
  • Click on the “Power Man­age­ment” tab
  • تأكد من أن جميع 3 وتكتك صناديق, then click OK and close device man­ager

2. تثبيت الحدث الشبح على جهاز الكمبيوتر الذي تريد التحكم

  • أسفل حمولة Event­Ghost
  • Install Event­Ghost on the PC you want to con­trol. The default set­tings are all ok to use. At the end of setup run Event­Ghost
  • Cre­ate a new file (the white file but­ton at the top left) and then use “File, Save As” to save it some­where con­veni­ent (prob­ably in My doc­u­ments)
  • Right Click on “Auto­Start” and select “Add Plu­gin”
  • Scroll to the bot­tom of the list and select “Web­Serv­er” and click OK
  • Change the Event Pre­fix to ST. Do not cre­ate a user­name or pass­word
  • I changed the port as I already had some­thing run­ning on Port 80. يمكنك تغيير المنفذ أو اتركه, ولكن إذا كنت تغييره دون ملاحظة ما قمت بتغيير ل.
  • انقر فوق موافق, and then when the Win­dows Fire­wall prompt appears, انقر فوق السماح.
  • Click Can­cel to reject the offer to add the “Con­fig­ur­a­tion Tree” actions
  • Right click on “Auto­Start” again, this time select “Cre­ate Macro”
  • Expand “sys­tem” and then “power man­age­ment”
  • Select “Stand By” (or “Hibern­ate Com­puter” if that is what you prefer your PC to do)
  • انقر فوق موافق, وانقر فوق موافق مرة أخرى على موجه المقبل (without choos­ing force close all pro­grams)
  • الآن إعادة حفظ الملف. نحن تقريبا (ولكن ليس تماما) fin­ished with it
  • انتقل إلى ملف, خيارات
  • وضع علامة في أول 2 خيارات (run on star­tup and min­im­ise to tray) ثم انقر فوق موافق
  • Leave Event­Ghost for now and go on to the next stage.

3. Install the Custom SmartThings Smart App “Send Events to EventGhost” in the SmartThings IDE

4. إنشاء مفتاح الظاهري في SmartThings IDE

  • Still in the SmartTh­ings IDE (from the pre­vi­ous step) click on “My Devices”
  • Click the Green “+ New Device”
  • Give your device a sens­ible name and label — I used the same for each — using the name and loc­a­tion for the PC I wanted to con­trol
  • Change the type to “Vir­tu­al Switch”
  • Give your device a unique net­work name — I used the format “vs-###” where ### was the com­puter name
  • Select your Home loc­a­tion for Loc­a­tion and select your SmartTh­ings Hub (معظمنا فقط 1) that you want to con­trol the switch from for the Hub
  • Make sure ver­sion is set to pub­lished
  • Leave group and zig­bee ID blank
  • Click “Cre­ate”

5. Set the switch to send the “off” signal to event ghost via the Smart App

  • Open the SmartTh­ings app on your mobile device
  • Go to Auto­ma­tion and click on “+ Add a SmartApp”
  • Scroll down to “My Apps” at the bot­tom of the list
  • Select “Send Events to Event­Ghost”
  • دخول IP address of the PC you wanted to con­trol (كان ينبغي أن يكون ثابت IP)
  • تغيير المنفذ من 80 if you changed the port in the Event­Ghost web­serv­er cre­ation earli­er, oth­er­wise leave it at 80
  • Click on the “Switches” option and select the name of the vir­tu­al switch you cre­ated and then press “Done”
  • Click “Save” and you should see “Suc­cess­fully added…” shown in green
  • Switch back to “My Home” in the SmartTh­ings app and toggle the switch that you cre­ated on and off
  • Go back to the PC you wish to con­trol and look at the “log” on the left hand side of “Event­Ghost”. You should see a couple of entries that show your switch toggle activ­ity in SmartTh­ings — mine were lis­ted as “ST.ST.CompName.switch.off []” and “ST.ST.CompName.switch.on []"
  • نريد أن نضع جهاز الكمبيوتر إلى النوم عندما كنا تبديل التحول إلى خارج, so we need the entry “ST.ST.CompName.switch.off []"
  • Drag and drop the “ST.ST.CompName.switch.off []” from the log onto the “Stand By” entry in the main pan­el
  • Save the Event­Ghost file again
  • Now try the but­ton in SmartTh­ings on your mobile device. When you toggle the switch to “off” the PC should go to sleep! You’ve com­pleted the first part of the oper­a­tion. والباقي يكون من السهل من هنا.

6. webCoRE الإعداد لSmartThings الخاص بك

  • لقد يستند هذا على offi­cial guide which is well worth look­ing at if you have any prob­lems
  • You will need a Git­Hub account (حر) حتى إذا لم يكن لديك بالفعل واحدة ثم رئيس لأكثر من Git­Hub and cre­ate one, يستغرق سوى بضع ثوان
  • إذا (مثلي) كنت في الاتحاد الأوروبي أو المملكة المتحدة then yo uneed to activ­ate Git­Hub integ­ra­tion for your SmartTh­ings IDE.
    اذهب إلى هذا الرابط and fol­low the instruc­tions to link your Git­Hub account to SmartTh­ings
  • بمجرد الانتهاء من ذلك (أو لو كان بالفعل بإعداد) log into the SmartTh­ings IDE الولايات المتحدة الأمريكية أو الولايات المتحدة & المملكة المتحدة
  • Click on “My SmartApps”
  • Click on “Set­tings” and then click on “Add new repos­it­ory” in the win­dow that appears
  • Use the fol­low­ing details for the repos­it­ory: Own­er= ady624; Name= web­CoRE; Branch= mas­ter
  • Click “save”
  • Next click the but­ton “Update from Repo” and select “web­CoRE (mas­ter)"
  • Tick ONLY the “web­CoRE” option (not the oth­er 3 خيارات), and tick the “pub­lish” but­ton and click “Execute Update”
  • Click on “Update from Repo” again, and select “web­CoRE (mas­ter)” again
  • Tick the remain­ing 3, tick “pub­lish” again, and click “Execute Update” again
  • Click on the “edit prop­er­ties” but­ton (حق 2 أزرار) next to the web­CoRE smart app in the list
  • Scroll down and click on “OAu­th” to expand the OAu­th options
  • Click on “Enable OAu­th in Smart App” and then click “Update”
  • Now go to the SmartTh­ings app on your mobile device
  • Click on “Mar­ket­Place” at the bot­tom and then select “Smart Apps” at the top
  • Scroll down to “My Apps” and select “web­CoRE” (not the dash­board, stor­age or pis­ton)
  • Fol­low the setup wiz­ard, includ­ing choos­ing a pass­word
  • Give web­CoRE access to the vir­tu­al switch you cre­ated earli­er when you get to the devices to con­trol choices.
    You can also select any oth­er devices you might want to con­trol web web­CoRE
  • Now click on the “Auto­ma­tion” tab in the SmartTh­ings App
  • Scroll down until you find web­CoRE and click on “Dash­board”
  • Enter the pass­word you cre­ated in the web­CoRE setup
  • To make web­CoRE easi­er to use we are going to access it via the browser on your PC…
  • In the auto­ma­tion tab click on web­CoRE again, but this time select “Register a browser”
  • على فتح جهاز الكمبيوتر الخاص بك dashboard.webcore.co and enter the code shown on your SmartTh­ings App
  • Now you have web­CoRE set up we can use it to send a WOL sig­nal

7. Create a webCoRE piston to send a WOL signal when the switch it toggled to “on”

  • In the web­CoRE Dash­board, في الجانب الأيسر, click on “+ New Pis­ton”
  • Select “Cre­ate a blank pis­ton”
  • تعيين الخاص بك اسم الكاتب, and give the pis­ton a sens­ible name (e.g. SAL) and click “Cre­ate”
  • In the code view win­dow click on “+ add a new state­ment”
  • Click on “Add an if” and select “Add a Con­di­tion”
  • Change “what to com­pare” to “phys­ic­al device” and then change “noth­ing selec­ted” to the name of the vir­tu­al switch you cre­ated earli­er. Change the final box to “switch”
  • Leave the next box set to “any inter­ac­tion”
  • Set the box “what kind of com­par­is­on” to “changes to” and set the value to “on”
  • Click the “add” but­ton. سترى تمت إضافة قليلا من التعليمات البرمجية.
  • التالي, click on the sec­tion of code that says “then” and click on “Add an action”
  • Leave the “devices” box set to “loc­a­tion” and click “add a task”
  • in the “Do” list, scroll down and select the “Wake a LAN device” option
  • In the “value” field enter the MAC address of the PC you want to con­trol. استخدام التنسيق س س:س س:س س:س س:س س:س س:س س:س س
  • Click the “Add” but­ton
  • Now click the “Save” but­ton at the top right of the web­CoRE Dash­board to save your code
  • You should now be able to use the switch in your SmartTh­ings app to wake your PC from sleep mode as well as put­ting it to sleep. We finally have the basic func­tion­al­ity we wanted! Try put­ting the PC to sleep and wak­ing it up with the switch. انتظر 20+ seconds between each oper­a­tion to give the PC chance to respond or the but­ton can get out of sync with the real state of the PC. We’ll do some more work next to keep the but­ton always in sync with the status of the PC.

8. تثبيت HostPinger على PC دائما على

  • To keep the switch always in sync with the real con­di­tion of the PC we ‘ping’ the PC from anoth­er device which needs to be always on. I have a serv­er which I have used for this pur­pose, but you could use a Rasp­berry Pi. This guide will focus on using a Win­dows PC, ولكن يمكنك استخدام guide by the STHost­Pinger app author to do this with oth­er devices.
  • Down­load STHostPinger.exe from Git­Hub (EXE V2.zip) and extract it to a con­veni­ent loc­a­tion on the “always on” PC
  • Modi­fy the config.config file that comes with STHostPinger.exe to include the IP address of the PC that your vir­tu­al switch con­trols
  • Change the check inter­val if you wish — I changed mine to 10 ثواني من الافتراضي 30
  • Keep the con­fig file open as we need 3 more set­tings for it once we have set up the smartapp
  • Login to the SmartTh­ings IDE الولايات المتحدة الأمريكية أو الولايات المتحدة & المملكة المتحدة and click on “My SmartApps”
  • Click on “Set­tings” and then click on “Add new repos­it­ory” in the win­dow that appears
  • Use the fol­low­ing details for the repos­it­ory: Own­er= jebbett; Name= STHost­Pinger; Branch= mas­ter
  • Click “save”
  • Next click the but­ton “Update from Repo” and select “STHost­Pinger (mas­ter)"
  • وضع علامة في الخيار الوحيد, and tick the “pub­lish” but­ton and click “Execute Update”
  • Click on the “edit prop­er­ties” but­ton (حق 2 أزرار) next to the STHost­Pinger smart app in the list
  • Scroll down and click on “OAu­th” to expand the OAu­th options
  • Click on “Enable OAu­th in Smart App” and then click “Update”
  • Now click on “My Device Hand­lers”
  • Next click the but­ton “Update from Repo” and select “STHost­Pinger (mas­ter)"
  • وضع علامة في الخيار الوحيد, and tick the “pub­lish” but­ton and click “Execute Update”
  • Go to the SmartTh­ings app on your mobile device
  • Click on Auto­ma­tion at the bot­tom right, and then scroll down and select “Add a SmartApp”
  • Scroll down and choose “My Apps”
  • Choose Host­Pinger, enter the name of the PC you want to mon­it­or, ال IP address of the PC you want to mon­it­or,
    change the “Turn this device on/off with status” and select the vir­tu­al switch you cre­ated earli­er. لتأخير لقد وجدت أنني بحاجة إلى تغيير الافتراضي ل 30 ثانية لتجنب إعادة تمهيد أجهزة الكمبيوتر الذهاب مباشرة إلى النوم. Once set click “Save”
  • Open the Host­Pinger smartapp from the auto­ma­tion menu, scroll down and turn on debug log­ging and click Save to close the smartapp
  • Switch back to the SmartTh­ings IDE and select the “live log­ging” menu
  • Reopen the Host­Pinger smartapp on your mobile device
  • Switch back to the IDE and you should see that sev­er­al events have appeared in the live log. These will include some inform­a­tion called “AppId”, “access­Token” and the IDE entity (الولايات المتحدة أو الاتحاد الأوروبي). You need this inform­a­tion
  • In the config.config file that you were edit­ing earli­er you need to enter the 3 bits of inform­a­tion from the live log. The IDE entity will look some­thing like this: “https://graph-eu01-euwest1.api.smartthings.com”. The oth­er 2 وإدخالات تكون في شكل XXXXXXXXXXXX-XXXXXXXX-XXXXXXXXXXXX
  • نسخ هذه الإدخالات في ملف config.config وحفظه. Now run the STHostPinger.exe and you should see a com­mand prompt style win­dow. It should dis­play the status of the PC you want to mon­it­or as either online or off­line, and hope­fully this will match what the PC is actu­ally doing.
  • Your vir­tu­al switch should now accur­ately show the status of your PC, no mat­ter how it was switched on or off. You can test this by turn­ing the PC and mak­ing sure it shows as “on” on the switch in the SmartTh­ings App. الآن انتقل إلى PC وتحويله بالكامل خارج (إيقاف تشغيله في الجدار). الآن, use the switch in the SmartTh­ings App to turn the PC on. بالطبع PC لا يمكن تشغيل لأنه هو خارج على الجدار. The switch should say “turn­ing on” for 10–15 seconds, and after­wards should go back to say­ing “off”. If this works the pinger ser­vice has turned the but­ton back to off cor­rectly.

الجزء ب: السيطرة على كودي

I tried a couple of dif­fer­ent Smart Apps for SmartTh­ings, but found one was easi­er to set up and did what I needed. مرة أخرى, I fol­lowed a guide on the SmartTh­ings for­um, this time writ­ten by the author of the smartapp called “Kodi for SmartTh­ings Beta".

1. تثبيت التطبيق الذكي ومعالج الجهاز في IDE SmartThings

Use the same prin­ciples as for the first stage, add the cus­tom smart app and device hand­ler and then con­fig­ure.

  • Login to the SmartTh­ings IDE الولايات المتحدة الأمريكية أو الولايات المتحدة & المملكة المتحدة and click on “My SmartApps”
  • Click on “Set­tings” and then click on “Add new repos­it­ory” in the win­dow that appears
  • Use the fol­low­ing details for the repos­it­ory: Own­er= iamcanadian2222; اسم = ST-كودي; Branch= mas­ter
  • Click “save”
  • Next click the but­ton “Update from Repo” and select “ST-Kodi (mas­ter)"
  • وضع علامة في الخيار الوحيد, and tick the “pub­lish” but­ton and click “Execute Update”
  • Now click on “My Device Hand­lers”
  • Next click the but­ton “Update from Repo” and select “ST-Kodi (mas­ter)"
  • وضع علامة في الخيار الوحيد, and tick the “pub­lish” but­ton and click “Execute Update”

2. تمكين HTTP السيطرة على كودي

  • تحميل كودي على جهاز الكمبيوتر الخاص بك
  • Open Sys­tem settngs
  • Nav­ig­ate to the “Ser­vices” option
  • في بنب علامة التبويب, turn on “Allow remote con­trol via UPnp”
  • In the “Web serv­er” tab, turn on “Allow remote con­trol via HTTP"

3. تكوين smartapp عبر التطبيق SmartThings

  • Open the SmartTh­ings App on your mobile device
  • Click on SmartApps at the bot­tom right
  • Scroll down to the bot­tom to “My Apps”
  • Select “Kodi (سابقا XBMC)"
  • The auto­mat­ic setup should find your Kodi box, عندما يكون لديه, حدده وانقر القيام به
  • Click “Done” a second time to fin­ish the setup
  • A device will appear in “My Home”, يجب أن تظهر ما تقوم به آلة كودي. Click on it to get a set of media con­trols

PART C: باستخدام SmartThings الروتينية لإيقاف مآخذ عندما يذهب للنوم PC

وبمجرد ما سبق 2 guides were com­plete it was very easy to cre­ate a SmartTh­ings routine to mon­it­or the status of the PC and turn off sock­ets when it is off, and turn on sock­ets when it is on.

1. إنشاء SmartThings روتين

  • Open the SmartTh­ings app on your mobile device
  • Click on the “auto­ma­tion” tab at the bot­tom and then select the “Routines” tab at the top
  • Click “Add a routine”
  • إعطاء روتينك اسم
  • في الشاشة الثانية, select the “turn off these lights or switches” and set the smart­plug you want to turn off
  • Next click on “Auto­mat­ic­ally per­form…” and then select “Some­thing turns on or off”
  • In the next menu click on “Which?” and select the vir­tu­al switch you cre­ated for your PC. Change “On” to “Off”
    for the “Turns” option, ثم انقر فوق حفظ, ثم انقر فوق حفظ مرة أخرى. You should now see your routine lis­ted
  • Cre­ate a second routine to turn the smart­plug back on when the vir­tu­al switch is turned on

وجدت هذا مفيدا? يرجى إعلامنا عن طريق إسقاط التعليق أدناه. إذا كنت ترغب في الاشتراك يرجى استخدام الرابط الاشتراك في القائمة في اعلى اليمين. يمكنك أيضا مشاركة هذا مع أصدقائك باستخدام الروابط الاجتماعية أدناه. في صحتك.

اترك رد