Feedback Wanted: Rules, Scenes, Tasks for my raspberry pi / web api project

Discussion in 'General Discussion' started by ievolve, Feb 16, 2013.

  1. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    Hey Guys,

    I appreciate all the feedback I have been getting on my efforts to come up with a real lightweight web api, and http interface to cbus that will easily run on a raspberry pi. I've been running for several weeks now and it has been pretty flawless.

    I was hoping to get some feedback on the way I am dealing with Rules, Scenes, and Tasks from those of you would have been doing this for a while and see if I am doing this in a way that makes sense.

    RULES: The rules engine will fire anytime there is a level change on a group. Rules have an expression that will evaluate the javascript, and fire the command(s) associated with the rule. The expression can use variables such as group level, or even some canned variables that are available such as sunset, sunrise, time, etc. Here is an example of a rule that ramps up the hall light if motion is sensed in a given area after 11PM (and before dawn):
    Code:
    {
        "id":"1",
        "name":"Late night motion on",
        "expression":"group=='95' && level > 0 && (time > '23:00' || time < dawn)",
        "commands":[
            {"type":"lighting","group":"46","level":20,"delay":0,"timeout":0}
         ]
    }
    TASKS: Task are recurring tasks that should fire command(s) on a given interval. In order to do that a CRON string is given which allows for very complex scheduled tasks to run at various intervals, on certain days, etc. CRON strings seemed like a great way to do recurring tasks. Here is an example that turns on the night lights every day of the week at 8:30PM:
    Code:
    {
        "id":"1",
        "name":"Turn on night lights",
        "cronstring":"00 30 20 * * 1-7",
        "expression":"",
        "commands":[
            {"type":"lighting","group":"46","level":20,"delay":0,"timeout":0}
        ]
    }
    SCENES: Scenes are pretty straight forward, when triggered and array of commands are fired. Here is a complex group of commands, first a light fades up to 20%, then there is a delay of 2 seconds, then a URL is called (callbacks can be useful), and finally a light comes up to 75%:
    Code:
    {
        "id":"3",
        "name":"Reading",
        "commands":[
            {"type":"lighting","group":"51","level":20,"delay":0,"timeout":0},
            {"type":"delay","delay":2},
            {"type":"url","url":"http://requestb.in/1jjdtu61"},
            {"type":"lighting","group":"53","level":75,"delay":0,"timeout":0}
         ]
    }
    COMMANDS: As illustrated above commands are an array of things that should happen when a task happens, a rule is matched, or a scene fires. Commands generally are just modifying the level of light, but each command has a "type" which allows for more flexible scenarios. Other types include: lighting, delay, url, email, sms, etc. Ever wanted to get a url callback when a button on the wall is pressed? You can do that. Need an SMS when motion is detected during certain hours? You can do that. The command types should allow for a lot of use cases. When using the lighting command you may also add a delay (which is the ramp delay), and/or also a timeout which allows the group to auto turn off after X seconds.

    Any feedback you guys might have on things I have missed, or other ways to look at things would be awesome. I'm really excited to get this into your hands and let you kick the tires.
     
    Last edited by a moderator: Feb 17, 2013
    ievolve, Feb 16, 2013
    #1
  2. ievolve

    poldim

    Joined:
    Dec 7, 2010
    Messages:
    166
    Likes Received:
    2
    Location:
    San Francisco, CA
    This sounds interesting. If its as easy as it looks in your code here, this would be a good addition for ~35 bucks.
     
    poldim, Feb 24, 2013
    #2
  3. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    ievolve, Nov 10, 2014
    #3
  4. ievolve

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    130
    Likes Received:
    1
    Location:
    Sydney, Australia
    welcome back!

    looked into your project many months ago, but all content was gone from github. thanks for putting it back :)
     
    zei20t, Nov 11, 2014
    #4
  5. ievolve

    poldim

    Joined:
    Dec 7, 2010
    Messages:
    166
    Likes Received:
    2
    Location:
    San Francisco, CA
    How straightforward is this to use? I haven't tried using the Raspberry Pi yet so this would be my first attempt. Do you have any instructions or tutorials on how to set it up? Sport if they're on the link, I didn't get a chance to dig in...
     
    poldim, Nov 11, 2014
    #5
  6. ievolve

    ievolve

    Joined:
    Mar 20, 2010
    Messages:
    112
    Likes Received:
    1
    Location:
    Idaho
    It might be easier to try just on a windows machine and if you like it and want a low power inexpensive way to run it then you can look at the raspberry pi.

    It is pretty straight forward to run, just need to get nodejs on the machine you want to run it from (www.nodejs.org) once it is installed you can download it from the link and run "npm install" from the directory you extracted the code to. After that you will want to update the config.js and db.json to the variables pertinent to your network. Finally, you can run "node server.js" and hit it from a browser. Let me know if you have any questions.
     
    ievolve, Nov 11, 2014
    #6
  7. ievolve

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    130
    Likes Received:
    1
    Location:
    Sydney, Australia
    zei20t, Nov 11, 2014
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.