Skip to content
Ulf edited this page Aug 31, 2014 · 12 revisions

Rule :

The following rule will switch on a light and after 20 seconds, the light will switched off.

fun(Pid, Name, Body) -> 
  case Body of 
    "off" -> ok; 
    "on" -> sensor:send([], Name, {"Licht","11111 2","1"}),
            sensor:send_after(Pid, Name, 20000, [], {"Licht","11111 2","0"});
        _ -> ok 
  end 
end.

When we get an motion detected signal, then we will inform the alarm thing to play a sound.

fun(Pid, Name, Body) ->  
  case Body of
    "on" -> sensor:send([], Name, "on"),
            sensor:send([], Name, [{to,"ua@innoq.com"}, {subject,"Alarm"}, {content, "somebody is in your house!"}]);
    _ -> ok
  end
end.

Sends only an on singnal. If a driver registrier to this event, you can play, for example, a sound.

fun(Pid, Name, Body) -> 
  sensor:send([], Name, "on") 
end.

Switch on the light when the actual time is between 8:00 and 19:00 o'clock.

fun(Pid, Name, Body) -> 
  case Body of 
    "off" -> ok; 
    "on" -> case date:is_time_in_range({08,00,00}, {19,00,00}, time()) of
                    true -> ok;
                    false -> sensor:send([], Name, {"Licht","11111 2","1"}),
                                sensor:send_after(Pid, Name, 20000, [], {"Licht","11111 2","0"})
                end;
        _ -> ok 
  end 
end.

Fail Over: When the node 'erlything1@macbook-pro' dies, than the thing 'Database' will be started on the local node.

fun(Name, Pid, [Payload]) -> 
    case Payload of 
       {error,{dead,'erlything1@macbook-pro'}} -> node_config:set_active("Database", true), ok; 
       {info,{alive,'erlything1@macbook-pro'}} -> node_config:set_active("Database", false), ok; 
      _Any -> nothing_to_do 
     end
end.

Clone this wiki locally