How-To Guides

Use Digital Twins to Contextualize Data

22min
refer to the following how to guide for leveraging digital twins for energy monitoring user scenario in this user scenario, the devicehub device will simulate the energy monitoring process across different plant sites the data generated by the tags reflects real time energy production, which allows for active analysis of energy efficiency, cost, and consumption patterns digital twins will model the asset as an energy monitoring machine located at several plant sites the instances for the model will be the specific energy monitoring machines at each site the power generated in the last hour will be used to calculate values for cost, energy used, and energy rate the timestamp value will be used to generate values for the attributes of season, start hour, and energy rate description we need to add two tags for this tag 1, named "l3 machine2", will generate random values simulating the variable power of an energy monitoring machine tag 2 in devicehub collects and stores data from energy monitoring devices it helps in analyzing energy rates and seasons by simulating timestamp values step 1 add a device follow the steps to connect a device docid\ ish7bqhzxswtdx8vbnszb and configure the following parameters device type simulator driver name generator enable alias topics select the checkbox step 2 add tags after connecting the device, add the following tag see add tags docid\ xgwokqbtpevii7or82ll0 to learn more tag 1 l3 machine2 name select s random value generator value type select float64 polling interval enter 1 tag name enter l3 machine2 min value enter 1 max value enter 25 values for power generated will be sent through the topic devicehub alias p2 electrical panel l3 machine2 tag 2 the data collected from energy monitoring devices is stored in devicehub by enabling the connect a device docid\ ish7bqhzxswtdx8vbnszb option on the simulator devices the simulator device will act as a device measuring power values the tag will simulate these timestamp values from one of the energy monitoring machines, and then the output will be written to the topic flowtodt emd l3 machine2 to process this data, you will need to connect to a third party database and create a flow using flows manager this flow will collect the values and determine the season and energy rate based on the date and timestamp // determine season and energy rate based on date and timestamp var arr = msg payload; var arrout = \[]; var time = flow\ get("tstart"); var tstart = new date(flow\ get("tstart")); var month = tstart getmonth(); var hour = tstart gethours(); flow\ set("month", month); flow\ set("hour", hour) // determine season if (month > 5 && 10 > month){ var season = 'summer'; } else { var season = 'winter'; } // determine energy rate if (season == 'summer'){ if (hour >= 7 && 11 > hour || hour >= 17 && 19 > hour){ var energyrate = 10 2; var energyratedescription = "mid peak"; } else if (hour >= 11 && 17 > hour){ var energyrate = 15 1; var energyratedescription = "off peak"; } else { var energyrate = 7 4; var energyratedescription = "on peak"; } } else { if (hour >= 7 && 11 > hour || hour >= 17 && 19 > hour){ var energyrate = 15 1; var energyratedescription = "on peak"; } else if (hour >= 11 && 17 > hour){ var energyrate = 10 2; var energyratedescription = "mid peak"; } else { var energyrate = 7 4; var energyratedescription = "off peak"; } } for (let device = 0; device < arr length; device++){ obj = {} // fields for sql insert obj time = time; obj plant = arr\[device] plant; obj line = arr\[device] line tag; obj asset = arr\[device] name tag; obj shift = global get("shift"); obj energyused = parsefloat((arr\[device] integral) tofixed(2)); obj energyrate = energyrate; obj energyratedescription = energyratedescription; obj season = season; obj cost = parsefloat((obj energyused energyrate) tofixed(2)); arrout push(obj) } msg payload = arrout; return msg; sample output payload from instance this user scenario will be based on the following sample output payload from one instance { "time" "2023 04 13t17 00 00 000z", "plant" "toronto", "line" "line 1", "asset" "machine 2", "shift" 2, "energyused" 2 51, "energyrate" 15 1, "energyratedescription" "on peak", "season" "winter", "cost" 37 9, "timestamp" 1681408544466, "starthour" "2023 04 13t17 00 00 000z" } step 3 create digital twins model you will first need to create the model that will store the instances of energy monitoring machines to create the model navigate to digital twins the models pane appears from the models pane, click the create a model tile the create a model dialog box appears click the type drop down list and select asset enter the name of the model in the name field (for example, energy monitoring model ) (optional) enter a short description of the model in the description field click add the new model appears in the models pane after creating the model, you can create and import models docid 09kftudhjli4ujyvwdcke with the following parameters model static attributes the static attributes will need to be customized for each instance asset line model manufacturer location plant transformations the transformations are based on the sample payload above energyratedescription { "value" "$energyratedescription", "timestamp" "$timestamp" } energyrate { "value" "$energyrate", "timestamp" "$timestamp" } energyused { "value" "$energyused", "timestamp" "$timestamp" } shift { "value" "$shift", "timestamp" "$timestamp" } starthour { "value" "$starthour", "timestamp" "$timestamp" } season { "value" "$season", "timestamp" "$timestamp" } cost { "value" "$cost", "timestamp" "$timestamp" } the list of transformations would display as the following tip to access nested metadata keys, you should include a period after the initial dollar sign for example $ metadata will extract the entire metadata object $ metadata cost will extract the cost key in the metadata object model dynamic attributes the dynamic attributes will use the appropriate schemaid (transformation) to generate values name unit (optional) datatype (optional) schemaid (optional) cost usd cost energyratedescription energyratedescription energyrate usd/kwh energyrate energyused energyused shift shift starthour starthour season season power kw hierarchy the output for the model will be based on the hierarchy, which would categorize the dynamic and static attributes into telemetry or properties it would look like the following step 4 create instances once the model is configured, you will need to add an instance docid\ dfotol4qdifzijkm cdxm for each energy monitoring device at each site one of the instances is described below based on the topics for the data in the user scenario description instance static attributes you will customize the model static attributes to the specific instance attribute name attribute value asset machine 2 line line 1 model model 112233 manufacturer siemens location canada plant toronto instance dynamic attributes you will configure the appropriate topics in the user scenario description to the dynamic attributes configured in the model name unit datatype topic schemaid (optional) power kw devicehub alias p2 electrical panel l3 machine2 cost usd flowtodt emd l3 machine2 cost energyratedescription flowtodt emd l3 machine2 energyratedescription energyrate usd/kwh flowtodt emd l3 machine2 energyrate energyused flowtodt emd l3 machine2 energyused shift flowtodt emd l3 machine2 shift starthour flowtodt emd l3 machine2 starthour season flowtodt emd l3 machine2 season