Rule so No announcements between 9 and 23 o'clock (wake the whole house)

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 ) :slight_smile:

import java.text.SimpleDateFormat
import java.util.Map
import org.joda.datetime.DateTime
import org.openhab.model.script.actions.Timer

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

the thing :

Bridge mqtt:broker:mqttBroker [ host=“10.0.0.53”, secure=false] {

// zigbee_stor_bad
Thing topic zigbee_stor_bad “zigbee_stor_bad” (mqtt:broker:mqttBroker) @ “zigbee” {
Channels:
//Type contact : zigbee_stor_bad_contact “Contact” [ stateTopic = “zigbee2mqtt/zigbee_stor_bad/contact”, transformationPattern=“JS:js/openclose.js”]
Type switch : contact “Contact” [ stateTopic = “zigbee2mqtt/zigbee_stor_bad/contact”,off=“false”, on=“true” ]
Type number : voltage “Voltage” [ stateTopic = “zigbee2mqtt/zigbee_stor_bad/voltage” ]
Type number : battery “Battery” [ stateTopic = “zigbee2mqtt/zigbee_stor_bad/battery” ]
Type number : linkquality “Link quality” [ stateTopic = “zigbee2mqtt/zigbee_stor_bad/linkquality” ]
}
}

the item :

Group:Contact:OR(OPEN,CLOSED) alleVinduer “Døre er [MAP(onoff.map):%s]”

// “zigbee_stor_bad”
Switch zigbee_stor_badContact “zigbee_stor_bad [%s]” (alleVinduer) { channel=“mqtt:topic:mqttBroker:zigbee_stor_bad:contact” }
Number zigbee_stor_badVoltage "zigbee_stor_bad_Voltage Voltage [%d mV] " { channel=“mqtt:topic:mqttBroker:zigbee_stor_bad:voltage” }
Number zigbee_stor_badBattery "zigbee_stor_bad_Battery Batterij [%.1f %%] " { channel=“mqtt:topic:mqttBroker:zigbee_stor_bad:battery” }
Number zigbee_stor_badLinkquality { channel=“mqtt:topic:mqttBroker:zigbee_stor_bad:linkquality” }

the sitemap :

sitemap zigbee label=“–zigbee–”
{
Frame label=“zigbee” {
Text label=“zigbee” icon=“lamps” {

Frame label="zigbee_stor_bad" icon="button" {	

//Text item=zigbee_stor_badContact icon=switch
Switch item=zigbee_stor_badContact icon=switch label=“zigbee_stor_bad : [%s]” mappings=[ON=“Lukket”, OFF=“AAben”] valuecolor=[==OFF=“#f8a9ad”, ==ON=“#a9f7b8”]
Text item=zigbee_stor_badBattery icon=“battery” label=“Battery [%.0f %%]”
Text item=zigbee_stor_badVoltage icon=“battery” label=“Voltage [%.0f mV]”
Text item=zigbee_stor_badLinkquality icon=“qualityofservice” label=“Link quality [%.0f]”
}
}

I`m running
openHAB 2.5.12 Release Build

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?

sorry the 10 was from testing this morning it was the intention to say 23 like after the // says

and yes this is " what comes of copy-paste without understanding " but learning as goes nothing wrong whit that right ???

between 9 and 23 o’clock

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 :slight_smile:

import java.text.SimpleDateFormat
import java.util.Map
import org.joda.datetime.DateTime
import org.openhab.model.script.actions.Timer

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)
**> } **
> }

}
end

I have also tried , but no luck there either :frowning:

import java.text.SimpleDateFormat
import java.util.Map
import org.joda.datetime.DateTime
import org.openhab.model.script.actions.Timer

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

Okay, the way an if() works;

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.")
}

1 Like

I love simple ,thanks a lot . :slight_smile: :smiley:

That’s exactly what i wanted