Event Detector - get point by XID
-
Hi,
Is it possible to get the value of event detectors (I assume they return a binary 0 or 1) by XID?
I tried ma-get-point for the XID of the event detector and it looks like it just returns an empty object.
Thanks!
-
@rshah said in Event Detector - get point by XID:
Is it possible to get the value of event detectors (I assume they return a binary 0 or 1) by XID?
Event detectors do not have a value. I assume you are trying to ascertain if an event is active or not?
@rshah said in Event Detector - get point by XID:
I tried ma-get-point for the XID of the event detector and it looks like it just returns an empty object.
An XID of an event detector is completely separate to that of a data point. They are not interchangeable.
-
@jared-wiltshire said in Event Detector - get point by XID:
An XID of an event detector is completely separate to that of a data point. They are not interchangeable.
Hi,
yes we are trying to see if a certain event is active or not and based on that change the style of a div on our dashboard.
-
Hi rshah,
You may find this thread interesting: https://forum.infiniteautomation.com/topic/3368/how-to-include-an-event-detector-value-into-a-function
So you could do something similar, and store the resulting aggregate value into a point for use on the dashboard.
If it's only one point though, you can have a set point handler set a binary true / false on the active / inactive actions.
-
@rshah said in Event Detector - get point by XID:
@jared-wiltshire said in Event Detector - get point by XID:
An XID of an event detector is completely separate to that of a data point. They are not interchangeable.
Hi,
yes we are trying to see if a certain event is active or not and based on that change the style of a div on our dashboard.
There is no support for this built into the components just yet. Please see @phildunlap 's answer.
You could write your own component and put it in the user module. To get events for a data point you would use the maEvents service using code like this
maEvents.buildQuery() .eq('dataPointId', 123) .eq('active', true) .query().then(result => { // do something with events });
-
Thank you, @Jared-Wiltshire .
Is it in the development plan to introduce something which would allow us to get the value of an event detector similar to how we get the value of a point?
I see that event-detectors already have their own XID, so a way to get a binary 1 / 0 from that XID with something like
<ma-point-values point-xid="eventDetectorXID"></ma-point-values>
would be great.Although I'm not sure how technically difficult it would be, or if it is even a good solution.
It looks like the component you wrote above actually does just that, except I'm not sure how it deals with multiple events for one point-- haven't tried it yet.
Do we have to use promises? Or can we use async/await?
-
@rshah said in Event Detector - get point by XID:
Is it in the development plan to introduce something which would allow us to get the value of an event detector similar to how we get the value of a point?
Its something I can look at making easier for sure. One thing to clarify is that an event detector does not have a value, it generates events which are active initially and can then become inactive. This is a completely different mechanism to point values.
It sounds like you should setup a meta data source and follow @phildunlap 's advise above for the meantime.
@rshah said in Event Detector - get point by XID:
It looks like the component you wrote above actually does just that, except I'm not sure how it deals with multiple events for one point-- haven't tried it yet.
Do we have to use promises? Or can we use async/await?Its not a component, its a snippet of javascript, and it doesn't deal with anything. Its just returning an array of events for you to use as you please.
Any code you put in the user module will run in the browser so check browser compatibility tables to see if you can use async/await.
-
@jared-wiltshire said in Event Detector - get point by XID:
Any code you put in the user module will run in the browser so check browser compatibility tables to see if you can use async/await.
Thank you!
-
@rshah said in Event Detector - get point by XID:
@jared-wiltshire said in Event Detector - get point by XID:
Any code you put in the user module will run in the browser so check browser compatibility tables to see if you can use async/await.
Thank you!
Oh, actually I just remembered - The promises used in Angular are not native ES6 promises so they probably wont work with async/await. See https://docs.angularjs.org/api/ng/service/$q
You could probably adapt them though.