Hi,
I wrote a DTH that parses a content to generate multiple events (around 20 distincts ones). It worked fine till I added more events. Then now some events are no longer fired.
For every event directly managed in the parse(), I store in a variable the result of the associated createvent and return it as a list at the end of the parse(). Here is the code for the parse():
def parse(description) {
log.debug "Executing 'parse'"
if (state.requestCounter==0)
return null
// Prevent parse to be executed twice (ST bug?)
state.requestCounter=0
def msg = parseLanMessage(description)
if (msg.status == 200)
{
def xmlParser = new XmlParser()
def html = xmlParser.parseText(msg.body)
log.debug "CO2: ${html.body.table.tr[1].td[0].text()}"
log.debug "PM2.5: ${html.body.table.tr[1].td[1].text()}"
log.debug "PM10: ${html.body.table.tr[1].td[2].text()}"
log.debug "Temperature: ${html.body.table.tr[1].td[3].text()}"
log.debug "Temperature_Cal: ${html.body.table.tr[1].td[4].text()}"
log.debug "humidity: ${html.body.table.tr[1].td[5].text()}"
log.debug "TVOC: ${html.body.table.tr[1].td[6].text()}"
log.debug "IAQ: ${html.body.table.tr[1].td[7].text()}"
log.debug "Battery: ${html.body.table.tr[1].td[8].text()}"
log.debug "UGW_feelslike:${html.body.table.tr[1].td[9].text()}"
log.debug "UGW_DewPoint:${html.body.table.tr[1].td[10].text()}"
log.debug "UGW_Humidity:${html.body.table.tr[1].td[11].text()}"
log.debug "UGW_Temp:${html.body.table.tr[1].td[12].text()}"
def co2_int = html.body.table.tr[1].td[0].text()
def pm2_5_int = html.body.table.tr[1].td[1].text()
def pm10_int = html.body.table.tr[1].td[2].text()
def temp_float = html.body.table.tr[1].td[3].text()
def temp_cal_float = html.body.table.tr[1].td[4].text()
def humid_float = html.body.table.tr[1].td[5].text()
def tvoc_int = html.body.table.tr[1].td[6].text()
def iaq_int = html.body.table.tr[1].td[7].text()
def battery_int = html.body.table.tr[1].td[8].text()
def UGW_feelslike_float = html.body.table.tr[1].td[9].text()
def UGW_DewPoint_float = html.body.table.tr[1].td[10].text()
def UGW_Humidity_float = html.body.table.tr[1].td[11].text()
def UGW_Temp_float = html.body.table.tr[1].td[12].text()
// You can compute your own country IAQ based on local regulations.
// Or use the Air Mentor Pro 2 IAQ
// if no measurment available, put -1 to get a blue colored icon at tiles
[...removed code for clarity...]
def co2_event = createEvent(name: "co2level", value: co2_int.toString())
def pm2_5_event = createEvent(name: "pm2_5level", value: pm2_5_int.toString())
def pm10_event = createEvent(name: "pm10level", value: pm10_int.toString())
def tvoc_event = createEvent(name: "tvoclevel", value: tvoc_int.toString())
def IAQ_event = createEvent(name: "iaqlevel", value: iaq_int.toString())
def IAQ_main_event = createEvent(name: "iaq_main", value: iaq_int.toString())
def temp_cal_event = createEvent(name:"temperaturecallevel", value: temp_cal_float.toString().format(java.util.Locale.US,"%.1f", temp_cal_float.toFloat()))
def hum_event = createEvent(name: "humiditylevel", value: humid_float.toString().format(java.util.Locale.US,"%.1f", humid_float.toFloat()))
// Environmental indicators
// Equilibrium Moisture Content Calculator
// TD: =243.04*(LN(RH/100)+((17.625*T)/(243.04+T)))/(17.625-LN(RH/100)-((17.625*T)/(243.04+T)))
// From http://andrew.rsmas.miami.edu/bmcnoldy/Humidity.html
def dew_point_value = 243.04*(Math.log(humid_float.toFloat()/100.0)+((17.625*temp_cal_float.toFloat())/(243.04+temp_cal_float.toFloat())))/(17.625-Math.log(humid_float.toFloat()/100.0)-((17.625*temp_cal_float.toFloat())/(243.04+temp_cal_float.toFloat())))
def dew_point_event =createEvent(name: "dewpointlevel", value: dew_point_value.toString().format(java.util.Locale.US,"%.1f", dew_point_value.toFloat()))
def emc_W =(349+(1.29*temp_cal_float.toFloat())+(0.0135*temp_cal_float.toFloat()*temp_cal_float.toFloat()))
def emc_k = 0.805+(0.000736*temp_cal_float.toFloat())-(0.00000273*temp_cal_float.toFloat()*temp_cal_float.toFloat())
def emc_k1 = 6.27-(0.00938*temp_cal_float.toFloat())-(0.000303*temp_cal_float.toFloat()*temp_cal_float.toFloat())
def emc_k2 = 1.91+(0.0407*temp_cal_float.toFloat())-(0.000293*temp_cal_float.toFloat()*temp_cal_float.toFloat())
def emc_humid=humid_float.toFloat()/100
def EMC = (1800/emc_W)*(((emc_k*emc_humid)/(1-emc_k*emc_humid))+(((emc_k1*emc_k*emc_humid)+(2*emc_k1*emc_k2*emc_k*emc_k*emc_humid*emc_humid))/(1+(emc_k1*emc_k*emc_humid)+(emc_k1*emc_k2*emc_k*emc_k*emc_humid*emc_humid))))
def state_EMC="Good ("
if (EMC<4.5)
state_EMC="Too Low! ("
else if (EMC > 12.5)
state_EMC="Too High! ("
state_EMC=state_EMC+EMC.toString().format(java.util.Locale.US,"%.1f", EMC.toFloat())+"%)"
def EMC_event = createEvent(name: "EMClevel", value: state_EMC)
// Real feel indoor temperature
def realfeel= temp_cal_float.toFloat()+0.348*emc_humid*6.105*Math.exp((17.27*temp_cal_float.toFloat())/(237.7+temp_cal_float.toFloat()))-4.25
def Indoor_Temp_event = createEvent(name: "RealFeellevel", value: realfeel.toString().format(java.util.Locale.US,"%.1f", realfeel.toFloat()))
// UnderGround Weather references
def UGW_feelslike_event = createEvent(name: "UGWFeelsLikelevel", value: UGW_feelslike_float.toString())
def UGW_DewPoint_event = createEvent(name: "UGWdewpointlevel", value: UGW_DewPoint_float.toString())
def UGW_Humidity_event = createEvent(name: "UGWhumiditylevel", value: UGW_Humidity_float.toString())
def UGW_Temp_event = createEvent(name: "UGWtemperaturecallevel", value: UGW_Temp_float.toString() )
log.debug "Generating alerts if not good"
generate_app_event( "IAQ",iaq_int.toInteger(), 50, 100,150, 200)
generate_app_event( "CO2",co2_int.toInteger(), 800, 1200,2000, 5000)
generate_app_event( "PM2_5",pm2_5_int.toInteger(), 15, 40, 65, 105)
generate_app_event( "PM10",pm10_int.toInteger(), 55, 155, 255, 355)
generate_app_event( "TVOC",tvoc_int.toInteger(), 312, 560, 1000, 3000)
return [co2_event,pm2_5_event,pm10_event, tvoc_event, IAQ_event, IAQ_main_event, dew_point_event, temp_cal_event, hum_event, EMC_event, Indoor_Temp_event, UGW_feelslike_event, UGW_DewPoint_event, UGW_Humidity_event, UGW_Temp_event]
}
}
As you see the return statement will return 12 events
return [co2_event, pm2_5_event, pm10_event, tvoc_event, IAQ_event, IAQ_main_event, temp_event, hum_event, UGW_feelslike_event, UGW_DewPoint_event, UGW_Humidity_event, UGW_Temp_event]
I also have a set of alert events toward a smartapp derived from the NotifyMeWhen smartapp.
These events are generated in a separate private method in order to factorize the alert event creation.
While developing this one, I found that despite the method generate_app_event was called from parse() and was returning the event map created by a createEvent, they were not fired to the app. So I had to change to a sendEvent and now the generate_app_event method doesn’t return any map at all.
private generate_app_event( name_, int value_, int thres_moderate, int thres_unhealthy_sensitive, int thres_unhealthy, int thres_very_unhealty)
{
def bcst_value_=""
def desc_=""
def fire_event = false
log.debug("generate_app_event: ${name_} ${value_} ${thres_moderate} ${thres_unhealthy_sensitive} ${thres_unhealthy} ${thres_very_unhealty}")
if (value_>thres_very_unhealty)
{
bcst_value_="very unhealthy"
desc_="${name_} alert: ${bcst_value_}"
fire_event=true
}
else if (value_>thres_unhealthy)
{
bcst_value_="unhealthy"
desc_="${name_} alert: ${bcst_value_}"
fire_event=true
}
else if (value_>thres_unhealthy_sensitive)
{
bcst_value_="unhealthy sensitive persons"
desc_="${name_} alert: ${bcst_value_}"
fire_event=true
}
else if (value_>thres_moderate)
{
bcst_value_="moderate"
desc_="${name_} alert: ${bcst_value_}"
fire_event=true
}
else
{
bcst_value_="good"
desc_="${name_} alert: ${bcst_value_}"
// change to true if want to be notified of good measures
fire_event=false
}
if (fire_event)
{
log.debug("Generated alert for : ${name_} ${value_}")
sendEvent(name: name_, value: bcst_value_, descriptionText: desc_)
}
else
{
log.debug("No alert generated for ${name_}")
}
}
In the device “Recently” log, I see the events refreshing the tiles but no events sent to the smartApp.
In the live_log, I see things I don’t clearly understand in term of sequence but it seems the code is executed properly.
The bold logs below are just before a sendEvent to the smartApp. And regarding the smartApp log, of course nothing happens. And of course it was working fine yesterday and despite I archive intermediate versions, I am not able to restore to a state that works fine.
**f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug Generated alert for : TVOC 417**
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug generate_app_event: TVOC 417 312 560 1000 3000
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug No alert generated for PM10
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug generate_app_event: PM10 13 55 155 255 355
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug No alert generated for PM2_5
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug generate_app_event: PM2_5 9 15 40 65 105
**f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug Generated alert for : CO2 960**
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug generate_app_event: CO2 960 800 1200 2000 5000
**f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug Generated alert for : IAQ 68**
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug generate_app_event: IAQ 68 50 100 150 200
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug Generating alerts if not good
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug UGW_Temp:15.1
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug UGW_Humidity:84%
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug UGW_DewPoint:12
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug UGW_feelslike:15.1
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug Battery: 0
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug IAQ: 68
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug TVOC: 417
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug humidity: 64.5704309475
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug Temperature_Cal: 22.38
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug Temperature: 28.08
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug PM10: 13
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:31 PM: debug PM2.5: 9
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:30 PM: debug path is: /airmentorpro2.php?Action=get
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:30 PM: debug The device id configured is: c0a80130:0050
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:30 PM: debug The device id before update is: c0a80130:0050
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:30 PM: debug 0050
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:30 PM: debug IP address entered is 192.168.1.48 and the converted hex code is c0a80130
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:30 PM: debug Executing refresh
f0a4fdd3-ea22-4dda-b74f-1cb17db6b1d0 10:48:30 PM: debug Executing 'updated'
Any idea?
Thanks!