• 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
pilight eventing - sunset/sunrise/time
#1
The sunset and sunrise times of openweathermap protocol are in a hh.mm format (hours and minutes combined in one field). This means that they cannot be used in a comparison in a rule because datetime returns the hours and minutes as separate fields.

So a rule like
Code:
IF datetime.time == sunset THEN ......
is not possible now, but has an equivalent as
Code:
IF weather.sun is set THEN .....

But what I really want to be able to do is something like this:

Code:
IF datetime.time == sunset + 30 minutes THEN .........

and this requires not only to have time fields in matching formats, but also the ability to do calculations with time.
 
Reply
#2
Code:
IF (sunriseset.sunset == (datetime.hour + (datetime.minute / 100))) THEN ...
 
Reply
#3
Oops.. Should have thought of that myselfConfused I didn't realise that the time fields of openweathermap are in fact just numbers. Shame on me.

That left me with the problem of the second example in my post, because adding to, or subtracting from minutes can cause an over/underflow ( > 59 or < 0). In case of sunset and sunrise fortunately we don't have to care about over/underflow with hours, because sunset and sunrise never will be around midnight.

For my example (30 minutes after sunset) I think i will split the rule in two like this (not tested yet!):
Code:
IF (datetime.minute  - 30) >= 0 AND sunriseset.sunset == (datetime.hour + (datetime.minute - 30) / 100) )THEN ...

IF (datetime.minute  - 30)  < 0 AND sunriseset.sunset == (datetime.hour - 1) + (datetime.minute - 30 + 60) / 100) )THEN ...
I assume something like this will work, but having a method for calculations with time/date would be appreciated.
 
Reply
#4
Or in one rule:
Code:
IF ((datetime.minute  - 30) >= 0 AND sunriseset.sunset == (datetime.hour + (datetime.minute - 30) / 100)) OR ((datetime.minute  - 30)  < 0 AND sunriseset.sunset == (datetime.hour - 1) + (datetime.minute - 30 + 60) / 100) THEN ...
 
Reply
#5
Hi,
I am new to the pilight community. I started this weekend and got a whole lot of nice eventing working. What I am missing in the basic functionality is to start and stop at random times. I thought I had found the answer with the time_math 3rd party module. However I do have a lot of problems to get it to work.
First of all the dependency on libpcap is not mentioned on the install page.
Once I got past that hurdle I found that pilight.h in the GitHub suppository is missing so I cannot compile the newdatetime protocol.
Finally I tried to move only the operators (since I am only really interested in the random operator). But now I get the message that /usr/local/lib/pilight/operators/ is not a directory. So I cannot copy my random.so file to it. Is this because pilight has a new file structure?

I do not know if this is the right part of the forum to post this if not please redirect me to the correct part.

Thank you for your help.
 
Reply
#6
Beside a solution with pilight/eventing you may have a look at piSchedule, an extension for pilight focusing on switching device also with sunrise/sunset and random variations of switch points also.
 
Reply
#7
@clkoolen

To use the third party modules you need to install pilight manually from the development branch. Here you can read how to manually install pilight.

Manual installation and subsequent compilation of third party modules requires libunwind-dev and libpcap-dev

The module directories such as /usr/local/lib/pilight/operators/ are not created by default, but you can create them yourself if needed.
 
Reply
#8
Hallo Niek,
Did you test the two rules? I tried (e.g. 3 h 22 min delay after sunrise ) but no way to make it work. Any suggestion?
Regards.
Code:
{
        "devices": {
                "datetime": {
                        "protocol": [ "datetime" ],
                        "id": [{
                                "longitude": 8.96965,
                                "latitude": 46.35972
                        }],
                        "year": 2015,
                        "month": 4,
                        "day": 17,
                        "hour": 9,
                        "minute": 57,
                        "second": 57,
                        "weekday": 6
                },
                "lamp01": {
                        "protocol": [ "elro_800_switch" ],
                        "id": [{
                                "systemcode": 31,
                                "unitcode": 1
                        }],
                        "state": "off"
                },
                "lamp02": {
                        "protocol": [ "elro_800_switch" ],
                        "id": [{
                                "systemcode": 31,
                                "unitcode": 2
                        }],
                        "state": "off"
                },
                "lamp03": {
                        "protocol": [ "elro_800_switch" ],
                        "id": [{
                                "systemcode": 31,
                                "unitcode": 4
                        }],
                        "state": "off"
                },
                "sunriseset": {
                        "protocol": [ "sunriseset" ],
                        "id": [{
                                "longitude": 8.96965,
                                "latitude": 46.35972
                        }],
                        "sunrise": 6.35,
                        "sunset": 20.14,
                        "sun": "rise"
                }
        },
        "rules": {
                "living_lights_02_on_rise": {
                        "rule": "IF (((datetime.minute - 22) >= 0 AND sunriseset.sunrise == ((datetime.hour - 3) + (datetime.minute - 22) / 100)) OR ((datetime.minute - 22) < 0 AND sunriseset.sunrise == (datetime.hour - 4) + (datetime.minute - 22 + 60) / 100)) AND lamp02.state IS off THEN switch DEVICE lamp02 TO on",
                        "active": 1
                }
        },
        "gui": {
                "datetime": {
                        "name": "Time & Date",
                        "group": [ "Living" ],
                        "media": [ "all" ],
                        "format": "HH:mm:ss - DD MMMM YYYY"
                },
                "lamp01": {
                        "name": "Lamp 1",
                        "group": [ "Living" ],
                        "media": [ "all" ]
                },
                "lamp02": {
                        "name": "Lamp 2",
                        "group": [ "Living" ],
                        "media": [ "all" ]
                },
                "lamp03": {
                        "name": "Lamp 3",
                        "group": [ "Kitchen" ],
                        "media": [ "all" ]
                },
                "sunriseset": {
                        "name": "Sunrise / Sunset",
                        "group": [ "Weather" ],
                        "media": [ "all" ]
                }
        },
        "settings": {
                "log-level": 4,
                "pid-file": "/var/run/pilight.pid",
                "log-file": "/var/log/pilight.log",
                "receive-repeats": 1,
                "ntp-servers": [ "0.ch.pool.ntp.org", "1.ch.pool.ntp.org", "2.ch.pool.ntp.org" ],
                "ntp-sync": 1,
                "webserver-enable": 1,
                "webserver-root": "/usr/local/share/pilight/",
                "webserver-port": 5001,
                "webserver-cache": 1
        },
        "hardware": {
                "433gpio": {
                        "sender": 0,
                        "receiver": 1
                }
        },
        "registry": {
                "pilight": {
                        "firmware": {
                                "version": 3,
                                "lpf": 80,
                                "hpf": 16000
                        },
                        "version": {
                                "current": "6.0"
                        }
                }
        }
}
 
Reply
#9
I have a Problem with time-based eventing.

I want to Switch a light half an hour before sunrise to on for three hours.

But already my Basic ruleset produces an Error:

Code:
"sunrise": {
                        "rule": "IF sunriseset.sunrise == DATE_FORMAT(datetime, %H.%M) AND AQ-Licht.state IS off AND datetime.second == 0 THEN switch DEVICE AQ_Licht TO on",
                        "active": 1
                }

Code:
[Apr 26 16:50:39:380732] pilight-daemon: ERROR: rule #3 invalid: trying to compare string variable "sunriseset.sunset" to an integer
[Apr 26 16:50:39:382104] pilight-daemon: INFO: rule #3 was parsed until: ... sunriseset.sunset == 18.39 AND AQ-Licht.state IS off AND datetime.second == 0 THEN switch DEVICE AQ-Licht TO on

Any Suggestions?
 
Reply
#10
The rule you're posting is not the one giving the error. Please post the correct rule.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  puzzled by syntax when using RANDOM time Emiks5 4 224 03-04-2020, 10:57 PM
Last Post: Emiks5
  [solved] sunset rule doesn't work fleisch 4 479 10-26-2019, 07:05 AM
Last Post: fleisch
  Sunset state check parse error dennisvo 6 518 09-27-2019, 08:34 PM
Last Post: curlymo
  pilight service not starting vlatko.jordanov 2 772 05-26-2018, 01:42 PM
Last Post: vlatko.jordanov
  Rule Sunset works, Sunrise not apartmedia 1 1,228 12-05-2017, 07:09 PM
Last Post: apartmedia
  tabs on pilight SeLi 5 2,770 05-31-2017, 09:25 PM
Last Post: NormBot
  Rule executed at wrong time philipp81 1 992 02-25-2017, 10:43 PM
Last Post: curlymo
  Eventing intervalls via webgui Shorf 3 1,775 08-30-2016, 06:18 AM
Last Post: Shorf
  [Solved ]Turn off device at random time manmetdehamer 4 2,273 07-27-2016, 03:35 PM
Last Post: manmetdehamer
  alarm system using pilight rbrueckner 4 2,351 05-14-2016, 12:24 PM
Last Post: diman87

Forum Jump:


Browsing: 1 Guest(s)