-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wen configured in ini file program now updates virtual BWR102 scale sensor to enable graphing. Emailing of weight data is now optional by config in ini.
- Loading branch information
1 parent
85c21fe
commit 4e9e093
Showing
5 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,24 +5,39 @@ | |
|
||
# The persons secion lists all the scale users | ||
# The list maybe extended to 8 persons | ||
# Domoticz index is only used if domoticz IP is set | ||
[Person1] | ||
username: John | ||
useremail: [email protected] | ||
domoticz_idx: 55 | ||
|
||
[Person2] | ||
username: Jill | ||
useremail: [email protected] | ||
domoticz_idx: 56 | ||
|
||
# Scale properties | ||
[Scale] | ||
ble_address: aa:bb:cc:11:22:33 | ||
device_name: 0202B6332211CCBBAA | ||
|
||
# Program behaviour | ||
# Sender email/pwd: gmail account info | ||
# Loglevel: debug | info | critical | error | ||
[Program] | ||
sender_email: [email protected] | ||
sender_pwd: yourpassword | ||
loglevel: debug | ||
logfile: BS440.log | ||
|
||
# Sender email/pwd: gmail account info | ||
# Uncomment [Email] to have emails sent | ||
[Email] | ||
sender_email: [email protected] | ||
sender_pwd: yourpassword | ||
|
||
# Uncomment [Domoticz] to enable updating | ||
# DomoticzIP: IP adres of Domoticz server | ||
# DomoticzUser: Username of Domoticz server | ||
# DomoticzPwd: Password of Domoticz server | ||
#[Domoticz] | ||
#domoticz_url: 192.168.0.10:8080 | ||
#domoticz_user: admin | ||
#domoticz_pwd: admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
''' | ||
BS440domoticz.py | ||
Update weight value to Domoticz home automation system | ||
''' | ||
import urllib2 | ||
import base64 | ||
import logging | ||
|
||
|
||
def UpdateDomoticz(config, weightdata): | ||
log = logging.getLogger(__name__) | ||
# sort to have list starting with most recent weight | ||
wds = sorted(weightdata, key=lambda k: k['timestamp'], reverse=True) | ||
domoticzurl = config.get('Domoticz', 'domoticz_url') | ||
domoticzuser = config.get('Domoticz', 'domoticz_user') | ||
domoticzpwd = config.get('Domoticz', 'domoticz_pwd') | ||
personsection = 'Person' + str(wds[0]['person']) | ||
if config.has_section(personsection): | ||
domoticzidx = config.get(personsection, 'domoticz_idx') | ||
scaleuser = config.get(personsection, 'username') | ||
else: | ||
log.error('Unable to update Domoticz: No details found in ini file ' | ||
'for person %d' % (wds[0]['person'])) | ||
return | ||
try: | ||
log.info('Updating Domoticz for user %s at index %s with weight %s' % ( | ||
scaleuser, domoticzidx, wds[0]['weight'])) | ||
url = 'http://%s/json.htm?type=command¶m=udevice&hid=2&' \ | ||
'did=%s&dunit=4&dtype=93&dsubtype=1&nvalue=0&svalue=%s' % ( | ||
domoticzurl, domoticzidx, wds[0]['weight']) | ||
req = urllib2.Request(url) | ||
base64string = base64.encodestring('%s:%s' % ( | ||
domoticzuser, domoticzpwd)).replace('\n', '') | ||
req.add_header('Authorization', 'Basic %s' % base64string) | ||
resp = urllib2.urlopen(req) | ||
log.info('Domoticz succesfully updated') | ||
except: | ||
log.error('Unable to update Domoticz: Error sending data.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters