Waardering:
  • 0 stemmen - gemiddelde waardering is 0
  • 1
  • 2
  • 3
  • 4
  • 5
Domoticz voorbeeld
#1
Beste BeeClear bezitter,

Hieronder een voorbeeld in python van een Domoticz gebruiker (Erik). Het mooiste is het als de code in 
een versie managementsysteem geplaatst wordt zoals "git".  Dan kunnen we naar de source verwijzen met een link. 


////////////////////////////////////////////////begin script///////////////////////////////////////////////////////////////////////////


#! /usr/bin/python
import urllib2
import urllib
import base64
import subprocess

host = '192.168.0.20'
username = 'beeclear'
password = 'wachtwoord'

class beeclear:
       def __init__( self, hostname, user, passwd ):
               self.hostname = hostname
               self.user = user
               self.passwd = passwd
               self.cookie = None;
       def connect( self ):
               post_args = urllib.urlencode( { 'username':  base64.b64encode(self.user), 'password': base64.b64encode(self.passwd) } )
               url = 'http://' + self.hostname + '/bc_login?' + post_args;
               req1 = urllib2.Request(url)
               response = urllib2.urlopen(req1)
               self.cookie = response.headers.get('Set-Cookie')
       def send( self, command ):
               url = 'http://' + self.hostname + '/' + command
               req = urllib2.Request(url)
               req.add_header('cookie', self.cookie)
               f = urllib2.urlopen(req)
               data = f.read()
               f.close
               return data


a = beeclear( host, username, password )
a.connect()


Str_beeclear = a.send ( 'bc_current' )
Str_beeclear = str(Str_beeclear)

ul= Str_beeclear[Str_beeclear.find("ul")+4:Str_beeclear.find("uh")-2]
uh= Str_beeclear[Str_beeclear.find("uh")+4:Str_beeclear.find("gl")-2]
gl= Str_beeclear[Str_beeclear.find("gl")+4:Str_beeclear.find("gh")-2]
gh= Str_beeclear[Str_beeclear.find("gh")+4:Str_beeclear.find('"u"')-1]
gas= Str_beeclear[Str_beeclear.find("gas")+5:Str_beeclear.find("gd")-2]
Eu= Str_beeclear[Str_beeclear.find('"u"')+4:Str_beeclear.find('"g"')-1]
Eg= Str_beeclear[Str_beeclear.find('"g"')+4:Str_beeclear.find('"gas"')-1]

Netto= (int(gl)+int(gh)-int(ul)-int(uh))
str(Netto)


#update Netto in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=45&nvalue=0&svalue="'+str(Netto))
output = subprocess.check_output(['bash','-c', command])


#update Gas in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=53&nvalue=0&svalue="'+str(gas))
output = subprocess.check_output(['bash','-c', command])

#update E-export in high tarrif in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=60&nvalue=0&svalue="'+str(gh))
output = subprocess.check_output(['bash','-c', command])

#update E-import in high tarrif in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=61&nvalue=0&svalue="'+str(uh))
output = subprocess.check_output(['bash','-c', command])

#update E-import in low tarrif in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=59&nvalue=0&svalue="'+str(ul))
output = subprocess.check_output(['bash','-c', command])

#update E-export in low tarrif in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=58&nvalue=0&svalue="'+str(gl))
output = subprocess.check_output(['bash','-c', command])

#update E-netto in low tarrif in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=62&nvalue=0&svalue="'+str(Netto))
output = subprocess.check_output(['bash','-c', command])

#update E-netto in low tarrif in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=65&nvalue=0&svalue="'+str(Eu))
output = subprocess.check_output(['bash','-c', command])

#update E-netto in low tarrif in Domoticz
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=66&nvalue=0&svalue="'+str(Eg))
output = subprocess.check_output(['bash','-c', command])

command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&param=udevice&idx=69&nvalue=0&svalue="'+str(Netto/1000))
output = subprocess.check_output(['bash','-c', command])


///////////////////////////////////////////////////////einde script////////////////////////////////////////////////////////////////////
Antwoord


Berichten in dit topic
Domoticz voorbeeld - door forumadmin - 05-06-2018, 19:44 PM
RE: Domoticz voorbeeld - door Desjeng - 13-03-2019, 13:57 PM

Ga naar locatie: