@vzorglub seems we recently discussed this in a different topic. For this rule your absolutely correct the , keeps it clean, as this is more than one line. Nice work Vincent!
We can probably remove about 15 lines on code from this rule by extracting the minutes value, parsing it into an int and get rid of the second switch case
Apology OP. @vzorglub Since your here---- ferrite beads, ferrite beads!!! The leads at the esp were longer than I remembered, about 6", snapped on a ferrite bead and good so far.
Rule "Garage Door Sensor changed"
when
Item garageDoorContact changed from CLOSED to OPEN
then
logInfo("Garage Door contact changed" + triggeringItem.state.toString)
sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)
if (triggeringItem.state == OPEN) {
GarageDoor_Timer.sendCommand(ON) // Start timer
sendBroadcastNotification(" Garage Door OPEN ")
} else {
GarageDoor_Timer.postUpdate(OFF) // Cancel timer
}
end
Error
2019-01-23 06:48:56.584 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garage Door Sensor changed': An error occurred during the script execution: index=1, size=1
First rule not Rule
Second your rule makes no sense triggeringItem.state will ALWAYS be OPEN because that’s how you trigger the rule:
rule "Garage Door Sensor changed"
when
Item garageDoorContact changed
then
if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return; //Invalid state: Do nothing
logInfo("Garage Door contact changed" + triggeringItem.state.toString)
sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)
if (triggeringItem.state == OPEN) {
GarageDoor_Timer.sendCommand(ON) // Start timer
} else {
GarageDoor_Timer.postUpdate(OFF) // resets the timer
end
rule "Garage door timer expired"
when
GarageDoor_Timer received command OFF
then
sendBoradcastNotification"Garage door it still open after 10m")
end
I tried your changes and I got the following error?
New rule
rule "Garage Door Sensor changed"
when
Item garageDoorContact changed
then
if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return; //Invalid state: Do nothing
logInfo("Garage Door contact changed" + triggeringItem.state.toString)
sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)
if (triggeringItem.state == OPEN) {
GarageDoor_Timer.sendCommand(ON) // Start timer
} else {
GarageDoor_Timer.postUpdate(OFF) // resets the timer
}
end
rule "Garage door timer expired"
when
GarageDoor_Timer received command OFF // this is 332
then
sendBoradcastNotification("Garage door it still open after 10m")
end
Error
2019-01-23 09:45:46.217 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'our_house.rules' has errors, therefore ignoring it: [332,5]: no viable alternative at input 'GarageDoor_Timer'
rule "Garage door timer expired"
when
Item GarageDoor_Timer received command OFF // this is 332
then
sendBoradcastNotification("Garage door it still open after 10m")
end
2019-01-23 11:35:51.156 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garage Door Sensor changed': An error occurred during the script execution: index=1, size=1
and the close error?
2019-01-23 11:36:32.156 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garage Door Sensor changed': An error occurred during the script execution: index=1, size=1
for the following
rule "Garage Door Sensor changed"
when
Item garageDoorContact changed
then
if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return; //Invalid state: Do nothing
logInfo("Garage Door contact changed" + triggeringItem.state.toString)
sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)
if (triggeringItem.state == OPEN) {
GarageDoor_Timer.sendCommand(ON) // Start timer
} else {
GarageDoor_Timer.postUpdate(OFF) // resets the timer
}
end
rule "Garage door timer expired"
when
Item GarageDoor_Timer received command OFF
then
logInfo("Garage Door ", " Opened for 10 min.")
sendBoradcastNotification("Garage door it still open after 10m")
end
2019-01-23 11:55:35.693 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garage Door Sensor changed': An error occurred during the script execution: index=1, size=1
With this?
rule "Garage Door Sensor changed"
when
Item garageDoorContact changed
then
logInfo("Garage Door contact changed - Then")
if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return; //Invalid state: Do nothing
logInfo("Garage Door contact changed" + triggeringItem.state.toString)
sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)
if (triggeringItem.state == OPEN) {
GarageDoor_Timer.sendCommand(ON) // Start timer
} else {
GarageDoor_Timer.postUpdate(OFF) // resets the timer
}
end
rule "Garage door timer expired"
when
Item GarageDoor_Timer received command OFF
then
logInfo("Garage Door ", " Opened for 10 min.")
sendBoradcastNotification("Garage door it still open after 10m")
end