• 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
Howto: easy eventing via crontab (incl. scheduling of sun/device/time dependencies)
#1
As discussed in a different thread I had the issue that switching multiple devices with one rule does not work in my case, as devises don’t switch reliable if there is no pause of at least 0.6 seconds between multiple switch commands. An alternative approach would have been to set up ~40 individual rules, but that would have been difficult to maintain. So I finally decided to move all eventing from pilight to crontab. And here is how I did that…

sunwait (modified main.c attached)
I am using a slightly modified version of https://www.risacher.org/sunwait. Main difference is that this modified version of sunwait does not wait for the next day when the specified time has already passed. It simply terminates. Also some -otherwise mandatory- parameters have been made optional

pilight-state (attached)
this is a one-liner (using jq for parsing json) to retrieve the state of any define pilight device from the daemon via:
Code:
wget -qO - http://localhost:5001/config | jq -r ".devices.\"$1\".state"
This way you can make switching dependent from the status of any device

pilight-switch (attached)
this little script is switching one defined device (or all) on or off - waiting 1 second between individual pilight-control executions

crontab (attached)
a part of the resulting crontab that I am currently using, replacing the necessity to otherwise define 39 rules in config.json

examples
let me explain 2 examples from the crontab:

switch on devices 10-1 10-3 20-2 20-3 30-1 at 7:05 AM on weekends if device "Unsch" has state "on"
Code:
05 07 * * 6,7  [ `pilight-state Unsch` = on ]       && pilight-switch on  10-1 10-3 20-2 20-3 30-1

switch off devices 10-3 10-4 10-5 20-2 20-3 20-5 30-1 at 1 hour after sunrise, earliest at 9:00 AM
Code:
00 09 * * *    sunwait sun up +1:00; [ $? -le 1 ]   && pilight-switch off 10-3 10-4 10-5 20-2 20-3 20-5 30-1



.zip   files.zip (Size: 3.75 KB / Downloads: 2)
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  puzzled by syntax when using RANDOM time Emiks5 4 211 03-04-2020, 10:57 PM
Last Post: Emiks5
  [Solved] On and Off for one device in one rule Oliver 3 494 10-28-2019, 06:55 PM
Last Post: Oliver
  Can't switch Relay device by rules: Error switch.lua:77 wobbi 6 1,171 07-31-2018, 06:25 AM
Last Post: curlymo
  Rule with&without device. One working not the other... Tamadite 9 1,436 07-24-2018, 08:55 AM
Last Post: curlymo
  Always trigger event on any device state Phil 8 2,488 03-22-2017, 07:30 PM
Last Post: Phil
  Rule executed at wrong time philipp81 1 992 02-25-2017, 10:43 PM
Last Post: curlymo
  Eventing intervalls via webgui Shorf 3 1,772 08-30-2016, 06:18 AM
Last Post: Shorf
  [Solved ]Turn off device at random time manmetdehamer 4 2,271 07-27-2016, 03:35 PM
Last Post: manmetdehamer
  event at randomized time after another event Emiks5 3 1,657 05-07-2016, 09:10 AM
Last Post: Thunder84
  Time interval between two rule checks muecke 3 1,992 04-21-2016, 02:31 PM
Last Post: pilino1234

Forum Jump:


Browsing: 1 Guest(s)