I have a simple rule that switches my Nest Thermostat to ‘Away’ if one of my main doors is open.
I would like to improve the rule so that a door must have been open for at least 10 seconds before it switches the Nest to Away.
Can anyone point me in the right direction?
Here is the current rule;
rule "Back Door Open Heating to Eco"
when
Item gMainDoors changed
then
if (gMainDoors.state == OPEN)
{NestTStat_away_mode.sendCommand("AWAY")}
else
{NestTStat_away_mode.sendCommand("HOME")}
end
var Timer timer = null
rule "gMainDoorsn CLOSED"
when
Item gMainDoors changed to CLOSED
then
if(timer !== null) {
timer.cancel()
timer = null}
end
rule "gMainDoors OPEN"
when
Item gMainDoors changed to OPEN
then
if(timer === null) {
timer = createTimer(now.plusSeconds(10)) [|
NestTStat_away_mode.sendCommand("AWAY")
timer = null]}
else
{NestTStat_away_mode.sendCommand("HOME")}
end
I’m needing to return to this. I created Harry’s rule (Many thanks Harry). It does switch the Nest Thermostat to ‘AWAY’ if the front or back door is open for longer than 10 seconds but it does not seem to be changing back to ‘HOME’ once the open door has been closed.
Here is the log for the door being open;
2018-09-13 10:45:25.678 [GroupItemStateChangedEvent] - gMainDoors changed from CLOSED to OPEN through Security_Door_Back
2018-09-13 10:45:25.688 [GroupItemStateChangedEvent] - gContact changed from CLOSED to OPEN through gMainDoors
2018-09-13 10:45:35.964 [ome.event.ItemCommandEvent] - Item 'NestTStat_away_mode' received command AWAY
2018-09-13 10:45:35.977 [nt.ItemStatePredictedEvent] - NestTStat_away_mode predicted to become AWAY
2018-09-13 10:45:35.986 [vent.ItemStateChangedEvent] - NestTStat_away_mode changed from Away to AWAY
and here is the log for the door being closed. Nothing concerning the Nest Thermostat is logged;
2018-09-13 10:46:27.829 [vent.ItemStateChangedEvent] - Security_Door_Back changed from OPEN to CLOSED
2018-09-13 10:46:27.835 [GroupItemStateChangedEvent] - gMainDoors changed from OPEN to CLOSED through Security_Door_Back
2018-09-13 10:46:27.842 [GroupItemStateChangedEvent] - gContact changed from OPEN to CLOSED through gMainDoors
The script is;
var Timer timer = null
rule "gMainDoors CLOSED"
when
Item gMainDoors changed from OPEN to CLOSED
then
if(timer !== null) {
timer.cancel()
timer = null}
end
rule "gMainDoors OPEN"
when
Item gMainDoors changed from CLOSED to OPEN
then
if(timer === null) {
timer = createTimer(now.plusSeconds(10)) [|
NestTStat_away_mode.sendCommand("AWAY")
timer = null]}
else
{NestTStat_away_mode.sendCommand("HOME")}
end
Any ideas as to why the thermostat is not being returned to ‘Home’ when the door is closed?
rule "gMainDoors CLOSED"
when
Item gMainDoors changed to CLOSED
then
if(timer !== null) {
timer.cancel()
timer = null}
NestTStat_away_mode.sendCommand("HOME")
end
var Timer timer = null
rule "gMainDoors CLOSED"
when
Item gMainDoors changed to CLOSED
then
if(timer !== null) {
timer.cancel()
timer = null}
NestTStat_away_mode.sendCommand("HOME")
end
rule "gMainDoors OPEN"
when
Item gMainDoors changed to OPEN
then
if(timer === null) {
timer = createTimer(now.plusSeconds(10)) [|
NestTStat_away_mode.sendCommand("AWAY")
timer = null]}
else
{NestTStat_away_mode.sendCommand("HOME")}
end
It is now sending the ‘HOME’ command but is doing it on every close and not just when the door has been open for 10 or more seconds.
It a busy house with a dog the constanly get let out to the garden so don’t want to go over the Nest threshold for sending commands.
Would this slight change work or should I test for the Thermostat being in the away mode.
rule "gMainDoors CLOSED"
when
Item gMainDoors changed to CLOSED
then
if(timer >= 10) {
timer.cancel()
timer = null}
NestTStat_away_mode.sendCommand("HOME")
end
EDIT: Just realised this wouldn’t reset the timer if it was not null but less than 10
So you don´t need to start/stop/reset timers. You only have an additional switch, which will auto switch to off, when the time is over. When the time is not over yet, you can switch it manually to off.
I think this is easier, but both ways are working.
Sorry for asking but my brain is not in rules mode…
I have a door with a contact
if contact has been open for 60 seconds or is closed before this cancel sending command
send a command to
Cromecast (pause)