How to get average of multiple Thermometers inside a ValueStream
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
How to get average of multiple Thermometers inside a ValueStream
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.
- Labels:
-
Best Practices
-
Coding
-
Examples
-
Troubleshooting
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here is how I built my experiment.
- I created a ThingTemplate called ThermometerTemplate, which contains the important property, Temperature.
- I created a ValueStream called TemperatureData, which contains the averageTemperature property.
- I then assigned TemperatureData to the ThermometerTemplate.
- Then, I created the number of Thermometer_X Things I needed.
- Inside TemperatureData, I created a service that pretty much calculates the average of the
Thing["Thermometer_X"].Temperature​
and stores that average inside the averageTemperature property of the ValueStream.
- Then, for each Thing I created a Subscription that is triggered by a DataChange in each Thermometer's Temperature, and calles the service I made in Step 5.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here is how I built my experiment.
- I created a ThingTemplate called ThermometerTemplate, which contains the important property, Temperature.
- I created a ValueStream called TemperatureData, which contains the averageTemperature property.
- I then assigned TemperatureData to the ThermometerTemplate.
- Then, I created the number of Thermometer_X Things I needed.
- Inside TemperatureData, I created a service that pretty much calculates the average of the
Thing["Thermometer_X"].Temperature​
and stores that average inside the averageTemperature property of the ValueStream.
- Then, for each Thing I created a Subscription that is triggered by a DataChange in each Thermometer's Temperature, and calles the service I made in Step 5.
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.