In this tutorial we will show how to send SMS message when sensors detect water leak.
We already show how to build water leak sensor. We can see sensor status in EasyIoT WEB user interface, but we usually want to be notified as soon as possible when water leak occurs. We assume, that we have installed SMS interface. We can also easily adopt automation program to use EmailHelper.
It's recommended to read tutorials about automation before you start:
EasyIoT server automation - part I
EasyIoT server automation - part II
EasyIoT server automation - part III
First add automation program and name it water leak notification.
In next step add SMS notification in Setup function. We will use EventHelper and SmsHelper. In event helper we will detect water leak alarm and with SmsHelper we will send SMS alarm notification.Program is like this. Change module addresses to suit your sensor configuration.
/*
This code is running one time when program is enabled
*/
public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{
// bathroom alarm
if (m.Domain == Domains.MYSENSORS && m.Address == "N8S0" && p.Property == "Sensor.Leak" && p.Value == "1")
SmsHelper.SendSms("+38xxxxxxxxx","Water leak in bathroom");
// living room
if (m.Domain == Domains.MYSENSORS && m.Address == "N3S0" && p.Property == "Sensor.Leak" && p.Value == "1")
SmsHelper.SendSms("+38xxxxxxxxx","Water leak in living room");
return true;
});
}
/*
This code is running periodicaly when program is enabled.
Cron job detirmine running period.
*/
public void Run()
{
}
We can also add switch to disable SMS notification. First add Virtual module DO switch and name it SMS notification enable.
Remember module address and modify existing program to check switch status.
/* This code is running one time when program is enabled */ public void Setup() { EventHelper.ModuleChangedHandler((o, m, p) => {
// read switch status
ModuleParameter par = ModuleHelper.GetProperty(Domains.VIRTUAL, "N19S0", "Sensor.DigitalValue");
if (par.Value == "1")
{ // bathroom alarm if (m.Domain == Domains.MYSENSORS && m.Address == "N8S0" && p.Property == "Sensor.Leak" && p.Value == "1") SmsHelper.SendSms("+38xxxxxxxxx","Water leak in bathroom"); // living room if (m.Domain == Domains.MYSENSORS && m.Address == "N3S0" && p.Property == "Sensor.Leak" && p.Value == "1") SmsHelper.SendSms("+38xxxxxxxxx","Water leak in living room"); } return true; }); } /* This code is running periodicaly when program is enabled. Cron job detirmine running period. */ public void Run() { }
Comments
Simply check when is last time when you send SMS and if time is to short do not send message again.
If I remember correctly one of community members post solution on forum.
Yes, there are two programs. One without switch and one with enable/disable switch.
RSS feed for comments to this post