Contact sensor on or off status check

Hello,

I would like to know using node js sdk how I could simply check the current on (open) or off (closed) value on a multicontactsensor? I don’t want to subscribe to the event handler, I just need to do adhoc checks on contact sensor open or close state. What is it nodejs sdk function/code doing this?

Regis

Hi, @rmazur

You can either track the component state/status or the capability state/status as following:

...
.updated(async (context, updateData) => {
  // track by component
  await context.api.devices.getComponentState( ... );
  // track by capability
  await context.api.devices.getCapabilityState( ... );
});

Thank you Erick.

One more question: For this simple requirement, should I use @smartthings/core-sdk instead? Or is @smartthings/smartapp still recommended package?

1 Like

For these requests, is ok if you only use the SmartThings Core SDK and a personal access token to authenticate your requests.

1 Like

Great! Thanks again Erick.

1 Like

Anytime, @rmazur.

Can you please help us by marking this as solved? And if you have any other questions, don’t hesitate in tagging me.