triggered

Automation is executed in triggered blocks

    • Given Clean OpenHAB with latest Ruby Libraries
  • rules have access to triggering item in triggered blocks

    • Given items:
      typenamelabelstate
      SwitchTestSwitchTest SwitchOFF
    • Given a deployed rule:
      rule 'Triggered has access directly to item triggered' do
        changed TestSwitch
        triggered { |item| logger.info("#{item.id} triggered") }
      end
    • When item "TestSwitch" state is changed to "ON"
    • Then It should log 'Test Switch triggered' within 5 seconds
  • Triggered item is item modified in group

    • Given group "Switches"
    • And items:
      typenamelabelstategroup
      SwitchSwitch1Switch Number OneOFFSwitches
      SwitchSwitch2Switch Number TwoOFFSwitches
    • And a deployed rule:
      rule 'Triggered item is item changed when a group item is changed.' do
        changed Switches.members
        triggered { |item| logger.info("Switch #{item.id} changed to #{item}")}
      end
    • When item "Switch1" state is changed to "ON"
    • Then It should log 'Switch Switch Number One changed to ON' within 5 seconds
  • Triggered supports pretzel colon (&:) operator

    • Given group "Switches"
    • And items:
      typenamelabelstategroup
      SwitchSwitch1Switch Number OneOFFSwitches
      SwitchSwitch2Switch Number TwoOFFSwitches
    • And a deployed rule:
      rule 'Turn off any switch that changes' do
        changed Switches.members
        triggered(&:off)
      end
    • When item "Switch1" state is changed to "ON"
    • And if I wait 1 seconds
    • Then "Switch1" should be in state "OFF" within 5 seconds
  • Multiple triggers in a rule

    • Given group "Switches"
    • And items:
      typenamelabelstategroup
      SwitchSwitch1Switch Number OneOFFSwitches
      SwitchSwitch2Switch Number TwoOFFSwitches
    • And a deployed rule:
      rule 'Turn a switch off and log it, 5 seconds after turning it on' do
        changed Switches.members, to: ON
        delay 5.seconds
        triggered(&:off)
        triggered {|item| logger.info("#{item.label} turned off") }
      end
    • When item "Switch1" state is changed to "ON"
    • And if I wait 1 seconds
    • Then "Switch1" should be in state "OFF" within 6 seconds
    • And It should log 'Switch Number One turned off' within 5 seconds