Question on Rules - Daylight if / etc

Hello:

Pretty new to OH, but finding my way around so far, and ready to ditch Vera! :slight_smile: I have a question around rules, and my lack of ability to program… Basically I have a trigger let’s call it Interior Garage Door ", that when I open it, I want the exterior garage lights to come on for a period of 10 minutes, then go off. Now, they should ONLY come on if it is dark outside ( I have installed Astro Binding, and it is working properly ).

I will also re enter the house through the same interior garage door, so when the door sensor get’s triggered, I ideally do not want the timer to start back at 10 minutes, but continue from when it was initially triggered…

Not sure if this is possible or not. The door trigger is a door contact on my alarm system with an EVL3 module, and the light is just a philips hue.

Here is my rule, minus of course the “Check if it’s Dark out” part, and not sure how to have the "re entry " into the house not stop the timer countdown.

Any help would be greatly appreciated


rule "Garage Light on Door Open"
when
    Item ZONE2_GENERAL_STATUS changed from CLOSED to OPEN
then
sendCommand(Light_Outdoor_Garage, "50")
createTimer(now.plusMinutes(10)) [|
sendCommand(Light_Outdoor_Garage, "0")
]
end

How about this:

Add an if statement prior to your lights on block and timer. Substitute whatever item you have for verifying day vs night.

Add another if statement prior to the timer block verifying if the light is already on.

//Test Rule for Garage Entry Timer

rule "Garage Light on Door Open"
when
Item ZONE2_GENERAL_STATUS changed from CLOSED to OPEN
then
if (daynight == “night”) { //if night do stuff
if (Light_Outdoor_Garage == 0) { //if light is off, start a timer and turn it on
createTimer(now.plusMinutes(10)) [|
sendCommand(Light_Outdoor_Garage, “0”)
]
sendCommand(Light_Outdoor_Garage, “50”)
}
}
end

Hey @Moxified

Thanks kindly for the reply. I’ve tried your code above, but unfortunately I can’t get it to work:


rule "Garage Light on Door Open"
when
Item ZONE2_GENERAL_STATUS changed from CLOSED to OPEN
then
if (Sunset_Event == ON) { //if night do stuff
if (Light_Outdoor_Garage == 0) { //if light is off, start a timer and turn it on
createTimer(now.plusMinutes(10)) [|
sendCommand(Light_Outdoor_Garage, "0")
]
sendCommand(Light_Outdoor_Garage, "50")
}
}
end

I See the rule executing:

2016-02-27 22:44:40.521 [DEBUG] [m.r.internal.engine.RuleEngine] - Executing rule 'Garage Light on Door Open'

But nothing happens. Been scratching my head for the last hour…

Thanks!

m0wlheld is right. I would also add logging into your rule until you have it working. Makes it easier to see where it broke down.

//Test Rule for Garage Entry Timer

rule "Garage Light on Door Open"
when
  Item ZONE2_GENERAL_STATUS changed from CLOSED to OPEN
then
  if (Sunset_Event == ON) { //if night do stuff
    loginfo("Garage Light on Door Open", "Is Night, do stuff")
    if (Light_Outdoor_Garage == 0) { //if light is off, start a timer and turn it on
     loginfo("Garage Light on Door Open", "Light was off, do stuff")
      createTimer(now.plusMinutes(10)) [|
        sendCommand(Light_Outdoor_Garage, "0")
        loginfo("Garage Light on Door Open", "Timer over, turned light off")
      ]
      sendCommand(Light_Outdoor_Garage, "50")
    } else loginfo("Garage Light on Door Open", "light was already on do nothing")
  } else loginfo("Garage Light on Door Open", "Is day, do nothing")
end

Hey @Moxified, @m0wlheld:

Guys thanks very much for the replies, greatly appreciated!

It’s now daylight here, so I’ve been experimenting with the Astro offset binding ( - / + 720 ) as you can see in the items file below, but I keep getting the following message logged on console, thinking it is daylight:

2016-02-28 10:05:59.520 [INFO ] [.m.s.Garage Light on Door Open] - Its day, do nothing

I tried following along with this post also from @KjetilA

That looks similiar as what mowlheld posted, but still no luck. Am I doing something wrong with the offset? Below is what my rules and items look like now:

Thanks very much again.

Rules:


rule "Daylight - Sunrise"
when
	Item Sunrise_Event changed to ON
then
	logInfo("daylight", "End of sunrise. It is now daylight outside.")
	Daylight.postUpdate(ON)
end

rule "Daylight - Sunset"
when
	Item Sunset_Event changed to ON
then
	logInfo("daylight", "Start of sunset. It is now dark outside.")
	Daylight.postUpdate(OFF)
end


//Test Rule for Garage Entry Timer

rule "Garage Light on Door Open"
when
  Item ZONE2_GENERAL_STATUS changed from CLOSED to OPEN
then
  if (Sunset_Event == ON) { //if night do stuff
    logInfo("Garage Light on Door Open", "Its Night, do stuff")
    if (Light_Outdoor_Garage == 0) { //if light is off, start a timer and turn it on
     logInfo("Garage Light on Door Open", "Light was off, do stuff")
      createTimer(now.plusMinutes(10)) [|
        sendCommand(Light_Outdoor_Garage, "0")
        logInfo("Garage Light on Door Open", "Timer over, turned light off")
      ]
      sendCommand(Light_Outdoor_Garage, "50")
    } else logInfo("Garage Light on Door Open", "light was already on do nothing")
  } else logInfo("Garage Light on Door Open", "Its day, do nothing")
end

Items File:

/* Sunset - Rise Items Start */

DateTime Sunrise_Time   "Sunrise [%1$tl:%1$tM %1$tp]"  {astro="planet=sun, type=rise, property=start"}
DateTime Sunset_Time    "Sunset [%1$tl:%1$tM %1$tp]"   {astro="planet=sun, type=set, property=end"}
Switch   Sunrise_Event                           		{astro="planet=sun, type=rise, property=start, offset=0"}
Switch   Sunset_Event                            		{astro="planet=sun, type=set, property=end, offset=-720"}
Switch Daylight

If you are getting that then your daylight switch still shows on. You have two moving parts you are trying to get right.

Put the switch on your sitemap so that you can easily see its state. You can also manually change it to test your garage door rule.

Once you have that you can regroup on making the day/night switch work.

I would add logging to your daylight switch rules to catch when they switch. Understanding that the rule for daylight will take patience to wait for it to trigger.

I’m away today but can help you dig in better tomorrow if you need.

Thanks @Moxified

Great idea on the switch, I should have thought of that…

I added one to the sitemap, and it seems to make no difference when toggled ON or OFF. The INFO message seems to still think it is daylight outside… I even tried changing the trigger in the rule to "daylight "as such:

//Test Rule for Garage Entry Timer

rule "Garage Light on Door Open"
when
 Item ZONE2_GENERAL_STATUS changed from CLOSED to OPEN
then
 if (daylight == OFF) { //if night do stuff
   logInfo("Garage Light on Door Open", "Its Night, do stuff")
   if (Light_Outdoor_Garage == 0) { //if light is off, start a timer and turn it on
    logInfo("Garage Light on Door Open", "Light was off, do stuff")
     createTimer(now.plusMinutes(10)) [|
       sendCommand(Light_Outdoor_Garage, "0")
       logInfo("Garage Light on Door Open", "Timer over, turned light off")
     ]
     sendCommand(Light_Outdoor_Garage, "50")
   } else logInfo("Garage Light on Door Open", "light was already on do nothing")
 } else logInfo("Garage Light on Door Open", "Its day, do nothing")
end

Sitemap:

Frame label="Sunset Switch" {
Switch item=daylight

}

The Astro binding works as I also created a sitemap text item to show sunrise / sunset, and it reports back fine with the correct info.

I’m sorry I wish I could see what the error was.

Thanks very much for the help!

Still on my iPhone so bare with me. You need to add .state to those rules. I didn’t notice that before.

rule "Garage Light on Door Open"
when
Item ZONE2_GENERAL_STATUS changed from CLOSED to OPEN
then
if (daylight.state == OFF) { //if night do stuff
logInfo(“Garage Light on Door Open”, “Its Night, do stuff”)
if (Light_Outdoor_Garage.state == 0) { //if light is off, start a timer and turn it on
logInfo(“Garage Light on Door Open”, “Light was off, do stuff”)
createTimer(now.plusMinutes(10)) [|
sendCommand(Light_Outdoor_Garage, “0”)
logInfo(“Garage Light on Door Open”, “Timer over, turned light off”)
]
sendCommand(Light_Outdoor_Garage, “50”)
} else logInfo(“Garage Light on Door Open”, “light was already on do nothing”)
} else logInfo(“Garage Light on Door Open”, “Its day, do nothing”)
end

Hello @Moxified

Can’t thank you enough for that great insight!!! It works like a charm! Actually even better than envisioned!!! :slight_smile: The .state made all the difference and got the rule running! Thank you so VERY much for your help with this! I hope to understand rules more in depth in the future as I go through the wiki’s, and forums.

Really appreciate it! If anyone else has a similar question, all of the above code with Astro binding works perfectly!

1 Like

@Moxified Thanks again very much for the help earlier. Sorry to bother but I have been trying day / night combinations on this rule also, without success and my lack of rule knowledge is killing me. This is a rule for XBMC lighting that works great, I just don’t need it to trigger during the daytime, following the astro bindings above. Any idea how I can only trigger this rule after sunset?

//Rule for Kodi Great Room Play Pause Start*/
 
rule "Lights Dim / Come On when Play Starts / Stops"
when
Item Family_TV_State changed
then
var String state = Family_TV_State.state.toString()

if (state.lowerCase == "play") {
sendCommand(Light_GF_Living_Tables, "5")
sendCommand(Light_GF_Kitchen_Table, "5")
}	
if (state.lowerCase == "pause") {
sendCommand(Light_GF_Living_Tables, "60")
sendCommand(Light_GF_Kitchen_Table, "60")
}
if (state.lowerCase == "stop") {
sendCommand(Light_GF_Living_Tables, "60")
sendCommand(Light_GF_Kitchen_Table, "60")
}
end

//Rule for Kodi Great Room Play Pause End*/

Thanks all very much again!

I think all you need to do is add an if statement prior to your other code that checks the daylight.state again. I also added logging. Log log log so you can see what it is doing during development. You can always comment out/remove them later. Also, don’t forget the extra “}” at the end with an additional log line to close out your new if statement:

//Rule for Kodi Great Room Play Pause Start*/

rule "Lights Dim / Come On when Play Starts / Stops"
when
Item Family_TV_State changed
then
if (daylight.state == OFF) { //if night do stuff
logInfo(“Lights Dim / Come On when Play Starts / Stops”, “Its night, do stuff”)
var String state = Family_TV_State.state.toString()

if (state.lowerCase == “play”) {
sendCommand(Light_GF_Living_Tables, “5”)
sendCommand(Light_GF_Kitchen_Table, “5”)
}
if (state.lowerCase == “pause”) {
sendCommand(Light_GF_Living_Tables, “60”)
sendCommand(Light_GF_Kitchen_Table, “60”)
}
if (state.lowerCase == “stop”) {
sendCommand(Light_GF_Living_Tables, “60”)
sendCommand(Light_GF_Kitchen_Table, “60”)
}
end
} else logInfo(“Lights Dim / Come On when Play Starts / Stops”, “Its day, do nothing”)

//Rule for Kodi Great Room Play Pause End*/