states

Rule languages supports states processing

    • Given Clean OpenHAB with latest Ruby Libraries
    • And items:
      typenamelabelstate
      SwitchSwitch1Switch Number OneOFF
      SwitchSwitch2Switch Number TwoOFF
  • States can be stored and restored using store_states

    • Given code in a rules file:
      states = store_states Switch1, Switch2
      Switch1 << ON
      after(5.seconds) { states.restore }
    • When I deploy the rule
    • Then "Switch1" should be in state "ON" within 2 seconds
    • But If I wait 5 seconds
    • Then "Switch1" should be in state "OFF" within 2 seconds
  • States can be stored and restored using store_states block

    • Given code in a rules file:
      store_states Switch1, Switch2 do
        Switch1 << ON
        sleep 5
      end
    • When I start deploying the rule
    • Then "Switch1" should be in state "ON" within 2 seconds
    • But If I wait 5 seconds
    • Then "Switch1" should be in state "OFF" within 2 seconds
  • Check item states

    • Given code in a rules file:
      Switch1.update <state>
      sleep 0.5
      logger.info "All items have a valid state: #{state? Switch1, Switch2}"
    • When I start deploying the rule
    • Then It should log "All items have a valid state: <result>" within 3 seconds

    Examples:

    state result
    ON true
    UNDEF false
    NULL false
  • Check item states before executing a rule

    • Given code in a rules file:
      Switch1.update <state>
      sleep 0.5
      rule 'state check' do
        on_start
        only_if { state? Switch1, Switch2 }
        run { logger.info "All items have a valid state: true" }
        otherwise { logger.info "All items have a valid state: false" }
      end
    • When I deploy the rule
    • Then It should log "All items have a valid state: <result>" within 3 seconds

    Examples:

    state result
    ON true
    UNDEF false
    NULL false
  • Check item states and their thing status

    • Given feature 'openhab-binding-astro' installed
    • And things:
      idthing_uidlabelconfigstatus
      homeastro:sunAstro Sun Data{"geolocation":"0,0"}<state>
    • And items:
      typename
      NumberSun_Elevation
    • And linked:
      itemchannel
      Sun_Elevationastro:sun:home:position#elevation
    • And a rule:
      Sun_Elevation.update 0
      sleep 0.2
      logger.info "Sun_Elevation is valid? #{state? Sun_Elevation, things: true}"
    • When I deploy the rule
    • Then It should log "Sun_Elevation is valid? <result>" within 5 seconds

    Examples:

    state result
    enable true
    disable false