How is a switch ope...
 

How is a switch operated by a sensor?  

  RSS

jen
 jen
(@jen)
New Member
Joined: 5 months ago
Posts: 2
June 28, 2019 8:55 am  

So I want a to switch on a pump when the water level reaches a certain point. I have the deriver for the water sensor working okay I think. It is a simple 0,1 kind of thing, where if there is water, the output is 1. So that's all good, but when the level goes to 1, how does it trigger the switch?


Quote
systems
(@systems)
Member Admin
Joined: 5 years ago
Posts: 5
June 28, 2019 11:24 am  

You didn't mention that there is a driver for the switch.  You need a driver for the switch itself.  You can probably use our GPIO driver for your switch if you aren't already: https://www.npmjs.com/package/@agilatech/lynxari-gpio-device

There's a couple ways to accomplish this: 1- put some code in your sensor driver, or 2- use our propagate app.

 

First the more difficult but more streamlined way, put the code in your water sensor driver:

// find the pump switch
const query = this.server.where({name: "pump_switch"}); // (or whatever your pump switch is named )
this.server.find(query, (err, results) => {
this.pump_switch = results[0];
});

// now set up an event handler to call the pump_switch directly when needed
this.streams['high_water'].on('data', (message) => {
this.pump_switch.call('change-output', 'high');
}

The other option is to simply use our propagate app: https://www.npmjs.com/package/@agilatech/lynxari-propagate-application

Just set up the config.json for the sensor device (fromDevice) and the pump switch (toDevice):

{
"connections": [
{
"fromDevice": {
"name": "water",
"property": "high_water"
},
"toDevice": {
"name": "pump_switch",
"transitions": [
{
"transition": "change-output",
"arguments": ["high"],
"acceptsMessage": false
}
]
}
}
]
}

Then whenever the water sensor triggers 'high_water', the pump switch will receive the 'change-output high' command.


ReplyQuote
Share:
Menu

Please Login or Register