Example: Send E-Mail alerts when some device's battery is low

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
Locked
User avatar
PoltoS
Posts: 4717
Joined: 26 Jan 2011 19:36

Example: Send E-Mail alerts when some device's battery is low

Post by PoltoS » 27 Mar 2012 17:04

To have E-Mail alerts on low battery use this battery pollin script:# Battery Polling and Alert Version 28.03.2012

gmailUser = "XXXXX"
gmailPwd = "XXXXXX"

subject = "Z-Wave Home Network Battery Alert"
import smtplib, logging
devices = ZWaveAPI.devices
msg = ""
skipNodes = []
for nodeId in filter(lambda (x): x not in skipNodes, devices.keys()):
if devices[nodeId].instances[0].commandClasses.has_key(0x80):
devices[nodeId].instances[0].commandClasses[0x80].Get()
if devices[nodeId].instances[0].commandClasses[0x80].data.last.value < 30 :
msg += "Battery of Node %s (%d) has battery level of %d %%
" % (ZWaveAPI.GetDeviceNameById(nodeId), nodeId, devices[nodeId].instances[0].commandClasses[0x80].data.last.value)
if devices[nodeId].instances[0].commandClasses[0x80].data.last.value == 255:
msg += "Battery of Node %s (%d) is empty!
" % (ZWaveAPI.GetDeviceNameById(nodeId),nodeId)
if len(msg):
try:
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.login(gmailUser, gmailPwd)
smtpserver.sendmail(gmailUser, gmailUser, "From: %s
To: %s
Subject: %s

%s

" % (gmailUser, gmailUser, subject, msg))
except:
logging.zw.info("SMTP failed")
Run this script as action from your schedule as often as you wish.

mcfanda
Posts: 43
Joined: 08 Mar 2013 14:12

logging

Post by mcfanda » 27 Mar 2012 17:04

I'm trying to experiment a bit on python scripts in z-cloud, but i could not write on the log file. I've tried logging.program.info("hello world") and logging.zw.info("hello world") with no success. Any help?
thanks

User avatar
PoltoS
Posts: 4717
Joined: 26 Jan 2011 19:36

Try to change logging mode to

Post by PoltoS » 27 Mar 2012 17:04

Try to change logging mode to DEBUG (in the log window of the UI). Or use logging.program.critical()

Locked