Jump to content









Photo

Rules examples

Rule Alarm Groovy

  • Please log in to reply
11 replies to this topic

#1 Manuel39

Manuel39

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 09 May 2014 - 06:48 PM

Hello,

 

First at all, congratulations for Carriots. :)

I'm beginning to discover it's fonctionnalities. I'm using and arduino and Ethernet module. I send temperature data to Carriots. It's works well.

Now, I want to generate an sms if temperature data exeeeds an specific value. I saw exemple with a listener, but I just need to send one sms when the transition occurs. It could be same with high to low transition.

Could i use a Rule to manage this, with local variable ? Have you some examples to share ?

 

Thanks for your advice.

E.L.

 

 

 



#2 jpastor

jpastor

    Development leader

  • Administrators
  • 159 posts

Posted 12 May 2014 - 08:29 AM

Hello Manuel39

 

You have two different ways to do that.

1. Send to Carriots temperature only when the transition occurs.
The example would be like our alert system tutorial. Arduino sends streams only when it changes from "light" to "no-light" or vice versa.

2. Always send the temperature and set the logic in Carriots. For this, the best way is to create a "device property" to mark the transition and check it to see if you send the sms. A device property is like a variable that you can use as you wish.
I am attaching some tips that will be useful to use device properties:

* Create property

 

Attached File  create_property.jpg   33.71K   92 downloads


* Check property (replace defaulDevice@carriots with your device):

import com.carriots.sdk.Device;

def device = Device.find('defaultDevice@carriots');
def value = device.device_properties.YOUR_PROPERTY;

 

if (value...

* Update property (replace defaulDevice@carriots with your device):

import com.carriots.sdk.Device;

def device = Device.find('defaultDevice@carriots');
device.device_properties.your_property=NEW_VALUE;
device.update();

 

 

 

Hope this helps. Please tell us if you have any questions



#3 Manuel39

Manuel39

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 13 May 2014 - 07:34 AM

Hi,

Thanks for your reply.

I want to use the second solution, because I need to store all data collected in carriots for future usage.

I understood how to declare a property and use it. But I need more info to write my code.

Could you explain me the difference between LIstener and Rule ? Because in a Listener, we can already write a kind of rule in if/then/else expression.

I don't know groovy langage (but I use java). How to transtype a text (context.data.sonde1 in my example) to numeric value (float) in groovy and test it ?

I want to write this kind of algorithm in carriots:

 

Property AlarmFired = false

For each context.data.mydata received {

   If mydata > temperature float value {

      if AlarmFIred = false {

          AlarmFired = true

          Send an sms : alarm and context.data.mydata value

       }   

   }

   else {

      if AlarmFIred = true {

          AlarmFired = false

          Send an sms : End of alarm and context.data.mydata value

       }

   }

 

}

 

In fact I just want to deal with raising or falling edge of a signal in carriots. :)

Many thanks.

 

Emmanuel



#4 Manuel39

Manuel39

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 19 May 2014 - 08:58 AM

Just for Up :)

 

Any idea for my small project ?

Thanks.



#5 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 103 posts
  • LocationMadrid, Spain.

Posted 19 May 2014 - 11:55 AM

Hi!

 

You can try write a listener (event: event data received), this listener is thrown in each stream that received the carriots platform:

 

import com.carriots.sdk.Device;

def device = Device.find('your_device@here');

if context.data.temperature > 30.0 {
	device.device_properties.fired=1;
	device.update();
} else {
  if device.device_properties.fired == 1 {	
  	device.device_properties.fired=0;
	device.update();
  }
}

 

I hope this helps, if you have questions do not hesitate to ask.



#6 jpastor

jpastor

    Development leader

  • Administrators
  • 159 posts

Posted 19 May 2014 - 12:13 PM

Hello Manuel39.

 

I propose a solution, although it is not the most efficient if it is very didactic and will help you understand how to work with listeners in Carriots.

Steps:

1. Creating a new property called "alarmFired" with value "false".
Attached File  create_property.jpg   33.71K   124 downloads

2. Creating a listener with the desired logic.
For this example, suppose that data stream that you send is like this: {"temp":"24.7"}

Attached File  listener.jpg   65.53K   148 downloads

 

I write here the code so you can reuse it

- If expression:

context.data.temp.toBigDecimal() > 25

 

- Then expression:

import com.carriots.sdk.Device;
import com.carriots.sdk.utils.Email;


def device = Device.find('YOUR DEVICE');
def alarm = device.device_properties.alarmFired;

if (alarm=="false") {
  def email = new Email();
  email.to="YOUR EMAIL";
  email.message="Alarm. Temp: " +context.data.temp;
 
  alarm="true";
  device.device_properties.alarmFired=alarm;
  device.update();
  email.send();
}

 

- Else expression:

import com.carriots.sdk.Device;
import com.carriots.sdk.utils.Email;


def device = Device.find('YOUR DEVICE');
def alarm = device.device_properties.alarmFired;

if (alarm=="true") {
  def email = new Email();
  email.to="YOUR EMAIL";
  email.message="End of alarm. Temp: " +context.data.temp;
 
  alarm="false";
  device.device_properties.alarmFired=alarm;
  device.update();
  email.send();
}

 

 

The example is made with email, but you can do it with SMS if you want.

 

Hope it helps.

 

Enjoy Carriots!

 

 

 

 

 

 



#7 Manuel39

Manuel39

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 23 May 2014 - 08:26 AM

Hi,

 

I will try your solution as soon as possible.

I will give a feedback in this post.

 

Thanks for help.

 Emmanuel



#8 archit2112

archit2112

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 02 July 2014 - 10:06 AM

Hello Manuel39.

 

I propose a solution, although it is not the most efficient if it is very didactic and will help you understand how to work with listeners in Carriots.

Steps:

1. Creating a new property called "alarmFired" with value "false".
attachicon.gifcreate_property.jpg

2. Creating a listener with the desired logic.
For this example, suppose that data stream that you send is like this: {"temp":"24.7"}

attachicon.giflistener.jpg

 

I write here the code so you can reuse it

- If expression:

context.data.temp.toBigDecimal() > 25

 

- Then expression:

import com.carriots.sdk.Device;
import com.carriots.sdk.utils.Email;


def device = Device.find('YOUR DEVICE');
def alarm = device.device_properties.alarmFired;

if (alarm=="false") {
  def email = new Email();
  email.to="YOUR EMAIL";
  email.message="Alarm. Temp: " +context.data.temp;
 
  alarm="true";
  device.device_properties.alarmFired=alarm;
  device.update();
  email.send();
}

 

- Else expression:

import com.carriots.sdk.Device;
import com.carriots.sdk.utils.Email;


def device = Device.find('YOUR DEVICE');
def alarm = device.device_properties.alarmFired;

if (alarm=="true") {
  def email = new Email();
  email.to="YOUR EMAIL";
  email.message="End of alarm. Temp: " +context.data.temp;
 
  alarm="false";
  device.device_properties.alarmFired=alarm;
  device.update();
  email.send();
}

 

 

The example is made with email, but you can do it with SMS if you want.

 

Hope it helps.

 

Enjoy Carriots!

Initially the alarm is set to false and when the temperature goes beyond 25 the value of alarm is changed to true. Is there a way to change the value of alarm back to false after ..say...1 hour ?



#9 jpastor

jpastor

    Development leader

  • Administrators
  • 159 posts

Posted 04 July 2014 - 06:31 AM

Hello archit2112

When you define your device, you have two fields named "Data Stream Frequency" and "Status Stream Frequency". This fields are a number representing the time range in which a data stream should be received (expressed in minutes).

If your device doesn't recive a stream in that timespan, their status will be automatically "disconnected", but If you send a stream your device will change to "OK".

These status are represented with different colors in the "list devices" window.

To know more about the different inner device status, please visit:

https://www.carriots...ce_inner_status
https://blog.carriot...t-applications/

In Carriots you can execute a listener when a device changes the status. May be you can set the "Data Stream Frequency" or "Status Stream Frequency" to 60 min. and execute a listener when the device changes the status. In this listener you could modify the property to false.

Tell us if this solution is usefull for you.



#10 homerruma

homerruma

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 08 December 2014 - 05:42 PM

Hello

@Manuel39

 

 I'm using and arduino and Ethernet module. I send temperature data to Carriots.

I am new and do not know how to send temperature data to Carriots.

Have you used CarriotsClient-sendStream?

How to send data to the variable (temperature)?

Please post your code.



#11 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 103 posts
  • LocationMadrid, Spain.

Posted 11 December 2014 - 04:42 PM

Hi homerruma,

 

You could start reading this tutorial about send stream with Arduino to Carriots:

 

https://www.carriots...arduino_library

 

 

BR



#12 homerruma

homerruma

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 11 December 2014 - 05:09 PM

I managed to send data on the temperature.

Attached File  CARRIOTS.png   55.41K   52 downloads







Also tagged with one or more of these keywords: Rule, Alarm, Groovy

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users