Have you ever used go-c8y-cli ..... 2.0

Part 1 - Creating Assets with Examples MEA’s

A while ago I had create a kind of a “documentation” for the nice command line interface https://goc8ycli.netlify.app/ .
With this new “documentation” the usage of go-c8y-cli and the parameters has changed.
My Intention for this new Version was, having a script creating everything you need with just one enter hit.

DTM preconfiguration

So here is the nice bash script and what it does:

  1. create a asset below the root asset with the allowed type
  2. create a device
  3. assign the device to the asset
  4. create some example MEAs and assign them to the asset
  5. create this for 6 different type of devices and assets

bash script

!/bin/bash

####################################################################################################
##  c8y_ui_4g_mp and asset_c8y_ui_4g_mp
echo "Start creation of asset and device" 
## get the id of the root DTM asset of type dashboard
ASSETID=$(c8y inventory list --type 'dashboard' -o csv --select id)
## create a new asset of type asset_c8y_ui_4g_mp with the name MP-30155 and some example data
GROUP=$(c8y inventory create --name MP-30155 --template "{c8y_IsDeviceGroup:{},c8y_IsAsset:{},type: 'asset_c8y_ui_4g_mp',deviceTypeValue:'asset_c8y_ui_4g_mp',c8y_Point: {gisId:'G4715',reason:'because it is nice',SerialNumber:'30155',from:'2025-02-26T08:03:59.810',to:'',deviceId:'',deviceName:'device_30155',equipmentId:'SAP5035'},c8y_Position: {lng:6.9155360203613565,lat:50.91732038086387},icon: {name:'water-pipe',category:'devicesAndSensors'}}" --force -o csv --select id)
## create a new device of type c8y_ui_4g_mp and assign it to asset_c8y_ui_4g_mp 
c8y devices create --name device_30155 --data "type=c8y_ui_4g_mp,owner=kai.reinhardt@cumulocity.co" --force| c8y devicegroups children assign --childType asset --id "$GROUP" --force| c8y devicegroups children assign --childType asset $ASSETID --child "$GROUP" --force --select id,name,type >> logfile.txt 

## fill variables
GROUPID=$(c8y inventory find --query "name eq 'MP-30155'" -o csv --select id)
## create example MEA for assets of type asset_c8y_ui_4g_mp 
echo "Create example MEA for assets of type asset_c8y_ui_4g_mp" 
c8y measurements create --device $GROUPID --type c8y_Temperature --data "c8y_Temperature.Temperature.value=25.0,c8y_Temperature.Temperature.unit=°C" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Battery --data "c8y_Battery.Battery.value=43,c8y_Battery.Battery.unit=%" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_SignalStrength --data "c8y_SignalStrength.SignalStrength.value=-63,c8y_SignalStrength.SignalStrength.unit=dbm" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Environment --data "c8y_Environment.Druck.value=0,c8y_Environment.Druck.unit=bar,c8y_Environment.Cel.value=25.1,c8y_Environment.Cel.unit=Cel" --force --select id,time,type >> logfile.txt 

## clear variables
unset ASSETID
unset GROUP
unset GROUPID


####################################################################################################
## c8y_tell-catm1_ir_es and asset_c8y_tell-catm1_ir_es
echo "Start creation of asset and device" 
## get the id of the root DTM asset of type dashboard
ASSETID=$(c8y inventory list --type 'dashboard' -o csv --select id)
## create a new asset of type asset_c8y_tell-catm1_ir_es with the name MP-330088 and some example data
GROUP=$(c8y inventory create --name MP-330088 --template "{c8y_IsDeviceGroup:{},c8y_IsAsset:{},type: 'asset_c8y_tell-catm1_ir_es',deviceTypeValue:'asset_c8y_tell-catm1_ir_es',c8y_Point: {gisId:'G4715',reason:'because it is nice',SerialNumber:'330088',from:'2025-02-26T08:03:59.810',to:'',deviceId:'',deviceName:'device_330088',equipmentId:'SAP5035'},c8y_Position: {lng:6.9155360203613565,lat:50.91732038086387},icon: {name:'water-pipe',category:'devicesAndSensors'}}" --force -o csv --select id)
## create a new device of type c8y_tell-catm1_ir_es and assign it to asset_c8y_tell-catm1_ir_es
c8y devices create --name device_330098 --data "type=c8y_tell-catm1_ir_es,owner=kai.reinhardt@cumulocity.co" --force |c8y devicegroups children assign --childType asset --id "$GROUP" --force| c8y devicegroups children assign --childType asset $ASSETID  --child "$GROUP" --force --select id,name,type >> logfile.txt

## fill variables
GROUPID=$(c8y inventory find --query "name eq 'MP-330088'" -o csv --select id)
DEVICEID=$(c8y inventory find --query "name eq 'device_330098'" -o csv --select id)
DEVICENAME=$(c8y  devices list --name device_330098 -o csv --select name)
## create example MEA for assets of type asset_c8y_tell-catm1_ir_es
echo "Create example MEA for assets of type asset_c8y_tell-catm1_ir_es"

c8y measurements create --device $GROUPID --type c8y_Temperature --data "c8y_Temperature.Temperature.value=25.0,c8y_Temperature.Temperature.unit=°C" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Battery --data "c8y_Battery.Battery.value=43,c8y_Battery.Battery.unit=%" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_SignalStrength --data "c8y_SignalStrength.SignalStrength.value=-63,c8y_SignalStrength.SignalStrength.unit=dbm" --force --select id,time,type >> logfile.txt
# Example Events
c8y events create --device $GROUPID --type c8y_door_Acc --text "Tür geschlossen $DEVICENAME" --data "Seriennummer Logger=$DEVICENAME,from=2025-02-26T13:53:39.500Z,to=,deviceId=$DEVICEID" --force --select id,time,type >> logfile.txt 
c8y events create --device $GROUPID --type c8y_door_Acc --text "Tür offen $DEVICENAME" --data "Seriennummer Logger=$DEVICENAME,from=2025-02-26T13:53:39.500Z,to=,deviceId=$DEVICEID" --force --select id,time,type >> logfile.txt 
c8y events create --device $GROUPID --type c8y_door_Reed --text "Tür geschlossen $DEVICENAME" --data "Seriennummer Logger=$DEVICENAME,from=,to=2025-02-26T13:53:39.500Z,deviceId=$DEVICEID" --force --select id,time,type >> logfile.txt 
c8y events create --device $GROUPID --type c8y_door_Reed --text "Tür offen $DEVICENAME" --data "Seriennummer Logger=$DEVICENAME,from=,to=2025-02-26T13:53:39.500Z,deviceId=$DEVICEID" --force --select id,time,type >> logfile.txt 

##clear variables
unset ASSETID
unset GROUP
unset GROUPID
unset DEVICEID
unset DEVICENAME


####################################################################################################
## c8y_vrh_water and asset_c8y_vrh_water
echo "Start creation of asset and device"
## get the id of the root DTM asset of type dashboard

ASSETID=$(c8y inventory list --type 'dashboard' -o csv --select id)
## create a new asset of type asset_c8y_vrh_water with the name MP-403654 and some example data
GROUP=$(c8y inventory create --name MP-403654 --template "{c8y_IsDeviceGroup:{},c8y_IsAsset:{},type: 'asset_c8y_vrh_water',deviceTypeValue:'asset_c8y_vrh_water',c8y_Point: {gisId:'G4715',reason:'because it is nice',SerialNumber:'403654',from:'2025-02-26T08:03:59.810',to:'',deviceId:'',deviceName:'device_403654',equipmentId:'SAP5035'},c8y_Position: {lng:6.9155360203613565,lat:50.91732038086387},icon: {name:'water-pipe',category:'devicesAndSensors'}}" --force -o csv --select id)
## create a new device of type c8y_vrh_water and assign it to asset_c8y_vrh_water
c8y devices create --name device_403654 --data "type=c8y_vrh_water,owner=kai.reinhardt@cumulocity.co" --force|c8y devicegroups children assign --childType asset --id "$GROUP" --force| c8y devicegroups children assign --childType asset $ASSETID  --child "$GROUP" --force --select id,name,type >> logfile.txt

## fill variables
GROUPID=$(c8y inventory find --query "name eq 'MP-403654'" -o csv --select id)
DEVICENAME=$(c8y  devices list --name device_403654 -o csv --select name)
DEVICEID=$(c8y inventory find --query "name eq 'device_403654'" -o csv --select id)

## create example MEA for assets of type asset_c8y_vrh_water
echo "Create example MEA for assets of type asset_c8y_vrh_water"
c8y measurements create --device $GROUPID --type c8y_Temperature --data "c8y_Temperature.Temperature.value=25.0,c8y_Temperature.Temperature.unit=°C" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Battery --data "c8y_Battery.Battery.value=43,c8y_Battery.Battery.unit=%" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_SignalStrength --data "c8y_SignalStrength.SignalStrength.value=-63,c8y_SignalStrength.SignalStrength.unit=dbm" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=3,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=5,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=0.8,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=1.4,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=1.5,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=1.6,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=1.7,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=1.9,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=1.9,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=1.9,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=2.1,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=2.5,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=2.9,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=3.1,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=3.2,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=3.4,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=3.4,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=3.5,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=3.7,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=3.8,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=4.1,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=4.7,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=5.8,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Threshold --data "c8y_Threshold.Threshold.value=5.8,c8y_Threshold.Threshold.unit=,c8y_Threshold.MainWindow.value=1" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Daily --data "c8y_Daily.Count.value=24,c8y_Daily.Min.value=0.8,c8y_Daily.Max.value=5.8,c8y_Daily.Avg.value=3.029" --force --select id,time,type >> logfile.txt 
# Example Events
c8y events create --device $GROUPID --type c8y_loggerStart --text "Start Datenlogger $DEVICENAME" --data "GIS ID=9853,reason=Hier wird es bald was besonderes geben.,Seriennummer Logger=$DEVICENAME,from=2025-02-26T13:53:39.500Z,to=,deviceId=$GROUPID" --force --select id,time,type >> logfile.txt 
c8y events create --device $GROUPID --type c8y_loggerEnd --text "Ende Datenlogger $DEVICENAME" --data "GIS ID=9853,reason=Hier wird es bald was besonderes geben.,Seriennummer Logger=$DEVICENAME,from=,to=2025-02-24T13:53:39.500Z,deviceId=$GROUPID" --force --select id,time,type >> logfile.txt 
# Example Alarms
c8y alarms create --device $GROUPID --type c8y_leakage_detection --time "-0s" --text "Ein Leitungsbruch steht kurz bevor" --severity MAJOR --data "Messpunkt ID=29182289215,GIS ID=9853,Seriennummer Logger=$DEVICENAME" --force --select id,time,type >> logfile.txt 
c8y alarms create --device $GROUPID --type c8y_leakage_detection --time "-0s" --text "Ein Leitungsbruch steht kurz bevor" --severity MAJOR --data "Messpunkt ID=$DEVICEID,GIS ID=9853,Seriennummer Logger=$DEVICENAME" --force --select id,time,type >> logfile.txt 
c8y alarms create --device $GROUPID --type c8y_leakage_detection --time "-0s" --text "Ein Leitungsbruch wird demnöchst passieren" --severity MINOR --data "Messpunkt ID=$DEVICEID,GIS ID=9853,Seriennummer Logger=$DEVICENAME" --force --select id,time,type >> logfile.txt 
c8y alarms create --device $GROUPID --type c8y_leakage_detection --time "-0s" --text "Ein Leitungsbruch könnte bevorstehen" --severity WARNING --data "Messpunkt ID=$DEVICEID,GIS ID=9853,Seriennummer Logger=$DEVICENAME" --force --select id,time,type >> logfile.txt 

# create some average daily values for the asset
c8y measurements create --device $GROUPID --type c8y_Daily --data "c8y_Daily.Count.value=26,c8y_Daily.Min.value=1,c8y_Daily.Max.value=4.8,c8y_Daily.Avg.value=4.029" --time 2025-02-21T13:53:39.500Z --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Daily --data "c8y_Daily.Count.value=27,c8y_Daily.Min.value=0.3,c8y_Daily.Max.value=6.8,c8y_Daily.Avg.value=5.029" --time 2025-02-22T13:53:39.500Z --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Daily --data "c8y_Daily.Count.value=23,c8y_Daily.Min.value=0.4,c8y_Daily.Max.value=3.8,c8y_Daily.Avg.value=7.029" --time 2025-02-23T13:53:39.500Z --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Daily --data "c8y_Daily.Count.value=22,c8y_Daily.Min.value=1.8,c8y_Daily.Max.value=7.8,c8y_Daily.Avg.value=2.029" --time 2025-02-24T13:53:39.500Z --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Daily --data "c8y_Daily.Count.value=21,c8y_Daily.Min.value=0.8,c8y_Daily.Max.value=5.8,c8y_Daily.Avg.value=1.029" --time 2025-02-25T08:53:39.500Z --force --select id,time,type >> logfile.txt 

## clear variables
unset ASSETID
unset GROUP
unset GROUPID
unset DEVICEID
unset DEVICENAME


####################################################################################################
## c8y_ui4_bt_gsm and asset_c8y_ui4_bt_gsm
echo "Start creation of assets and device"
## get the id of the root DTM asset of type dashboard
ASSETID=$(c8y inventory list --type 'dashboard' -o csv --select id)
## create a new asset of type asset_c8y_ui4_bt_gsm with the name MP-8777 and some example data
GROUP=$(c8y inventory create --name MP-8777 --template "{c8y_IsDeviceGroup:{},c8y_IsAsset:{},type: 'asset_c8y_ui4_bt_gsm',deviceTypeValue:'asset_c8y_ui4_bt_gsm',c8y_Point: {gisId:'G4715',reason:'because it is nice',SerialNumber:'8777 ',from:'2025-02-26T08:03:59.810',to:'',deviceId:'',deviceName:'device_8777',equipmentId:'SAP5035'},c8y_Position: {lng:6.9155360203613565,lat:50.91732038086387},icon: {name:'water-pipe',category:'devicesAndSensors'}}" --force -o csv --select id)
##  create a new device of type c8y_ui4_bt_gsm and assign it to asset_c8y_ui4_bt_gsm
c8y devices create --name device_8777 --data "type=c8y_ui4_bt_gsm,owner=kai.reinhardt@cumulocity.co" --force| c8y devicegroups children assign --childType asset --id "$GROUP" --force| c8y devicegroups children assign --childType asset $ASSETID  --child "$GROUP" --force --select id,name,type >> logfile.txt

## fill variables
GROUPID=$(c8y inventory find --query "name eq 'MP-8777'" -o csv --select id)

## create example MEA for assets of type asset_c8y_ui4_bt_gsm
echo "erstelle example MEA for assets type asset_c8y_ui4_bt_gsm"
c8y measurements create --device $GROUPID --type c8y_Temperature --data "c8y_Temperature.Temperature.value=25.0,c8y_Temperature.Temperature.unit=°C" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Battery --data "c8y_Battery.Battery.value=43,c8y_Battery.Battery.unit=%" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_SignalStrength --data "c8y_SignalStrength.SignalStrength.value=-63,c8y_SignalStrength.SignalStrength.unit=dbm" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID --type c8y_Environment --data "c8y_Environment.Druck.value=3.5,c8y_Environment.Druck.unit=bar,c8y_Environment.Temperature.value=1,c8y_Environment.Temperature.unit=°C" --force --select id,time,type >> logfile.txt 

## clear variables
unset ASSETID
unset GROUP
unset GROUPID

####################################################################################################
## c8y_ui4_bt_gsm_1 and asset_c8y_ui4_bt_gsm_1
echo "Start creation of asset and device"
## get the id of the root DTM asset of type dashboard
ASSETID=$(c8y inventory list --type 'dashboard' -o csv --select id)
## create a new asset of type asset_c8y_ui4_bt_gsm_1 with the name MP-8988 and some example data
GROUP=$(c8y inventory create --name MP-8988 --template "{c8y_IsDeviceGroup:{},c8y_IsAsset:{},type: 'asset_c8y_ui4_bt_gsm_1',deviceTypeValue:'asset_c8y_ui4_bt_gsm_1',c8y_Point: {gisId:'G4715',reason:'because it is nice',SerialNumber:'8988',from:'2025-02-26T08:03:59.810',to:'',deviceId:'',deviceName:'device_8988',equipmentId:'SAP5035'},c8y_Position: {lng:6.9155360203613565,lat:50.91732038086387},icon: {name:'water-pipe',category:'devicesAndSensors'}}" --force -o csv --select id)
## create a new device of type c8y_ui4_bt_gsm_1 and assign it to asset_c8y_ui4_bt_gsm_1
c8y devices create --name device_8988 --data "type=c8y_ui4_bt_gsm_1,owner=kai.reinhardt@cumulocity.co" --force |c8y devicegroups children assign --childType asset --id "$GROUP" --force| c8y devicegroups children assign --childType asset $ASSETID  --child "$GROUP" --force --select id,name,type >> logfile.txt

## fill variables
GROUPID=$(c8y inventory find --query "name eq 'MP-8988'" -o csv --select id)

## create example MEA for assets of type asset_c8y_ui4_bt_gsm_1
echo "erstelle example MEA for assets type asset_c8y_ui4_bt_gsm_1"
c8y measurements create --device $GROUPID  --type c8y_Temperature --data "c8y_Temperature.Temperature.value=25.0,c8y_Temperature.Temperature.unit=°C" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID  --type c8y_Battery --data "c8y_Battery.Battery.value=43,c8y_Battery.Battery.unit=%" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID  --type c8y_SignalStrength --data "c8y_SignalStrength.SignalStrength.value=-63,c8y_SignalStrength.SignalStrength.unit=dbm" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID  --type c8y_Environment --data "c8y_Environment.Druck.value=5,c8y_Environment.Druck.unit=bar,c8y_Environment.Max.value=7,c8y_Environment.Max.unit=bar,c8y_Environment.Min.value=2,c8y_Environment.Min.unit=bar" --force --select id,time,type >> logfile.txt 

## clear variables
unset ASSETID
unset GROUP
unset GROUPID

####################################################################################################
## c8y_ui4_bt_gsm_2 and asset_c8y_ui4_bt_gsm_2
echo "Start creation of asset and device"
## get the id of the root DTM asset of type dashboard
ASSETID=$(c8y inventory list --type 'dashboard' -o csv --select id)
## create a new asset of type asset_c8y_ui4_bt_gsm_2 with the name MP-9371 and some example data
GROUP=$(c8y inventory create --name MP-9371 --template "{c8y_IsDeviceGroup:{},c8y_IsAsset:{},type: 'asset_c8y_ui4_bt_gsm_2',deviceTypeValue:'asset_c8y_ui4_bt_gsm_2',c8y_Point: {gisId:'G4715',reason:'because it is nice',SerialNumber:'9371',from:'2025-02-26T08:03:59.810',to:'',deviceId:'',deviceName:'device_9371',equipmentId:'SAP5035'},c8y_Position: {lng:6.9155360203613565,lat:50.91732038086387},icon: {name:'water-pipe',category:'devicesAndSensors'}}" --force -o csv --select id)
## create a new device of type c8y_ui4_bt_gsm_2 and assign it to asset_c8y_ui4_bt_gsm_2
c8y devices create --name device_9371 --data "type=c8y_ui4_bt_gsm_2,owner=kai.reinhardt@cumulocity.co"  --force|c8y devicegroups children assign --childType asset --id "$GROUP" --force| c8y devicegroups children assign --childType asset $ASSETID  --child "$GROUP" --force --select id,name,type >> logfile.txt

## fill variables
GROUPID=$(c8y inventory find --query "name eq 'MP-9371'" -o csv --select id)

## create example MEA for assets of type asset_c8y_ui4_bt_gsm_2
echo "erstelle example MEA for assets type c8y_ui4_bt_gsm_2"
c8y measurements create --device $GROUPID  --type c8y_Temperature --data "c8y_Temperature.Temperature.value=25.0,c8y_Temperature.Temperature.unit=°C" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID  --type c8y_Battery --data "c8y_Battery.Battery.value=43,c8y_Battery.Battery.unit=%" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID  --type c8y_SignalStrength --data "c8y_SignalStrength.SignalStrength.value=-63,c8y_SignalStrength.SignalStrength.unit=dbm" --force --select id,time,type >> logfile.txt 
c8y measurements create --device $GROUPID  --type c8y_Environment --data "c8y_Environment.Trbung.value= 3.37,c8y_Environment.Trbung.unit=FNU,c8y_Environment.Injection.value=13.3,c8y_Environment.Injection.unit=V,c8y_Environment.Temperature.value=1,c8y_Environment.Temperature.unit=°C" --force --select id,time,type >> logfile.txt 

## clear variables
unset ASSETID
unset GROUP
unset GROUPID



Result

As result you will get Assets created below the defined root asset

with assigned devices

and some sample data on the designated assets

Recommendation

As you possibly have seen … the author is using per asset its own deviceTypeValue

{
    "type": "asset_c8y_ui_4g_mp",
    "name": "MP-30155",
    "c8y_IsDeviceGroup": {},
    "c8y_IsAsset": {},
    "deviceTypeValue": "asset_c8y_ui_4g_mp",
    "c8y_Position": {
        "lng": 6.9155360203613565,
        "lat": 50.91732038086387
    },
    "c8y_Point": {
        "gisId": "G4715",
        "reason": "because it is nice",
        "SerialNumber": "30155",
        "from": "2025-02-26T08:03:59.810",
        "to": "",
        "deviceId": "",
        "deviceName": "device_30155",
        "equipmentId": "SAP5035"
    },
    "icon": {
        "name": "water-pipe",
        "category": "devicesAndSensors"
    }
}

Within a future release it is planned to have Dashboards based on different asset types as it is possible at the moment for device types

Part 2 - Create Assets and Devices out of a given csv file

Sometimes you have to create a lot of devices and assets for a tenant to maybe restore or recreate on another tenant what you already have on a tenant.

So here are is a bash script which does this for you:

your Example csv file looks like this, where the first line is the header:

serialNumber,deviceName,assetname,devicetype,assettype,longitude,latitude,gisId,reason,from,to,equipmentId
8777,E8777,MP-000001,c8y_ui4_bt_gsm,asset_c8y_ui4_bt_gsm,6.764953876,51.05641256,G4711,because it is nice,2025-02-04T08:03:59.810Z,,SAP5032
8778,E8778,MP-000002,c8y_ui4_bt_gsm,asset_c8y_ui4_bt_gsm,6.74934399,50.90521331,G4712,because it is nice,2025-02-04T08:03:59.810Z,,SAP5033

The bash script looks like this:

what it does:

  1. creates two files to store temporary id data for assets and devices
  2. creates the assets based on the data given through input.csv file and write te output to asset.csv
  3. creates the devices based on the data given through input.csv file and write to output to devices.csv
  4. assign each device to one asset based on the give order from asset.csv and devices.csv

######################################################################################################
## Create  Assets and devices out of a given csv file and assign each device to the corresponding asset
#######################################################################################################
##
## create dummy files which are needed for the device 2 asset assignment
## define filenames for assets and devices
ASSET="asset.csv"
DEVICES="devices.csv"

# create files
cat << EOL > "$ASSET"
id,assetname
EOL

cat << EOL > "$DEVICES"
id,name
EOL

echo "Files has been created"
echo ""
echo "-----------------"
echo ""


####################################################################################################
echo "Create Cumulocity Assets" 
## find the asset id of the DTM asset of type city which was prior created with the DTM
ASSETID=$(c8y inventory find --type 'city' --query "name eq 'unsortiert'" -o csv --select id)

## create all assets out of the input.csv file (nearly 700 assets)
c8y util repeatcsv input.csv | c8y inventory create --template "{name: input.value.assetname,c8y_IsDeviceGroup:{},c8y_IsAsset:{},type: input.value.assettype,deviceTypeValue:input.value.assettype,c8y_Point: {gisId:input.value.gisId,reason:input.value.reason,SerialNumber: '' +  input.value.serialNumber,from:input.value.from,to:'',deviceId:'',deviceName: input.value.deviceName,equipmentId:input.value.equipmentId},c8y_Position: {lng: input.value.longitude,lat: input.value.latitude},icon: {name:'water-pipe',category:'devicesAndSensors'}}" -o csv --select id --force |c8y devicegroups children assign --id "$ASSETID" --child "$id" --childType asset --select id,name  --force --output csv >> asset.csv 
echo "All Cumulocity Assets are created"
echo "-----------------"
echo ""

echo "Create all Cumulocity devices"
c8y util repeatcsv input.csv | c8y devices create --template "{serialNumber:  '' +  input.value.serialNumber,type: input.value.devicetype,name: input.value.deviceName,owner: 'kai.reinhardt@cumulocity.com',c8y_Position: {lng: input.value.longitude,lat: input.value.latitude}}" | c8y identity create --template "{ externalId: input.value.serialNumber }" --force -o csv --select id,name >> devices.csv
echo "All Cumulocity devices are created"
echo "-----------------"
echo ""

####################################################################################################
echo "Assign all devices to all assets"
## read both files and use a Header
exec 3< <(tail -n +2 "$ASSET")
exec 4< <(tail -n +2 "$DEVICES")

####################################################################################################
## assign each device row to the asset row
while IFS=',' read -r sp1a sp1b <&3 && IFS=',' read -r sp2a sp2b <&4; do
        c8y devicegroups children assign --id $sp1a --child $sp2a --childType asset --force --output csv --select id,name,type >> logfile.txt
 done

echo "All Devices are assigned"
echo "-----------------"
echo ""

## close file descriptor 
exec 3<&-
exec 4<&-




The author had to create roughly 700 assets with the same amount of devices. Each of them assigned to one asset. So it is a nice way to create the assets and devices and to set some additional Metadata.

Result

As result all Assets with the corresponding devices are created below a designated asset