Running App Code Based on a Switch Toggle?

Hello, I have some application code running decently, but I want to expand it, and could use a nudge in the proper direction.

Basically, if someone changes the state of a switch (already a Z-Wave light switch device in Hubitat), I want that action to run a function in my app code that instantiates timer to trigger another action after a preset time.

I'd like it to trigger when a device in the Hubitat is toggled... Ideally anything that causes that light switch to change state: Physical device switch, a dashboard click, or the device configuration page in device setups...

Thoughts?

You need to:

  1. Provide an input in your app for the user (you) to select any device(s) you needed for the below
  2. Subscribe to the desired event(s) from the devices you want to "listen" for events from using a call to subscribe()
  3. Do whatever you want in the callback method you specified in the previous step, which will run when the subscribed event(s) happen.

If you are not familiar with these steps, this document should get you started because it demonstrates all of them:

1 Like

Helpful--thank you! Working on it now...

'Think it's working now. Thanks, 'just newish to programming ("lite" so to speak) for the platform and didn't get that some of those functions are reserved words / expected and required functions (sub/unsubscribe, and event handling, e.g.).

Thank you, again.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.