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/rspec/openhab/core/actions.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) ⇒ void

This method returns an undefined value.

Send a notification.

Examples:

Send a broadcast notification via openHAB Cloud

rule 'Send an alert' do
  changed Alarm_Triggered, to: ON
  run { notify 'Red Alert!' }
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)
  • severity (String, Symbol, nil)


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/openhab/core/actions.rb', line 69

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

  if email
    NotificationAction.send_notification(email.to_s, msg.to_s, icon&.to_s, severity&.to_s)
  else
    NotificationAction.send_broadcast_notification(msg.to_s, icon&.to_s, severity&.to_s)
  end
end