Task persistance

Internal state

In case you need to write a sensor that needs to remember the previous results, you should use the internalState

This is a code of the sensor that toggles between one and zero:

const previousState = options.internalState 
const newState = previousState === '1' ? '0' : '1'

send(null, {
  observedState: newState,
  internalState: newState
})

This way we get a sensor that toggles between two states in consecutive executions. Here we are creating a digital counter by stacking them together, also using the transition feature to control the order and condition when a particular sensor gets executed:

image

Using data produced by other sensor

In this example we are first running the weather sensor, and then use the result of the sensor execution in another two sensors: conditional sensor and the simple lambda (script) sensor

One is simply looking at a particular condition

${nodes.currentWeather_1.rawData.temperature} > 10 && ${nodes.currentWeather_1.rawData.humidity} <80

While the other one is just taking the object returned by the first sensor and printing it in the debug window (note that we are binding the object using $$ syntax):

()=>{
const data = $${nodes.currentWeather_1.rawData}
console.log("data", data)
return data
}

image