Integrate a Python API

Questions and comments specific to a particular plugin should go here.
Post Reply
Foune
Experienced User
Posts: 89
Joined: Sun Jul 03, 2011 7:08 pm

Integrate a Python API

Post by Foune » Sun Aug 20, 2017 12:04 pm

Hello,

Is there somebody kind enough to give me the guidelines to integrate this API within EG?
As I'm not a good developper, the simpler the better.

Python API for retrieving status devices from Broadlink
https://github.com/mjg59/python-broadlink

This api provide features for controlling devices, but the most important for me is the status polling in order to get events from the broadlink alarm and sensors.

User avatar
kgschlosser
Site Admin
Posts: 3218
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Integrate a Python API

Post by kgschlosser » Sun Aug 20, 2017 2:20 pm

ok not an issue getting this to work.

But....

This library supports:
MP1 - Discontinued
SP1 - plug supported in Argentina, New Zealand, and a few others but not many
SP2 - plug US
A1 - Air detector
RM2 = the newer bridge

it has no support for s2, r1, sc1, sp3, tc2

But to make it work you would download the github and decompress the broadlink folder into
replace ** with 26 if your eg version is 0.4 and 27 if 0.5

eventghost\lib**\site-packages folder

then create a python script and put this code in it. this is only going to scan for devices and print the device types it finds.

Code: Select all

import broadlink

devices = broadlink.discover(5.0)

for device in devices:
    print device.get_type()

If you like the work I have been doing then feel free to Image

Foune
Experienced User
Posts: 89
Joined: Sun Jul 03, 2011 7:08 pm

Re: Integrate a Python API

Post by Foune » Tue Aug 22, 2017 10:25 am

Thank you very much, it's working perfectly.
There is a small flaw, the device I'm managing must be polled at regular intervals (say 2 sec) if I want to detect a change, for instance "door opened" or "motion sensor triggered".
I made a simple system using the timer plugin recursively , it's working but the log gets polluted each time the event is triggered, so every 2 sec.
If I find enough time, maybe I'll use a thread, just like I did for my foscam plugin. But I don't know if I can do this from a simple plugin, without creating a plugin.

User avatar
kgschlosser
Site Admin
Posts: 3218
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Integrate a Python API

Post by kgschlosser » Wed Aug 23, 2017 3:11 pm

sure you can do it from a python script. just make the thread instance set it into an eg.global and make sure that you make the thread a daemon thread. the purpose for this is so the thread will close all nice nice when you shutdown EG

Code: Select all

t = threading.Thread(target=some_function)
t.daemon = True
t.start()
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3218
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Integrate a Python API

Post by kgschlosser » Wed Aug 23, 2017 11:37 pm

scratch that last post.. The process has to end for the daemon thread to end. don't know what i was thinking about with this one.
If you like the work I have been doing then feel free to Image

Post Reply