cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Alert based in setting historical values

LuisCabello
13-Aquamarine

Alert based in setting historical values

Hello Community :),

 

My question is the next: 

My use case: I have one temperature sensor that send to me data each hour and I receive 4 measures (1 each 15 minutes) in order to have a correct implementation I use the fuction AddNumberValueStreamEntry to record the historical values (the measures in the moment that the device record they) with the correct timestamp.

How I can generate one alert if from the sensor I receive historical values?

 

One of  the methods that I thougth is uncheck the logged type property and to have only persist checked, set the data 2 times:

1. Things[deviceName].property = valueProperty; (JUST TO GENERATE THE ALERT)

2. Use AddNumberValueStreamEntry  (To record the values with a correct timestamp)

but the problem is that the alert is not going to have the correct timestamp.

 

Exist any solution in thingworx to do this? Anybody had this problem and can help me?

 

Thank you in advance :), Greetings.

 

Luis.

ACCEPTED SOLUTION

Accepted Solutions
LuisCabello
13-Aquamarine
(To:PaiChung)

Finally I get it with UpdatePropertyValues, and triggers alerts and events, so this function is perfect :).

Thank you too

var params = {
infoTableName: "UpdatePropertiesInfoTableTMP" /* STRING */,
dataShapeName: "NamedVTQ" /* DATASHAPENAME */
};

 

var updateValues = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

 

var time = new Date();

 

updateValues.AddRow({'time': time, 'name': property_name, 'quality': 'GOOD', 'value': new_value});

 

me.UpdatePropertyValues({values: updateValues});

View solution in original post

8 REPLIES 8
PaiChung
22-Sapphire I
(To:LuisCabello)

Write the values to your property with VTQ and you can just use your Data Change event.

Else evaluate the 'batch' of data for alerts while you enter it into the Stream?

LuisCabello
13-Aquamarine
(To:PaiChung)

Hello @PaiChung ,

 

If I don't understand well. Maybe the I can use the @Constantine example to generate alerts while im processing the data, checking the values and trigger the alerts in this moment. But the problem of this is I can not to use the alert system by default I guess... Write the properties with VTQ solve that? If I have a alert and I write with VTQ is eable to trigger one alert defined in the thing?

 

Thank you in advance,

Luis.

PaiChung
22-Sapphire I
(To:LuisCabello)

So you have I believe 4 records that you receive, what writeVTQ would do is you can provide the proper timestamp into the property update and the associated alert will fire with the proper time stamp associated with it.

LuisCabello
13-Aquamarine
(To:PaiChung)

Hello @PaiChung

 

Where I can find the write or set VTQ property function, because im using the general thing template but I can not find it.

Thank you in advance.

 

Luis.

PaiChung
22-Sapphire I
(To:LuisCabello)

LuisCabello
13-Aquamarine
(To:PaiChung)

Finally I get it with UpdatePropertyValues, and triggers alerts and events, so this function is perfect :).

Thank you too

var params = {
infoTableName: "UpdatePropertiesInfoTableTMP" /* STRING */,
dataShapeName: "NamedVTQ" /* DATASHAPENAME */
};

 

var updateValues = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

 

var time = new Date();

 

updateValues.AddRow({'time': time, 'name': property_name, 'quality': 'GOOD', 'value': new_value});

 

me.UpdatePropertyValues({values: updateValues});

Hello Luis,

 

You can trigger events using the service call syntax. For example, you can emulate alerts:

 

Things[thingName].Alert({  // Here Alert is an Event, not Service
	ackTimestamp: undefined /* DATETIME */,
	alertType: undefined /* STRING */,
	ackBy: undefined /* STRING */,
	ack: undefined /* BOOLEAN */,
	name: undefined /* STRING [Primary Key] */,
	sourceProperty: undefined /* STRING [Primary Key] */,
	description: undefined /* STRING */,
	message: undefined /* STRING */,
	priority: undefined /* INTEGER */
});

 

/ Constantine

logger.info("TriggerEventAlarm testing");
try{
    Things["WT.LUIS.HUB"].Alert({  // Here Alert is an Event, not Service
        ackTimestamp: undefined /* DATETIME */,
        alertType: undefined /* STRING */,
        ackBy: undefined /* STRING */,
        ack: undefined /* BOOLEAN */,
        name: "MovementAlert" /* STRING [Primary Key] */,
        sourceProperty: "N" /* STRING [Primary Key] */,
        description: "No movement detected" /* STRING */,
        message: "No movement detected" /* STRING */,
        priority: 1 /* INTEGER */
    });

}catch(e){
    logger.info("TriggerEventAlarm test error: " + e);
}

 

Hello @Constantine,

 

I try to emulate alerts with this chunk of code and Im not sure what I'm doing wrong (Example of my dummy code above). I always get the next error:

 

JavaException: com.thingworx.common.exceptions.InvalidRequestException: Entity [WT.LUIS.HUB] event [Alert] cannot be invoked externally

 

I want to generate Alerts triggering with a Scheduller/Timer checking a condition in a period of time but this Alert(event) doesnt work to me. It's importar that I generate a Alert Event because I have several Subscriptions with AnyAlert event. 

Do you have anyidea? Also @PaiChung If you could help in this case I would appreciate.

 

Thank you in advance

 

Announcements


Top Tags