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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

How to get average of multiple Thermometers inside a ValueStream

Themis
7-Bedrock

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!

ACCEPTED SOLUTION

Accepted Solutions
Themis
7-Bedrock
(To:Themis)

Here is how I built my experiment.

  1. I created a ThingTemplate called ThermometerTemplate, which contains the important property, Temperature.
  2. I created a ValueStream called TemperatureData, which contains the averageTemperature property.
  3. I then assigned TemperatureData to the ThermometerTemplate.
  4. Then, I created the number of Thermometer_X Things I needed.
  5. 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.

  6. 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.

 

View solution in original post

3 REPLIES 3
odukiya
16-Pearl
(To:Themis)

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

Themis
7-Bedrock
(To:odukiya)

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.

Themis
7-Bedrock
(To:Themis)

Here is how I built my experiment.

  1. I created a ThingTemplate called ThermometerTemplate, which contains the important property, Temperature.
  2. I created a ValueStream called TemperatureData, which contains the averageTemperature property.
  3. I then assigned TemperatureData to the ThermometerTemplate.
  4. Then, I created the number of Thermometer_X Things I needed.
  5. 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.

  6. 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.

 

Announcements


Top Tags