To create a dynamic SmartApp page, you can implement the Simple SmartApp Tutorial and update the SmartApp’s definition as following:
/* Defines the SmartApp */
app
//.enableEventLogging() // Log and pretty-print all lifecycle events and responses
.disableCustomDisplayName(true)
.permissions(['r:devices:*', 'x:devices*'])
.appId('Example SmartApp')
.page('mainPage', (context, page, configData) => {
// Random value - This value should be replaced
// by the Web Service's value you want to use.
let randValue = (() => Math.round(Math.random()*10))
// String to display the value.
let paragraph = '\n- Dynamic value: '+ randValue() +'\n'
// SmartApp's paragraph sertting.
page.complete(true)
.name('WebValue Example')
.section('Web Value', section => {
section.paragraphSetting('')
.name('Example SmartApp that capture reading from X Web Service.')
.description(paragraph)
});
})
.updated(async (context, updateData) => {
...
Note: The value will be updated every time you open the SmartApp. Also, the randValue and paragraph variables shoud be handled according to your needs.
To push this values from the SmartApp to a Virtual Device, follow the next steps: