Skip to content

Commit

Permalink
subscribe to state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DEV2DEV-DE committed Nov 23, 2023
1 parent ef3677c commit 76d5567
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,8 @@ class Jablotron extends utils.Adapter {
}
}

// In order to get state updates, you need to subscribe to them. The following line adds a subscription for our variable we have created above.
this.subscribeStates('testVariable');
// You can also add a subscription for multiple states. The following line watches all states starting with "lights."
// this.subscribeStates('lights.*');
// Or, if you really must, you can also watch all states. Don't do this if you don't need to. Otherwise this will cause a lot of unnecessary load on the system:
// this.subscribeStates('*');

/*
setState examples
you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd)
*/
// the variable testVariable is set to true as command (ack=false)
await this.setStateAsync('testVariable', true);

// same thing, but the value is flagged "ack"
// ack should be always set to true if the value is received from or acknowledged from the target system
await this.setStateAsync('testVariable', { val: true, ack: true });

// same thing, but the state is deleted after 30s (getState will return null afterwards)
await this.setStateAsync('testVariable', { val: true, ack: true, expire: 30 });
// subscribe to all state changes
this.subscribeStates('status.alarm');

}

Expand Down

0 comments on commit 76d5567

Please sign in to comment.