When switching the actuator, set different values for the sensor

It is convenient to use when setting up scripts without real devices.
Virtual sensors of temperature, humidity, light, etc. can be used as analog sensors.

Script

/** 
* @name Analog Sensor Emulation  
* @desc When switching the actuator, set different values for the sensor  
* @version 4
*/

const actor = Device("ActorD", "Actuatorр", [
  {"name":"porog_0", "note":"Set by on", "type":"number", "val":100},
  {"name":"porog_1", "note":"Set by off", "type":"number", "val":0}
  ]);
const sensor = Device("SensorA", "Sensor"); 

startOnChange(actor);

script ({
    start() {
      this.assign(sensor, "aval", (actor.isOn()) ?  actor.getParam("porog_1") : actor.getParam("porog_0")); 
    } 
});
Close Menu