Page 1 of 1

Telenet telemeter

Posted: Wednesday 17 January 2018 19:21
by nood
I made my first script ever to check how many GB's I downloaded this month by parsing telenet's webtool.

Code: Select all

import requests

DOMOTICZ_IP = 'http://192.168.*.**:8080'
DEVICE_IDX = 'your dummy counter idx'

POST_LOGIN_URL = "https://login.prd.telenet.be/openid/login"
REQUEST_URL ="https://api.prd.telenet.be/ocapi/public/?p=internetusage,internetusagereminder"
payload = {
    "j_username": "your username",
    "j_password": "your password"
}
COOKIE = #your request cookie

with requests.Session() as session:
    post = session.post(POST_LOGIN_URL, data=payload)
#    print(post.status_code)
    page = session.get(REQUEST_URL,headers=headers)

#    print(page.status_code)
   # print(page.content)
file = page.json()
KBCOUNTER = file['internetusage'][0]['availableperiods'][0]['usages'][0]['totalusage']['includedvolume']

COUNTER = str(KBCOUNTER / 1048576)
#print(COUNTER)

requests.get(DOMOTICZ_IP + "/json.htm?type=command&param=udevice&idx=" + DEVICE_IDX + "&svalue=" + COUNTER)

to get this code working you need to have the requests package installed.
On my rpi it ran only on python2 but with some warning in the terminal, i got an error with python3. On my pc it ran fine with python3.
I run this script with crontab and it works fine
Image

Re: Telenet telemeter

Posted: Tuesday 13 February 2018 14:47
by sis3970
Hi,

I get this error when trying on a Synology:

root@nas:/volume1/@appstore/domoticz/var/scripts/python# python3 telenet.py
File "telenet.py", line 14
COOKIE = #your request cookie

Re: Telenet telemeter

Posted: Tuesday 06 March 2018 9:36
by cever
Hi Nood,

I've tested the script and there are indeed some issues (however I'm no python specialist) :
- COOKIE = #your request cookie -> Do we need to provide something here ?
- userID and password -> is this the new style (e-mail address / Password) or the old style (userID / password)
- There is also a issue on "page = session.get(REQUEST_URL,headers=headers)" -> headers is not declared

Great idea, looking forward to see this working.

Also, do you know where to find a reference about the Telenet API ?

Thanks,

Re: Telenet telemeter

Posted: Thursday 22 March 2018 23:40
by nood
Thanks for trying my first script! :D

This script only works if you copy the entire Cookie of the telemeter page and paste it in the script (by examining the page in your browser). It's ugly and temporary (I realise now) but it works. I am trying to fix this but my knowledge of python and cookie's is the limiting factor.

I used my username, not my email adres, but i guess if they both work on the website they wil both work in this script.

The script, as it is now will work for a few weeks, so you can test the functionality. I think i need to find a way to include the auth in the header, but i don't know yet how to do that.

Re: Telenet telemeter

Posted: Friday 23 March 2018 9:25
by cever
Hi Nood,

I think it is a great start, especially knowing you have limited knowledge on cookies and python.
If I can find some time over the week-end I will give it a try.
Do you know if you can get additional information like data consumption of the mobile phones ?

Thanks,
Chris

Re: Telenet telemeter

Posted: Friday 23 March 2018 15:49
by nood
nood wrote: Thursday 22 March 2018 23:40 I think i need to find a way to include the auth in the header, but i don't know yet how to do that.
I did some investigation on my script, all you need is the OCASESSIONID as the cookie. My only problem is I don't know where to extract it from.
The response from the POST only contains an OAUTHSESSIONID, using this results in 401 response.
cever wrote: Friday 23 March 2018 9:25 Do you know if you can get additional information like data consumption of the mobile phones ?
I don't have a mobile phone subscription from Telenet, but I guess that webpage/API can be parsed in a similar way.

Re: Telenet telemeter

Posted: Tuesday 19 March 2019 14:25
by schietschijf
A small update for those interested:

Mobile usage can be requested via https://api.prd.telenet.be/ocapi/public/?p=mobileusage

you could combine the two usage parameters in one go:https://api.prd.telenet.be/ocapi/public ... ernetusage


For the script, the internetusagereminder parameter is not needed so it can be omitted.

Re: Telenet telemeter

Posted: Saturday 14 August 2021 10:25
by TankySpanky
Hey :)

I have tried to search for the cookie on the page with the "chrome analyse" function but i see tons of info but nothing about a cookie ??

Re: Telenet telemeter

Posted: Sunday 29 August 2021 10:28
by Filip
You can find a plugin for the Telenet meter at https://github.com/FilipDem/Domoticz-Telemeter-plugin.
F