A SCENE THAT ONLY HAPPENS BETWEEN 10 PM AND 7 AM

I have tried to do the following that seems very simple but I simply can?t:

I want that when a door sensor is opened, the lights of a room turn on and a receive an e-mail alert. BUT I WANT THIS TO HAPPEN ONLY BETWEEN 10 PM and 6 AM and here is where I simply can?t find a clue.

Thanks in advance for your help

Create a scene which arms the sensor at 10 pm with a trigger which is sending an email when the armed sensor is tripped. Create another scene with a schedule at 7 am which disarms the sensor

Or use the PLEG plugin and:

  • Add a PLEG schedule that is true at 10pm and becomes false at 7am (name it: At_Night)

  • Add a PLEG trigger for the tripped door sensor (name it: Door_Opened)

  • Add a PLEG condition (name it: Lights_On): (Door_Opened AND At_Night)

  • Create a scene which turns your light(s) on and sends the email; add the PLEG device as a trigger (condition: Lights_On)

I used this script for something similar:

local currentHour = os.date('*t').hour
if (7 <= currentHour) and (currentHour < 22) then
  return true
else
  return false
end

I think you need something like:

local currentHour = os.date('*t').hour
return (7 > currentHour) or (currentHour >= 22)

or:

local currentHour = os.date('*t').hour
if (7 <= currentHour) and (currentHour < 22) then
  return false
else
  return true
end