Device events() method cannot get all types of events

smartapp
api

(Wan Rong Jih) #1

I write a SmartApp to retrieve device events by using the myDevice.events() and use the evt.descriptionText and evt.description to get the event description.

def event_list = contacts.events()

// subscribe more than one contact sensors
for ( int i=0; i < event_list.size(); i++) 
{     for (int j=0; j < event_list[i].size(); j++)
      {   log.debug "${event_list[i][j].descriptionText}"
          log.debug "${event_list[i][j].description}"
      }
}

For my SmartSense Multi sensors, the description method returns

contactState: 1, accelerationState: 0, temp: 199, battery: 1C, rssi: 64, lqi: 255

while the descriptionText returns only

MySmartSenseMulti1 was 20°C.

By using the evt.name method, all the events from the events() method are only the temperature events. The IDE -> My Device -> MySmartSenseMulti -> List Event, the event name shows not only the temperature, but also include lqi, rssi, battery.

Is it possible to get all event history not only one type of event? Or is there any device method can translate the content of description into description text. (I’ve tried to use myDevice.parse(str), but it encountered method/property not support error during runtime.


(Neil Cherry) #2

Hi Wan_Rong_Jih, I don’t know Groovy very well so take that into account when reading my words (they may be worthless). Is your valid code? The for loop looks like it’s missing something. Like a definition for event_list[i], then then something similar for the second J loop.

for (i = 0; i <3; i++) {
   System.out.println("Hello World")
}

Yours looks like this:

    def event_list = contacts.events()

    // subscribe more than one contact sensors
    for (int i=0; i {
        for (int j=0; j { 
            log.debug "${event_list[i][j].descriptionText}"
            log.debug "${event_list[i][j].description}"
        }
    }

I’d say that Groovy is giving you exactly what you are asking for, log entries of event_list[0][0]. I think you need to define the for loops differently. Sorry i couldn’t be of more help at this time.


(Wan Rong Jih) #3

Thanks @ncherry . Despite the mistake of copy/paste (the code has been corrected, it caused by the ‘<’ need space to show.). Either SmartApp IDE editor or the live logging does not have any error about my code, but the results of descriptionText do not fully translate the values of description.

Could anyone help me to get the full description of event logs?


(Wan Rong Jih) #4

I still cannot get all the event types, nor parse the description to full description text. Anyone could help?


(Wan Rong Jih) #5

After check events on my phone, I know why the descriptionText can only display the temperature event for SmartSense Multi. As the descriptionText returns the description of the event that is to be displayed to the user in the mobile application and the temperature event is the only type of event that SmartSense Multi on mobile devices.


(SGK) #6

Hi Wan_Rong_Jih,
I am trying to get all events from history and trying to display decriptionText in mobile.

i have used your code:
def event_list = contacts.events() //here i am getting list of event in below format

event_list =[[physicalgraph.app.EventWrapper@30fb843b, physicalgraph.app.EventWrapper@50a6569c, physicalgraph.app.EventWrapper@58804521, physicalgraph.app.EventWrapper@4d3aa6eb, physicalgraph.app.EventWrapper@45a4b5e9, physicalgraph.app.EventWrapper@40a2f7b7, physicalgraph.app.EventWrapper@b353088, physicalgraph.app.EventWrapper@51053677, physicalgraph.app.EventWrapper@2d3ae82f, physicalgraph.app.EventWrapper@76617cdb], [physicalgraph.app.EventWrapper@38a0f555, physicalgraph.app.EventWrapper@4f4abc7e, physicalgraph.app.EventWrapper@339d1cdd, physicalgraph.app.EventWrapper@fd20ba4, physicalgraph.app.EventWrapper@26fa4419, physicalgraph.app.EventWrapper@788cd94c, physicalgraph.app.EventWrapper@670e4a68, physicalgraph.app.EventWrapper@5b3726b3, physicalgraph.app.EventWrapper@1cde08e, physicalgraph.app.EventWrapper@73518b8e]]

for ( int i=0; i < event_list.size(); i++)
{ for (int j=0; j < event_list[i].size(); j++)
{ log.debug "${event_list[i][j].descriptionText}"
log.debug “${event_list[i][j].description}”
}
}
error:
java.lang.NullPointerException: Cannot invoke method size() on null object @ line 155

Could you please help on this?


(Wan Rong Jih) #7

My code is a partial of SmartApp…
It seems that the Definition section and Preference section are missed.
SmartThings API documents will show you the SmartApp structure.


(SGK) #8

I just copy pasted a part of my smartapp…

Do you have any idea ? how to parse the event list?

Ex logs: physicalgraph.app.EventWrapper@30fb843b


(Wan Rong Jih) #9

If you read SmartThings Developer Documents thoroughly, you will get the results successfully.

I do not understand the meaning of “how to parse the event list?” Do you mean parsing the returned event string? If it is, it’s hard for SmartApp to perform grammar/syntax parse, you should download the results and parsing them on your local machine.


(SGK) #10

Yes, parsing the returned event string
Thank you for your reply.