Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hello, I've been trying to experiment with multiple sensors and averaging their data to activate an AC.
Basically, I have a number of "Thermometer" Things with the same Template to which I have assigned a "TemperatureData" ValueStream. Of course, said temperature data is Logged in the Template.
For my application, I want to have a Service get the last entry from each individual thing, then average that data and give me a single reading.
How do I go about it?
My Thingworx version is 9.0
Many thanks in advance!
Solved! Go to Solution.
Here is how I built my experiment.
Thing["Thermometer_X"].Temperature
and stores that average inside the averageTemperature property of the ValueStream.
I wish I was able to trigger the subscriptions internally with a DataChange in the logged data, but in the end, even if this very janky and not at all scalable, it worked just fine for the few Thermometers I needed to simulate.
Hello @Themis
The average of data stream entries can be calculated easily with a custom service utilizing the built in code snippets. For eg Aggregate snippet under service can be used for the same.
Thanks
Om Dukiya
Thanks for your answer!
I had a bit of trouble finding out how to trigger such a service through every recorded DataChange in all asociated Things' properties. However, I found I could just make as many Subscriptions as I need for each Thing I need to monitor. A bit clunky, but at least the average gets logged in the ValueStream. I'll post a more comprehensive answer and mark it as the solution.
Here is how I built my experiment.
Thing["Thermometer_X"].Temperature
and stores that average inside the averageTemperature property of the ValueStream.
I wish I was able to trigger the subscriptions internally with a DataChange in the logged data, but in the end, even if this very janky and not at all scalable, it worked just fine for the few Thermometers I needed to simulate.