Module: OpenHAB::Core::Actions

Included in:
DSL
Defined in:
lib/openhab/core/actions.rb,
lib/openhab/core/actions/exec.rb,
lib/openhab/core/actions/http.rb,
lib/openhab/core/actions/ping.rb,
lib/openhab/core/actions/audio.rb,
lib/openhab/core/actions/voice.rb,
lib/openhab/core/actions/ephemeris.rb,
lib/openhab/core/actions/transformation.rb

Overview

Access to global actions.

All openHAB's actions including those provided by add-ons are available, notably:

From add-ons, e.g.:

Thing-specific actions can be accessed from the Thing object. See Thing#actions.

Defined Under Namespace

Classes: Audio, Ephemeris, Exec, HTTP, Ping, Transformation, Voice

Class Method Summary collapse

Class Method Details

.notify(msg, email: nil, icon: nil, severity: nil, title: nil, on_click: nil, attachment: nil, buttons: nil) ⇒ void

Note:

The parameters title, on_click, attachment, and buttons were added in openHAB 4.2.

This method returns an undefined value.

Send a notification using openHAB Cloud Notification Action.

Examples:

Send a broadcast notification via openHAB Cloud

rule "Send an alert" do
  changed Alarm_Triggered, to: ON
  run { notify "Red Alert!" }
end

Provide action buttons in a notification

rule "Doorbell" do
  changed Doorbell, to: ON
  run do
    notify "Someone pressed the doorbell!",
      title: "Doorbell",
      attachment: "http://myserver.local/cameras/frontdoor.jpg",
      buttons: {
        "Show Camera" => "ui:/basicui/app?w=0001&sitemap=cameras",
        "Unlock Door" => "command:FrontDoor_Lock:OFF"
      }
  end
end

Parameters:

  • msg (String)

    The message to send.

  • email (String, nil) (defaults to: nil)

    The email address to send to. If nil, the message will be broadcast.

  • icon (String, Symbol, nil) (defaults to: nil)

    The icon name (as described in Items).

  • severity (String, Symbol, nil) (defaults to: nil)

    A description of the severity of the incident.

  • title (String, nil) (defaults to: nil)

    The title of the notification. When nil, it defaults to openHAB inside the Android and iOS apps.

  • on_click (String, nil) (defaults to: nil)

    The action to be performed when the user clicks on the notification. Specified using the action syntax.

  • attachment (String, nil) (defaults to: nil)

    The URL of the media attachment to be displayed with the notification. This URL must be reachable by the push notification client.

  • buttons (Array<String>, Hash<String, String>, nil) (defaults to: nil)

    Buttons to include in the notification.

    • In array form, each element is specified as Title=$action, where $action follows the action syntax.
    • In hash form, the keys are the button titles and the values are the actions.

    The maximum number of buttons is 3.

See Also:



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
# File 'lib/openhab/core/actions.rb', line 101

def notify(
  msg,
  email: nil,
  icon: nil,
  severity: nil,
  title: nil,
  on_click: nil,
  attachment: nil,
  buttons: nil
)
  unless Actions.const_defined?(:NotificationAction)
    raise NotImplementedError, "NotificationAction is not available. Please install the openHAB Cloud addon."
  end

  args = []
  if email
    args.push(:send_notification, email)
  else
    args.push(:send_broadcast_notification)
  end
  args.push(msg.to_s, icon&.to_s, severity&.to_s)

  # @!deprecated OH 4.1
  if Core.version >= Core::V4_2
    buttons ||= []
    buttons = buttons.map { |title, action| "#{title}=#{action}" } if buttons.is_a?(Hash)
    raise ArgumentError, "buttons must contain (0..3) elements." unless (0..3).cover?(buttons.size)

    args.push(title&.to_s, on_click&.to_s, attachment&.to_s, buttons[0]&.to_s, buttons[1]&.to_s, buttons[2]&.to_s)
  end

  NotificationAction.__send__(*args)
end