Class: OpenHAB::Core::Items::DimmerItem

Inherits:
SwitchItem show all
Includes:
NumericItem
Defined in:
lib/openhab/core/items/dimmer_item.rb

Overview

A DimmerItem can be used as a switch (ON/OFF), but it also accepts percent values to reflect the dimmed state.

Examples:

DimmerOne << DimmerOne.state - 5
DimmerOne << 100 - DimmerOne.state

Turn on all dimmers in group

Dimmers.members.each(&:on)

Turn off all dimmers in group

Dimmers.members.each(&:off)

Turn on switches that are off

Dimmers.select(&:off?).each(&:on)

Turn off switches that are on

Dimmers.select(&:on?).each(&:off)

Dimmers can be selected in an enumerable with grep.

items.grep(DimmerItem)
     .each { |dimmer| logger.info("#{dimmer.name} is a Dimmer") }

Dimmers can also be used in case statements with ranges.

items.grep(DimmerItem)
     .each do |dimmer|
  case dimmer.state
  when (0..50)
    logger.info("#{dimmer.name} is less than 50%")
  when (51..100)
    logger.info("#{dimmer.name} is greater than 50%")
  end
end
rule 'Dim a switch on system startup over 100 seconds' do
  on_load
  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_load
  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)
         .select { |i| (1...50).cover?(i.state) }
         .each(&:off)
    end
end

Direct Known Subclasses

ColorItem

Constant Summary

Constants included from Semantics

Semantics::Equipment, Semantics::Location, Semantics::Point, Semantics::Property, Semantics::Tag

Instance Attribute Summary collapse

Attributes inherited from GenericItem

#category, #formatted_state, #label, #name, #raw_state, #tags

Attributes included from Semantics

#equipment, #equipment_type, #location, #location_type, #point_type, #property_type, #semantic_type

Attributes included from Item

#accepted_command_types, #accepted_data_types, #all_groups, #channel, #channel_uid, #channel_uids, #channels, #groups, #links, #metadata, #name, #provider, #thing, #things

Instance Method Summary collapse

Methods inherited from SwitchItem

#off, #off!, #off?, #on, #on!, #on?, #toggle

Methods inherited from GenericItem

#command, #modify, #null?, #refresh, #state?, #time_series=, #undef?, #update

Methods included from Semantics

add, #equipment?, #location?, lookup, #point?, #points, remove, #semantic?, tags

Methods included from Item

#color_item?, #contact_item?, #date_time_item?, #dimmer_item?, #group_item?, #image_item?, #inspect, #link, #location_item?, #member_of?, #number_item?, #player_item?, #rollershutter_item?, #string_item?, #switch_item?, #tagged?, #to_s, #unlink

Methods included from DSL::Items::TimedCommand

#command

Methods included from Persistence

#average_between, #average_since, #changed_between?, #changed_since?, #count_between, #count_since, #count_state_changes_between, #count_state_changes_since, #delta_between, #delta_since, #deviation_between, #deviation_since, #evolution_rate, #historic_state, #last_update, #maximum_between, #maximum_since, #minimum_between, #minimum_since, #persist, #previous_state, #sum_between, #sum_since, #updated_between?, #updated_since?, #variance_between, #variance_since

Methods included from DSL::Items::Ensure::Ensurable

#ensure

Instance Attribute Details

#statePercentType? (readonly)

Returns:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/openhab/core/items/dimmer_item.rb', line 87

class DimmerItem < SwitchItem
  include NumericItem

  #
  # Dim the dimmer
  #
  # @param [Integer] amount to dim by
  #  If 1 is the amount, the DECREASE command is sent, otherwise the
  #  current state - amount is sent as a command.
  #
  # @return [Integer] level target for dimmer
  #
  # @example
  #   DimmerOne.dim
  #   DimmerOne.dim(2)
  #
  def dim(amount = 1)
    target = [state&.-(amount), 0].compact.max
    command!(target)
    target
  end

  #
  # Brighten the dimmer
  #
  # @param [Integer] amount to brighten by
  #   If 1 is the amount, the INCREASE command is sent, otherwise the
  # current state + amount is sent as a command.
  #
  # @return [Integer] level target for dimmer
  #
  # @example
  #   DimmerOne.brighten
  #   DimmerOne.brighten(2)
  #
  def brighten(amount = 1)
    target = [state&.+(amount), 100].compact.min
    command!(target)
    target
  end

  # @!method increase
  #   Send the {INCREASE} command to the item
  #   @return [DimmerItem] `self`

  # @!method decrease
  #   Send the {DECREASE} command to the item
  #   @return [DimmerItem] `self`

  # raw numbers translate directly to PercentType, not a DecimalType
  # @!visibility private
  def format_type(command)
    return Types::PercentType.new(command) if command.is_a?(Numeric)

    super
  end
end

Instance Method Details

#brighten(amount = 1) ⇒ Integer

Brighten the dimmer

current state + amount is sent as a command.

Examples:

DimmerOne.brighten
DimmerOne.brighten(2)

Parameters:

  • amount (Integer) (defaults to: 1)

    to brighten by If 1 is the amount, the INCREASE command is sent, otherwise the

Returns:

  • (Integer)

    level target for dimmer



122
123
124
125
126
# File 'lib/openhab/core/items/dimmer_item.rb', line 122

def brighten(amount = 1)
  target = [state&.+(amount), 100].compact.min
  command!(target)
  target
end

#decreaseDimmerItem

Send the DECREASE command to the item

Returns:



# File 'lib/openhab/core/items/dimmer_item.rb', line 132

#dim(amount = 1) ⇒ Integer

Dim the dimmer

Examples:

DimmerOne.dim
DimmerOne.dim(2)

Parameters:

  • amount (Integer) (defaults to: 1)

    to dim by If 1 is the amount, the DECREASE command is sent, otherwise the current state - amount is sent as a command.

Returns:

  • (Integer)

    level target for dimmer



103
104
105
106
107
# File 'lib/openhab/core/items/dimmer_item.rb', line 103

def dim(amount = 1)
  target = [state&.-(amount), 0].compact.max
  command!(target)
  target
end

#increaseDimmerItem

Send the INCREASE command to the item

Returns:



# File 'lib/openhab/core/items/dimmer_item.rb', line 128