Wednesday 18 December 2013

Cyrus rule to turn on a light when it gets dark

Here is what a Cyrus rule could look like, to turn on that light that I mentioned yesterday.

There are two Cyrus objects, the first representing the light, and the other representing the light sensor which is on a different host (e.g. another R-Pi):

{ Rules: uid-RR
  is: light
  light: 0 0 0
  light-sensor: http://X.X.X.X/o/uid-SS.json
}

{ is: light-sensor
  light-level: 200
}

The light object is currently off (RGB=0,0,0). It has a link to the light sensor (uid-SS) whose level is 200.

Here's the rule object that turns on the light when the light level falls below 100:

{ is: light rule
  light-sensor: { light-level: < 100 }
  light: => 1 1 1
}

The light object has a link to this rule (uid-RR). It's on the same host, so doesn't need a full URL.

This rule will attempt to pattern-match to the light and rewrite it if it matches. The "=>" symbol - pronounced "becomes" - is the place where the light is turned on (RGB=1,1,1) if the condition "< 100" matches the light level.

This rule transparently jumps the light-sensor link to see into the light sensor object as if it were inlined, which triggers an observation of the sensor over the network. Whenever the light level is updated, the rule will be re-triggered.


End User Programming

Now clearly I'm not expecting just anyone to be able to program like this, but it's possible to see how close this language is to something that anyone could access through a GUI, perhaps in the style of If This Then That.

People who are competent in Excel formulae or HTML and CSS will have no trouble at all programming their Things in Cyrus.

No comments:

Post a Comment