Toon2domoticz

From Domoticz
Revision as of 18:14, 20 August 2016 by Trixwood (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Purpose

This script will get the current state from your Toon thermostat and save it as a uservariable in Domoticz.
The python script depends on the module rvdm/toon which can be found on Github [1].
To make a few modifications I forked the script, results can also be found on Github [2]. Clone this one for easy installation using setup.py (see chapter 4)

The uservar can change into 5 different Eneco Toon states:
RELAX (comfort) == 0
ACTIVE (thuis) == 1
SLEEP (slapen) == 2
AWAY (weg) == 3
HOLIDAY (vakantie) == 4
You can use the current Toon state inside your Blockly or LUA scripts.

Create a uservariable in Domoticz

variable type: integer
variable value: can be any discrete number. Consider starting with 8. Toon state can only be 0 to 4, so if you install the script correct you should notice certain change.

Make sure you’ve got Python & Git installed on your rpi or synology

I run Domoticz on my Synology NAS and installed the packages using ipkg [3]
After installation of ipkg it's easy, for instance:

ipkg install git

On your rpi I suppose it should be something like

sudo apt-get install git


Install the (python) Toon module

Go to a location where you can download some files, for instance /tmp and enter

git clone https://github.com/mphagenaars/toon.git
cd toon
python setup.py install


Modify toon2domoticz.py

Inside the Toon folder you will find a script named toon2domoticz.py. You can copy this script to a location of your choice. Mine is placed inside the domoticz/var/scripts folder.
You need to edit just two lines (lines 5 & 8) inside the script. Most easy way to edit would be to use WinSCP, but off course you can also use VI or any other editor of your choice

domoticzserver = "your_ip_here:port"
uservariable = "name_of_uservar"


for instance

domoticzserver = "192.168.1.50:8084"
uservariable = "varToonState"



Execute the script

Make sure you can execute the script:

chmod 755 toon2domoticz.py

Or use a tool like WinSCP to set permissions.
Username (-U option) & password (-P option) are the same as you use to log on to Toonopafstand [4]

toon2domoticz.py -U your_username_here -P your_password_here

If you installed everything correct the uservariable should now be changed to the current Toon state.

The uservar can change into 5 different Eneco Toon states:
RELAX (comfort) == 0
ACTIVE (thuis) == 1
SLEEP (slapen) == 2
AWAY (weg) == 3
HOLIDAY (vakantie) == 4

I’ve scheduled the script to run every 5 minutes on my Synology NAS. You can do the same on your rpi using cron.

You can now use the current Toon state inside your Blockly or LUA scripts


toon2domoticz.py script

Remember, in order to work this script will need you to install Toon module to Python. Please refer to chapter 4 for instructions

#!/usr/bin/python
# -*- coding: utf-8 -*-

# domoticz server & port information
domoticzserver = "192.168.1.50:8084"

# domoticz uservariable name to set the Toon state
uservariable = "varToonState"


# Do not change anything beyond this line
#___________________________________________________________________________________________________

import pprint
from Toon import Toon
import argparse
import urllib
import urllib2
import urlparse

parser = argparse.ArgumentParser(description='Communicate with the Eneco Toon thermostat')
parser.add_argument('-U', '--username', help='the Toon username', required=True, dest='username')
parser.add_argument('-P', '--password', help='the Toon password', required=True, dest='password')

args = parser.parse_args()

username = args.username
password = args.password

toon = Toon(username, password)
toon.login()

state = toon.get_program_state()
url = 'http://'+domoticzserver+'/json.htm?type=command&param=updateuservariable&vname='+uservariable+'&vtype=0'
params = {'vvalue':state}
url_parts = list(urlparse.urlparse(url))
query = dict(urlparse.parse_qsl(url_parts[4]))
query.update(params)
url_parts[4] = urllib.urlencode(query)
urllib2.urlopen(urlparse.urlunparse(url_parts))

toon.logout()