Custom integration for Gl-inet routers!

I have a router made by Gl-inet. Their routers run a modified version of OpenWRT. As part of their modification they have a very full featured API, everything from client lists to VPN status. It even accepts POSTS to change many states.

  • VPN control (OVPN, WG, ShadowSocks)
  • LTE Modem control incl SMS
  • Client lists
  • Firewall and port forwarding
  • Public IP
  • BLE controller

I am thinking about developing an integration for these routers. However I’m not sure where to start. One could certainly use it for presence detection as a start.

What class of device would it be? Local polling? Or best to build several separate integrations for the different functions?

There is no python library for the API - should I start there?

Can anyone point me in the direction of an integration that has done something similar so I can know where to start?

Edit: I have now made a first draft that does device tracking only.

2 Likes

Yes, good start :slight_smile: But of course you could use the rest integrations.

Started building an API wrapper: GitHub - HarvsG/gli_py: A python 3 API wrapper for GL-inet routers. [WIP]
Is this the sort of thing that would make an integration easier to build?

Depends on your final goal, if you want to push your integration into core home assistant, pypi based python library is a must. If you are fine to stick with hacs, you can embed the api into integration. I am lazy and usually going with second approach.

Regarding multiple entities vs multiple integrations, you can go with one integration and multiple sensors/entities and users can always disable the ones they don’t need.

1 Like

Has proved very easy to knock together a python package, wI will release it on to pypi soon. Then will start work on a precense detection integration.

Would do a raft of sensors/binary sensors as well. And even some switches. The routers support reboot and VPN on/off over the API.

1 Like

Hi HarvsG
Great stuff - I have a small island in the Bahamas and I use the GliNet 750v2 as a failure internet device. I love the GliNet devices - they are great! Would love to be able to send sms from it, as it is presently my failover of my ptp net connection to the mainland (main island). Would love to test it out as I leave for the island on Thursday and will be there for 4 weeks.

Cheers
Wayne

Sounds awful…

Nice!
Please post when there is something we can test for this. Very interested.

I have released a pypi package that exposes the API: https://pypi.org/manage/project/gli-py/releases/ GitHub is here: GitHub - HarvsG/gli_py: A python 3 API wrapper for GL-inet routers. [WIP]

Feel free to play around with the package pip install gli_py . I’ve not documented the API functions yet but you can see them here: gli_py/glinet.py at 3d554a56fe2e06ace74ad440b7eef02d0fdb859f · HarvsG/gli_py · GitHub

Assuming you have python 3.8 get started with from gli_py import GLinet my_router = GLinet("YOUR_ROUTER_PASSWORD", base_url="http://192.168.8.1/cgi-bin/api/")

@wreuvers I would appreciate any errors you get with the SMS functions, my router doesn’t have a modem at the moment so I haven’t been able to test it.

With regards to building an integration it is a bit more of an unknown for me. I need to get a dev environment set up. I’m trying to work out how much code I can just lift from https://github.com/home-assistant/core/blob/fe5abf1a87bf4c38a6d2ac259dbee5002a51f93b/homeassistant/components/asuswrt

Will be developing the integration here: GitHub - HarvsG/ha-glinet-intergration: staging repo for an GL-inet intergration for homeassistant

1 Like

Hi HarvsG

I do not have a python environment setup, although it is something on my long string of things I need to learn. Once your integration is ready to be used in HA, even if not stable, I’d love to help test it. And if you are ever in the Bahamas (the Abacos), you are welcome to spend a few days on our island - it’s paradise with a bunch of cool tech stuff :smile:

Hi, wow that sounds amazing!! The integration is now working (for me) so is ready to test. You can copy the files to your custom configuration file. You will also have to edit manifest.json to have a version number. Then you should be good to go.

Hi HarvsG
I have only ever installed via HACS. So I gave this try by creating a folder in custom_components called gli_py, added the files to it, and added a new manifest.json which I edited. How do I “access” it? or Use it?
Thanks
Wayne

I got it to appear when adding Integrations, but it shows this message
image

This is the manifest.json I created

{
  "domain": "glinet",
  "name": "gliNet",
  "config_flow": false,
  "documentation": "https://github.com/HarvsG/gli_py",
  "ssdp": [],
  "zeroconf": [],
  "homekit": {},
  "dependencies": [],
  "codeowners": [
    "@HarvsG"
  ],
  "version": "0.4.0"
}

your manifest.json should look like this

{
  "domain": "glinet",
  "name": "GL-inet",
  "config_flow": true,
  "documentation": "https://www.home-assistant.io/integrations/glinet",
  "requirements": ["gli_py==0.0.12"],
  "version": "0.0.2",
  "ssdp": [],
  "zeroconf": [],
  "homekit": {},
  "dependencies": ["network", "http"],
  "dhcp": [{ "hostname": "*gl-inet*" }, { "macaddress": "9483C4*" }],
  "codeowners": ["@HarvsG"],
  "iot_class": "local_polling"
}

And the folder structure should look like this:

And the files are downloaded from:

But beware, you will have to add the "version": "0.0.2", line to the manifest.json from the above files

Hi @HarvsG, I’m also planning on purchasing the Beryl router. How’s your HA integration going?

Fine - ish. There was an update to a dependency for the python package which broke it. So I have have to downgrade uplink to 0.9.5 every time I update HA.

TBH you can probably just use the OpenWRT integration OpenWRT (luci) - Home Assistant

Oh, that’s even better! Thanks for the info.

I have not tested OpenWRT integration with Glinet products. And since a recent version it doesn’t come with LUCI out of the box but there is a one-click install. At the very least if you were to flash Beryl with a pure OpenWRT it would work.

Do report back with your success/failure.

I started developing this not for precedence detection - already sorted with the luci integration (or so I hope) but more to develop VPN and connection controls in future

Ahhh I see. Yeah, I’ll report back on my efforts. Thanks again!