I have a that turns the heating off if one of the main doors is open for more than 20 seconds and then turns the heating back on when the door is closed.
It also has Amazon Alexa announce the heating being turned off and on.
This used to work fine, but has now started to have Alexa announce that the heating has been turned on every time the door is closed.
The 20 second ‘Heating turned off’ still works correctly.
The rule is below, can someone advise what has changed to cause this?
Many thanks.
var Timer timer = null
rule "gMainDoors CLOSED"
when
Item gMainDoors changed to CLOSED
then
if(timer !== null) {
timer.cancel()
timer = null}
if(NestTStat_away_mode.state == "HOME") return;
NestTStat_away_mode.sendCommand("HOME")
Echo_Living_Room_TTS.sendCommand('Heating turned on')
end
rule "gMainDoors OPEN"
when
Item gMainDoors changed to OPEN
then
if(timer === null) {
timer = createTimer(now.plusSeconds(20)) [|
NestTStat_away_mode.sendCommand("AWAY")
Echo_Living_Room_TTS.sendCommand('Heating turned off')
timer = null]}
else
{NestTStat_away_mode.sendCommand("HOME")}
end
I think that is a potential trap. If you ever add another rule with a timer,be very careful not to use the same variable name. I’d use something like doorsTimer to avoid later problems.
If your rule is getting past that line when you don’t expect it, you probably want to investigate by logging out the actual state using logInfo() before the if() test.
2020-01-31 11:38:33.820 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'gMainDoors CLOSED': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null
Okay, logInfo requires two strings at its simplest. You can of course build up strings from parts. Your gMainDoors Item is not a string. Your timer variable is not a string.
I have no idea why you are looking at timer at all. You’ve just set it to null. You know its null. It has no bearing on whether the heating-on code is executed or not.
The gateway if() toyour heating-on code is controlled by an Item state. I thinkit would be useful to know that Item state?
logInfo("test" , "Item state " + NestTStat_away_mode.state.toString)
==> /var/log/openhab2/events.log <==
2020-01-31 12:06:22.211 [GroupItemStateChangedEvent] - gMainDoors changed from CLOSED to OPEN through Security_Door_Back
2020-01-31 12:06:22.222 [vent.ItemStateChangedEvent] - Security_Door_Back changed from CLOSED to OPEN
2020-01-31 12:06:22.247 [GroupItemStateChangedEvent] - gContact changed from CLOSED to OPEN through gMainDoors
2020-01-31 12:06:26.513 [GroupItemStateChangedEvent] - gMainDoors changed from OPEN to CLOSED through Security_Door_Back
2020-01-31 12:06:26.518 [GroupItemStateChangedEvent] - gContact changed from OPEN to CLOSED through gMainDoors
2020-01-31 12:06:26.524 [vent.ItemStateChangedEvent] - Security_Door_Back changed from OPEN to CLOSED
==> /var/log/openhab2/openhab.log <==
2020-01-31 12:06:26.526 [INFO ] [.eclipse.smarthome.model.script.test] - Item StateNULL
==> /var/log/openhab2/events.log <==
2020-01-31 12:06:26.584 [ome.event.ItemCommandEvent] - Item 'NestTStat_away_mode' received command HOME
2020-01-31 12:06:26.667 [ome.event.ItemCommandEvent] - Item 'Echo_Living_Room_TTS' received command Heating turned on
2020-01-31 12:06:26.676 [nt.ItemStatePredictedEvent] - NestTStat_away_mode predicted to become NULL
2020-01-31 12:06:26.681 [nt.ItemStatePredictedEvent] - Echo_Living_Room_TTS predicted to become Heating turned on
2020-01-31 12:06:26.709 [GroupItemStateChangedEvent] - gAlexa_TTS changed from to UNDEF through Echo_Living_Room_TTS
2020-01-31 12:06:26.714 [vent.ItemStateChangedEvent] - Echo_Living_Room_TTS changed from to Heating turned on
2020-01-31 12:06:28.444 [GroupItemStateChangedEvent] - gAlexa_TTS changed from UNDEF to through Echo_Living_Room_TTS
2020-01-31 12:06:28.457 [vent.ItemStateChangedEvent] - Echo_Living_Room_TTS changed from Heating turned on to
Here is your problem. Somehow NestTStat_away_mode.state is NULL (and thus not "HOME").
I think you have to find out why NestTStat_away_mode is NULL. Does the binding still works?