- Platform information:
- Hardware: Pi4B 4GB
- OS: openhabian Raspian/GNU Buster
- Java Runtime Environment: JDK 11
- openHAB 3.2 Release Version
- Issue of the topic: I made my first rule using Blockly to create a script. It is a simple rule, to turn off the bathroom exhaust fan after it runs for 3 minutes. The problem is that the timer keeps repeating and sends an off command to the fan’s power switch every 3 minutes. I’m sure I’m missing something really simple.
Here is the code from the Main UI Rule:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: MasterBathToiletFanMQTTThing_MasterBathToiletFanSwitch
type: core.ItemStateUpdateTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
type="oh_timer" id="k{{F^64m8/X:m~9nUH/=" x="183" y="-729"><field
name="delayUnits">plusMinutes</field><value name="delay"><shadow
type="math_number" id="{UJoh9Ng].z}6GoV1P=#"><field
name="NUM">3</field></shadow></value><value name="timerName"><shadow
type="text" id="C6zI/@u/aOTUBe,-Qm`1"><field
name="TEXT">MasterToiletFanTimer</field></shadow></value><statement
name="timerCode"><block type="oh_event" id="ey`lbnT4)Tl4NSTsqilL"><field
name="eventType">sendCommand</field><value name="value"><shadow
type="text" id="-Us@+~TACEKtnVl@~;{X"><field
name="TEXT">OFF</field></shadow></value><value name="itemName"><shadow
type="oh_item" id="WxuMRfoI`+CiUrhnk1MU"><field
name="itemName">MasterBathToiletFanMQTTThing_MasterBathToiletFanSwitch</field></shadow></value><next><block
type="oh_timer_cancel" id="mR!aQp:G?TWRXl8~mRMc"><value
name="timerName"><shadow type="text" id="qlYb{aO^:?!KpIia|(l{"><field
name="TEXT">MasterToiletFanTimer</field></shadow></value></block></next></block></statement></block></xml>
type: application/javascript
script: >
var scriptExecution =
Java.type('org.openhab.core.model.script.actions.ScriptExecution');
var zdt = Java.type('java.time.ZonedDateTime');
if (typeof this.timers === 'undefined') {
this.timers = [];
}
if (typeof this.timers['MasterToiletFanTimer'] === 'undefined' || this.timers['MasterToiletFanTimer'].hasTerminated()) {
this.timers['MasterToiletFanTimer'] = scriptExecution.createTimer(zdt.now().plusMinutes(3), function () {
events.sendCommand('MasterBathToiletFanMQTTThing_MasterBathToiletFanSwitch', 'OFF');
if (typeof this.timers['MasterToiletFanTimer'] !== 'undefined') {
this.timers['MasterToiletFanTimer'].cancel();
this.timers['MasterToiletFanTimer'] = undefined;
}
})
}
type: script.ScriptAction
Here is screenshot of the Blockly:
Thanks for any suggestions.