Re: Activate macro when battery status in payload reaches 1?
Posted: Fri Apr 15, 2016 8:22 am
That fixed it PERFECTLY - THANX a lot!!!!! 
Support Forum
http://www.eventghost.net:80/forum/
Code: Select all
if 'humidity' in deviceData:
humidity = int(deviceData['humidity'])
prefix = 'HumidityAlert' if humidity > 50 else False
if prefix: eg.TriggerEvent(
prefix=prefix,
suffix=eg.event.suffix,
payload="current Humidity at "+deviceData['humidity ']+"%"
)
Code: Select all
try:
temperature = float(temperature[:temperature.find(' ')-1])
except:
temperature = False
this will slice the data and try and convert it to a float. if there is anything in the data that does not qualify it to be a float it will trigger an exception and that exception is caught (without you getting that ugly red error on the screen) and sets the variable to False instead
so lets see if you can make that script do something more with that information.
now remember watch the payload data for all the device to see what you may want to have performed if thing are at different levelsCode: Select all
NOTICE = 15
WARN = 10
eg.event.payload += ' '
data = eg.event.payload.split(':')
deviceData = dict([[data[i][data[i].rfind(" "):].strip(), data[i+1][:data[i+1].rfind(" ")].strip()] for i in range(len(data)-1)])
if 'battery' in deviceData:
battery = int(deviceData['battery'])
prefix = 'SensorBatteryWarning' if battery <= WARN else 'SensorBatteryNotice' \
if battery <= NOTICE and battery > WARN else False
if prefix: eg.TriggerEvent(
prefix=prefix,
suffix=eg.event.suffix,
payload="current battery level is at "+deviceData['battery']+"%"
)