Skip to main content Link Search Menu Expand Document (external link)

DimmerItem

MethodParametersDescriptionExample
truthy? Item state not UNDEF, not NULL and is ONputs "#{item.name} is truthy" if item.truthy?
on Send command to turn item ONitem.on
off Send command to turn item OFFitem.off
on? Returns true if item state == ONputs "#{item.name} is on." if item.on?
off? Returns true if item state == OFFputs "#{item.name} is off." if item.off?
dimamount (default 1)Dim the dimmer the specified amountDimmerSwitch.dim
decrease Decrease brightness of the dimmerDimmerSwitch.decrease
-amountSubtract the supplied amount from DimmerItemDimmerSwitch << DimmerSwitch - 5
brightenamount (default 1)Brighten the dimmer the specified amountDimmerSwitch.brighten
increase Increase brightness of the dimmerDimmerSwitch.increase
+amountAdd the supplied amount from the DimmerItemDimmerSwitch << DimmerSwitch + 5
<=>DimmerItem, NumberItem, Number, StringCompare the value of DimmerItem against othersDimmerSwitch > 100

Examples

DimmerOne << DimmerOne - 5
DimmerOne << 100 - DimmerOne

on/off sends commands to a Dimmer

# Turn on all dimmers in group
Dimmers.each(&:on)

# Turn off all dimmers in group
Dimmers.each(&:off)

on?/off? Checks state of dimmer

# Turn on switches that are off
Dimmers.select(&:off?).each(&:on)

# Turn off switches that are on
Dimmers.select(&:on?).each(&:off)

dim dims the specified amount, defaulting to 1. If 1 is the amount, the decrease command is sent, otherwise the current state - amount is sent as a command.

DimmerOne.dim
DimmerOne.dim 2

brighten brightens the specified amount, defaulting to 1. If 1 is the amount, the increase command is sent, otherwise the current state + amount is sent as a command.

DimmerOne.brighten
DimmerOne.brighten 2   

Dimmers can be selected in an enumerable with grep.

# Get all dimmers
items.grep(DimmerItem)
     .each { |dimmer| logger.info("#{dimmer.id} is a Dimmer") }

Dimmers work with ranges and can be used in grep.

# Get dimmers with a state of less than 50
items.grep(DimmerItem)
     .grep(0...50)
     .each { |item| logger.info("#{item.id} is less than 50") }

Dimmers can also be used in case statements with ranges.

#Log dimmer states partioning aat 50%
items.grep(DimmerItem)
     .each do |dimmer|
       case dimmer
       when (0..50)
         logger.info("#{dimmer.id} is less than 50%")
        when (51..100)
         logger.info("#{dimmer.id} is greater than 50%")
         end
end

Other examples

rule 'Dim a switch on system startup over 100 seconds' do
  on_start
  100.times do
    run { DimmerSwitch.dim }
    delay 1.second
  end
end

rule 'Dim a switch on system startup by 5, pausing every second' do
   on_start
   100.step(-5, 0) do | level |
     run { DimmerSwitch << level }
     delay 1.second
   end
end
rule 'Turn off any dimmers curently on at midnight' do
   every :day
   run do
     items.grep(DimmerItem)
          .select(&:on?)
          .each(&:off)
    end
end
rule 'Turn off any dimmers set to less than 50 at midnight' do
   every :day
   run do
     items.grep(DimmerItem)
          .grep(1...50)
          .each(&:off)
     end
end