• 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
#31
Possible new methods for "time-based" eventing will not be part of pilight version 6 and once version 6 is released, it probably will take some time to carefully think what will be the best solution and implement that.

I am trying not to be the smart-alec, but I still think that in the meantime my solution can be useful for other pilight users.

Since this solution works with just a few new operators and does not touch the core of pilights eventing system at all, couldn't it be a nice way to provide those who need eventing based on time an intermediate and safe way to create compact and clear rules for that?

In addition to the minustime (-t), plustime (+t) and random (~) operators I made a version of the datetime protocol with one additional property "time", that gives the current time in hh.mm format, which simplifies creating time based rules even more.

Rules that looked quite complex before, with "MOD"s, "DIV"s and "OR"s and lots of hooks, are now looking as simple as this:

Code:
"teston": {
         "rule": "IF huiskamer3.state IS off AND datetime.time == (23.00 +t (0 ~ 90.01)) THEN switch DEVICE huiskamer3 TO on",
         "active": 1
},
"testoff": {
         "rule": "IF huiskamer3.state IS on AND datetime.time == (23.00 +t (0 ~ 90.01) +t (5 ~ 30.02)) THEN switch DEVICE huiskamer3 TO off",
         "active": 1
  }

The first rule switches the device on at a time between 23:00 and 00:30. The second one switches it off between 5 and 30 minutes later.

The results of the random operator change once a day at midnight. So the moment the device is switched on and the time it stays on will be different every day. Random operations with a second operand with the same fractional part will use the same seed and thus give the same result in any rule during the day. With a different fractional part the seed will be different and so will the result.

But even a rather simple rule without random operations like one that switches a device at a time based on let's say sunset time, is simplified quite a lot:

Code:
IF portiek.state IS off AND datetime.time == (sunriseset.sunset -t 30) THEN ...

Without my operators and datetime protocol, this would look something like this:

Code:
IF portiek.state IS off AND sunriseset.sunset == (((datetime.minute + 30) % 60) / 100) + ((datetime.hour + ((datetime.minute + 30) \\ 60)) % 24) THEN ...
 
Reply
#32
Still, the whole points of software development is that you just can't constantly include new stuff Smile You can always distribute them as modules on your own. That's also why all protocols and operators are modular.
 
Reply
#33
Yes, I agree.
It was in fact just because the modularity makes it so easy to add stuff, that I didn't see it as a change to the version you are trying to finish. But now I realise that of course it would have been be a change.

I will stop asking for new things until version 6 is published, but after that........SmileSmile.

But no kidding, it is a great great solution you have developed and I thank you very much for this.
 
Reply
#34
Can you make a tutorial on how users can add these operators / protocols themselves based on what's described here:
http://www.pilight.org/modules/protocols/#module
 
Reply
#35
Yes, I will make such a tutorial.

To be sure that the tutorial will tell the right things to do, I excersised the proces of building and installing the modules myself first, but I ran into something I don't understand.

I installed pilight with the modified datetime protocol already in libs/protocols, so the protocol was built straight into pilight. That works fine, but if I use that same protocol as a module, pilight crashes with a Segmentation Fault.

gdb doesn't give me a clue to what is wrongConfused, but hopefully you will recognise this behaviour and know what to do about it:

Code:
(gdb) backtrace
#0  0x00000000 in ?? ()
#1  0xb6fc5ab4 in datetimeParse () from /usr/local/lib/pilight/protocols/datetime.so
#2  0xb6e2dc00 in start_thread () from /lib/arm-linux-gnueabihf/libpthread.so.0
#3  0xb6d50358 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6
#4  0xb6d50358 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)
 
Reply
#36
What does Frame 1 tell us? And did you compile with the gcc -g parameter to include the debugging symbols?
 
Reply
#37
Just to make sure that the Segmentation Fault was not related to my modification, I built a module with the original datetime.c. (compiled with -g this time Smile).

pilight crashes due to a Segmentation Fault at the same statement in datetimeParse as with the modified version. As I mentioned before, this happens when used as a module and not when compiled into pilight.

Code:
(gdb) backtrace
#0  0x00000000 in ?? ()
#1  0xb6fc5a94 in datetimeParse (param=0xadaf0) at libs/protocols/datetime.c:227
#2  0xb6e2dc00 in start_thread () from /lib/arm-linux-gnueabihf/libpthread.so.0
#3  0xb6d50358 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6
#4  0xb6d50358 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) frame 1
#1  0xb6fc5a94 in datetimeParse (param=0xadaf0) at libs/protocols/datetime.c:227
227                     pilight.broadcast(datetime->id, datetime->message);
(gdb)
 
Reply
#38
Can you post the link to the source?
 
Reply
#39
It is just the current one from the development branch, cloned from github 3 days ago (january 27), so after your latest commit.

https://github.com/pilight/pilight/blob/...datetime.c
 
Reply
#40
Short question to your MOD operator:

I use it to switch a fan to on every 10 seconds who distributes fog.
Is there a possible rule to switch the device off after fixed seconds?
At the moment i use the "old" variant for this:
Code:
        "airfog_on": {
            "rule": "IF rfans.state IS on AND fog.state IS on AND (zeit.second % 10 == 0) THEN switch DEVICE airfog TO on",
            "active": 1
        },
        "airfog_off": {
            "rule": "IF rfans.state IS on AND airfog.state IS on AND (zeit.second == 01 OR zeit.second == 11 OR zeit.second == 21 OR zeit.second == 31 OR zeit.second == 41 OR zeit.second == 51) THEN switch DEVICE airfog TO off",
            "active": 1
        },
 
Reply
  


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

Forum Jump:


Browsing: 1 Guest(s)