Hello .
I will like to implement in a rule that Alexa echo dont wake the whole house just because a door or window is or get open at night. I have the rule working without this now ,but i cant find out how to ,and if a window is all ready open before 23 the announcements just have to be stopped too and then begin again in the morning.
I have this from another rule and i have tried various ways and combination but no luck can anybody help ?
{
if(now.getHourOfDay > 9 && now.getHourOfDay < 23 ) //but only between KL.9 and KL.23
{
logInfo(“alleVinduer”, "alleVinduer tilladt tidsrum: its between 9 and 23: " + now.getHourOfDay)
}
else
{
logInfo(“alleVinduer”, "alleVinduer ikke tilladt tidsrum: its NOT between 9 and 23: " + now.getHourOfDay)
}
}
THE RULE : ( WORKING RULE AND ALEXA GOES ON ALL NIGHT )
rule “member of group alleVinduer open”
when
Member of alleVinduer changed from ON to OFF
then
val Number TimerLength = 20 //Tiden til første meddelelse
val Number TimerReschedule = 20 //Tiden til næste besked.
if (Season_Name.state==“SUMMER”) {
timers.get(triggeringItem.name)?.cancel
timers.remove(triggeringItem.name)
logInfo(“Test”, “The timer gets canceled because current season is summer”)
return;
}
else {
logInfo(“Test”, “New timer created for: " + transform(“MAP”, “windows.map”, triggeringItem.name))
var elapsedTime = 20 //must be the same as TimerLength
timers.put(triggeringItem.name, createTimer(now.plusMinutes(TimerLength.intValue), [|
val String longName = transform(“MAP”, “windowLongName.map”, triggeringItem.name.toString)
logInfo(“Test”, transform(“MAP”, “windows.map”, triggeringItem.name) + " have been " + elapsedTime + " minuts open.”)
Echo_Living_Room_TTS.sendCommand("hey there please be aware that " + longName + “has been” + elapsedTime + “minuts open please close it right now please.”)
elapsedTime = elapsedTime + TimerReschedule
timers.get(triggeringItem.name).reschedule(now.plusMinutes(TimerReschedule)) // the time to say gets renewed
]))
}
end
I guess this what comes of copy-paste without understanding.
I cannot think of a number that is more than 9 and less than 10 at the same moment.
What are you actually trying to do here, is it like the comment? Why wouldn’t you use >8 and <23 for 0900 to 2259?
Well,now you’ve (nearly) fixed that, what is the problem?
I say nearly, because that will be true from 10:00 to 22:59.
To be as comment, you’s want >8 and <23
Up until 09:59, the hour of day is not more than 9
i dont want Echo to say anything from x to y the numbers are not the problem i do know the time it is the announcements thats the problem , i just dont know have to put the code in the rule.
Like this but it gives error that i cant solve being that im not a coder ,just a simple user
rule “member of group alleVinduer open”
when
Member of alleVinduer changed from ON to OFF
then
val Number TimerLength = 20 //Time to first message
val Number TimerReschedule = 20 //Time to between messages
if (Season_Name.state==“SUMMER”) {
timers.get(triggeringItem.name)?.cancel
timers.remove(triggeringItem.name)
logInfo(“Test”, “The timer gets canceled because current season is summer”)
return;
}
else {
logInfo(“Test”, “New timer created for: " + transform(“MAP”, “windows.map”, triggeringItem.name))
var elapsedTime = 20 //must be the same as TimerLength
timers.put(triggeringItem.name, createTimer(now.plusMinutes(TimerLength.intValue), [|
val String longName = transform(“MAP”, “windowLongName.map”, triggeringItem.name.toString)
logInfo(“Test”, transform(“MAP”, “windows.map”, triggeringItem.name) + " have been " + elapsedTime + " minuts open.”)
//
//
//
//
//
> { > if(now.getHourOfDay > 9 && now.getHourOfDay < 10 ) //but only between .9 and 23 > { > logInfo(“alleVinduer”, "alleVinduer permitted period: its between 9 and 23: " + now.getHourOfDay) > }
//
//
//
//
//
//
//
Echo_Living_Room_TTS.sendCommand("hey there please be aware that " + longName + “has been” + elapsedTime + “minuts open please close it right now please.”)
elapsedTime = elapsedTime + TimerReschedule
timers.get(triggeringItem.name).reschedule(now.plusMinutes(TimerReschedule)) // the time to say gets renewed
]))
//
//
//
// else > { > logInfo(“alleVinduer”, "alleVinduer not allowed: its NOT between 9 and 23: " + now.getHourOfDay) > timers.get(triggeringItem.name)?.cancel > timers.remove(triggeringItem.name)
**> } ** > }
rule “member of group alleVinduer ope”
when
Member of alleVinduer changed from ON to OFF
then
val Number TimerLength = 20 //Time to first message
val Number TimerReschedule = 20 //Time to between messages
if (Season_Name.state==“SUMMER”) OR (now.getHourOfDay() >9 && now.getHourOfDay() <23) {
timers.get(triggeringItem.name)?.cancel
timers.remove(triggeringItem.name)
logInfo(“Test”, “The timer gets canceled because current season is summer”)
return;
}
else {
logInfo(“Test”, “New timer created for: " + transform(“MAP”, “windows.map”, triggeringItem.name))
var elapsedTime = 20 //must be the same as TimerLength
timers.put(triggeringItem.name, createTimer(now.plusMinutes(TimerLength.intValue), [|
val String longName = transform(“MAP”, “windowLongName.map”, triggeringItem.name.toString)
logInfo(“Test”, transform(“MAP”, “windows.map”, triggeringItem.name) + " have been " + elapsedTime + " minutes open.”)
{
if(now.getHourOfDay > 9 && now.getHourOfDay < 23 ) //but only between KL.9 and KL.23
{
logInfo(“alleVinduer”, " alleVinduer permitted period: its between 9 and 23: " +now.getHourOfDay)
}
Echo_Living_Room_TTS.sendCommand("hey there please be aware that " + longName + “has been” + elapsedTime + “minuts open please close it right now please.”)
elapsedTime = elapsedTime + TimerReschedule
timers.get(triggeringItem.name).reschedule(now.plusMinutes(TimerReschedule)) // the time to say gets renewed
])) > else > { > logInfo(“alleVinduer”, " alleVinduer not allowed: its NOT between 9 and 23: " + now.getHourOfDay) > timers.get(triggeringItem.name)?.cancel > timers.remove(triggeringItem.name)
**> } ** > }
**> ** > }
end
if (condition) {
then do something
}
do something else
if condition is true, “something” gets done.
Whether its true or not,“something else” gets done.
if() only controls the part in { }.
So you want to not make an announcement overnight.
You can write lots of complicated code that works out if you are going to schedule a message during a quiet period, and if so doesn’t schedule it.
Or you might just do the simple way - let everything work exactly as it does now,just don’t make the voice messages during the quiet period.
Replace
Echo_Living_Room_TTS.sendCommand("hey there please be aware that " + longName + "has been" + elapsedTime + "minuts open please close it right now please.")
with
if (now.getHourOfDay > 8 && now.getHourOfDay < 23 ) { // after 0900 and before 22:59
Echo_Living_Room_TTS.sendCommand("hey there please be aware that " + longName + "has been" + elapsedTime + "minuts open please close it right now please.")
}