Hello @DJX,
Glad to hear that, excellent job!
I would recommend to start looking forward and create a SmartApp using the SDKs available on SmartThings Github. The sample below is based on the smartapp-sdk-nodejs and the configuration helps you to:
- Select a motion sensor (you can also change it to be able to select more than one)
- Create the subscriptions for the “active” and “inactive” states of the motion sensor
- Make a request to an external REST API, on the “active” subscription handler you can find an example (in this case, using Axios)
const express = require('express');
const bodyParser = require('body-parser');
const SmartApp = require('@smartthings/smartapp');
const axios = require('axios');
const server = express();
require('dotenv').config();
server.use(bodyParser.json());
const app = new SmartApp()
/* Handles lifecycle events from SmartThings */
server.post('/', async (req, res) => {
app.handleHttpCallback(req, res);
});
/* Defines the SmartApp */
app.enableEventLogging() // Log and pretty-print all lifecycle events and responses
.configureI18n() // Use files from locales directory for configuration page localization
.page('mainPage', (context, page, configData) => {
page.section('sensors', section => {
section.deviceSetting('sensor').capabilities(['motionSensor']).required(true);
});
})
.updated(async (context, updateData) => {
await context.api.subscriptions.unsubscribeAll();
return Promise.all([
context.api.subscriptions.subscribeToDevices(context.config.sensor, 'motionSensor', 'motion.active', 'motionActiveEventHandler'),
context.api.subscriptions.subscribeToDevices(context.config.sensor, 'motionSensor', 'motion.inactive', 'motionInactiveEventHandler')
])
})
.subscribedEventHandler('motionActiveEventHandler', async (context, deviceEvent) => {
let httpget=await axios.get('http://...');
})
.subscribedEventHandler('motionInactiveEventHandler', (context, deviceEvent) => {
//Add some actions
});
/* Starts the server */
let port = process.env.PORT;
server.listen(port);
For more information, visit: