Telenet telemeter

Python and python framework

Moderator: leecollings

Post Reply
nood
Posts: 22
Joined: Sunday 26 July 2015 13:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Telenet telemeter

Post 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
sis3970
Posts: 1
Joined: Tuesday 13 February 2018 14:46
Target OS: -
Domoticz version:
Contact:

Re: Telenet telemeter

Post 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
cever
Posts: 7
Joined: Thursday 07 January 2016 15:02
Target OS: Linux
Domoticz version:
Contact:

Re: Telenet telemeter

Post 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,
nood
Posts: 22
Joined: Sunday 26 July 2015 13:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Telenet telemeter

Post 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.
cever
Posts: 7
Joined: Thursday 07 January 2016 15:02
Target OS: Linux
Domoticz version:
Contact:

Re: Telenet telemeter

Post 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
nood
Posts: 22
Joined: Sunday 26 July 2015 13:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Telenet telemeter

Post 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.
schietschijf
Posts: 1
Joined: Tuesday 19 March 2019 14:22
Target OS: -
Domoticz version:
Contact:

Re: Telenet telemeter

Post 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.
TankySpanky
Posts: 43
Joined: Wednesday 06 February 2019 18:54
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Telenet telemeter

Post 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 ??
Raspberry Pi 3 B+ & Domoticz Beta & Dashticz Beta = Headache :)
But it keeps you van the straat
Filip
Posts: 107
Joined: Thursday 03 November 2016 10:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Telenet telemeter

Post by Filip »

You can find a plugin for the Telenet meter at https://github.com/FilipDem/Domoticz-Telemeter-plugin.
F
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest