• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Done] Eventing - operators MOD and DIV
Change it to this:
IF ((dummy.state IS off) AND (sunriseset.sunset == ((((datetime.minute + 90) % 60) / 100) + ((datetime.hour + ((datetime.minute + 90) \\ 60)) % 24)))) THEN ...
Again thanks for your help.

In the meantime I have created a github account. Following the tutorial, I created a fork of pilight and added my sources to the operators folder of the development branch. It looks like I can create a pull request for my sources now.

Is that how you want it to be?

I have one more operator (~). This one returns a pseudo random value. E.g. 10 ~ 30 returns a value between 10 and 30. This is on github too. Is that OK, or should I only have sources in there that you explicitly ask me to create a pull request for?

If you wish, you can have a look at my github
The steps should be this:
1. Create a clean fork of pilight
2. Commit each new functionality to a new branch (in one commit).
3. Do a PR from each branch.

I have created a new set of operators for manipulations with time: plustime (+t) and minustime (-t). With these operators you can easily and safely add/subtract any number of minutes to/from a given time.


IF dummy.state IS off AND sunriseset.sunset +t 90 == datetime.hour + datetime.minute / 100 THEN ...

This makes rules like this easier to debug than when the time calculation is done in the rule itself and reduces the number of replacements required to evaluate such rules.

If you like these operators, of course I will be happy to share them.

As an example, this is the code of the +t operator:

    Copyright (C) 2015 CurlyMo & Niek

    This file is part of pilight.

    pilight is free software: you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free Software
    Foundation, either version 3 of the License, or (at your option) any later

    pilight is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with pilight. If not, see    <http://www.gnu.org/licenses/>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "log.h"
#include "operator.h"
#include "plustime.h"
#include "dso.h"
#include "math.h"

static void operatorPlustimeCallback(double a, double b, char **ret) {
    double hour, minute;
    int getMod(int a, int b){
        int result = a - b * floor(a / b);
        return result;
    int getDiv(int a, int b){
        int result = a / b;
        return result;
    minute = modf(a, &hour) * 100;
    sprintf(*ret, "%f", (double)getMod(hour + getDiv(minute + b, 60), 24) + (double)getMod(minute + b, 60) / 100);

#ifndef MODULE
void operatorPlustimeInit(void) {
    event_operator_register(&operator_plustime, "+t");
    operator_plustime->callback_number = &operatorPlustimeCallback;

#ifdef MODULE
void compatibility(struct module_t *module) {
    module->name = "+t";
    module->version = "0.1";
    module->reqversion = "5.0";
    module->reqcommit = NULL;

void init(void) {
I like the idea, but i rather create some sort of function support in the next version line MYSQL does it: http://dev.mysql.com/doc/refman/5.1/en/d...n_date-add
I am aware of this (I have worked with MYSQL before), but functions are not available in pilight as yet. Anyway, your are the boss Smile. So I will use these operators myself until something better becomes avalable .
I recommend that some kind of line is drawn to separate real-time (event) processing from control level operation.
Please elaborate
You want to perform certain tasks in real-time (event processing, status monitoring, data collection, control tasks), using a minimum amount of resources (e.q. CPU cycles, memory)
Other tasks (GUI events / button presses), you want to be responsive as well, however then there is a set of tasks (Data logging) for which time delays are tolerable in exchange for handling lots of data and storing them safely using easy to use standards. The comfort of SQL typically comes with a price tag (in the form of CPU cycles) - the comfort of speed with cryptic interfaces.
In pilight, certain threads already get more or less priority. The sending and receiving threads currently get most.

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Done] pilight eventing - dimming step by step terrar 3 3,181 02-11-2015, 02:39 PM
Last Post: Niek
  [Done] pilight-cron (implemented with eventing) dzjaivnt 30 20,644 04-28-2014, 11:48 PM
Last Post: dzjaivnt
  [Done] Eventlist (implemented with eventing) JurnD 18 8,380 01-16-2014, 08:39 PM
Last Post: curlymo

Forum Jump:

Browsing: 2 Guest(s)