I’ve submitted a PR for a new feature for jruby helper libraries to do this.
It’s not yet merged / updated to the gem (look for version 5.0.0.rc11 or newer), but once it has, you could:
- Change your trigger to
ItemStateChangeTriggerand remove the “state: OPEN” condition, so that it triggers on any state change for the Door_State item.
configuration: {}
triggers:
- id: "1"
configuration:
itemName: Door_State
type: core.ItemStateChangeTrigger
- Install jruby automation + configure it with the helper library. The easy way to do this is by installing the jruby automation from the Marketplace.
- You would change your action to run a script, select Ruby script, and have this in your script:
debounce_for(1.minute) do
next unless event.state.open?
Voice.say("CLOSE THE DOOOOOOOR", sink: "enhancedjavasound")
end
Voila!
Here’s the full yaml for UI based rule:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: Door_State
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/x-ruby
script: |-
debounce_for(1.minute) do
next unless event.state.open?
Voice.say("CLOSE THE DOOOOOOOR", sink: "enhancedjavasound")
end
type: script.ScriptAction
Note that this is already supported in file-based rules in the current version of the helper library. The file based rule would look like this:
rule "Open door alert" do
changed Door_State, to: OPEN, for: 1.minute
run { Voice.say("CLOSE THE DOOOOOOOOR", sink: "enhancedjavasound") }
end