Actions

Use Core & Cloud Actions

For ScriptExecution, see Use a timer. For LogAction, see LogAction.

from core.actions import Exec
Exec.executeCommandLine("/bin/sh@@-c@@/usr/bin/curl -s --connect-timeout 3 --max-time 3 http://host.example.com",5000)

from core.actions import HTTP
HTTP.sendHttpPutRequest("someURL.example.com, "application/json", '{"this": "that"}')

from core.actions import Ping
if Ping.checkVitality("10.5.5.5", 0, 5000):
    log.info("Server is online")
else:
    log.info("Server is offline")

from core.actions import Audio
Audio.playSound("doorbell.mp3")# using the default audiosink
Audio.playSound("my:audio:sink", "doorbell.mp3")# specifying an audiosink
Audio.playStream("http://myAudioServer.example.com/myAudioFile.mp3")# using the default audiosink
Audio.playStream("my:audio:sink", "http://myAudioServer.example.com/myAudioFile.mp3")# specifying an audiosink

from core.actions import NotificationAction
NotificationAction.sendNotification("someone@example.com","This is the message")
NotificationAction.sendBroadcastNotification("This is the message")
NotificationAction.sendLogNotification("This is the message")

from core.actions import Transformation
Transformation.transform("JSONPATH", "$.test", test)

from core.actions import Voice
Voice.say("This will be said")

from core.actions import Things
Things.getThingStatusInfo("zwave:device:c5155aa4:node5")
var OPENHAB_CONF = Java.type('java.lang.System').getenv('OPENHAB_CONF');
load(OPENHAB_CONF + '/automation/lib/javascript/core/actions.js');

Exec.executeCommandLine("/bin/sh@@-c@@/usr/bin/curl -s --connect-timeout 3 --max-time 3 http://host.example.com",5000);

HTTP.sendHttpPutRequest("someURL.example.com, "application/json", '{"this": "that"}');

if (Ping.checkVitality("10.5.5.5", 0, 5000)) {
    LogAction.logInfo("Rules", "Server is online");
} else {
    LogAction.logInfo("Rules", "Server is offline");
}

Audio.playSound("doorbell.mp3");// using the default audiosink
Audio.playSound("my:audio:sink", "doorbell.mp3");// specifying an audiosink
Audio.playStream("http://myAudioServer.example.com/myAudioFile.mp3");// using the default audiosink
Audio.playStream("my:audio:sink", "http://myAudioServer.example.com/myAudioFile.mp3");// specifying an audiosink

NotificationAction.sendNotification("someone@example.com", "This is the message");
NotificationAction.sendBroadcastNotification("This is the message");
NotificationAction.sendLogNotification("This is the message");

LogAction.logInfo("Rules", Transformation.transform("JSONPATH", "$.test", test));

Voice.say("This will be said");

LogAction.logInfo("Rules", Things.getThingStatusInfo("zwave:device:c5155aa4:node5").toString());
TODO
TODO

Persistence extensions

Others not listed are similar

from core.actions import PersistenceExtensions
PersistenceExtensions.previousState(ir.getItem("Weather_SolarRadiation"), True).state

from org.joda.time import DateTime
PersistenceExtensions.changedSince(ir.getItem("Weather_SolarRadiation"), DateTime.now().minusHours(1))
PersistenceExtensions.maximumSince(ir.getItem("Weather_SolarRadiation"), DateTime.now().minusHours(1)).state
var OPENHAB_CONF = Java.type('java.lang.System').getenv('OPENHAB_CONF');
load(OPENHAB_CONF + '/automation/lib/javascript/core/actions.js');

LogAction.logInfo("Rules", PersistenceExtensions.previousState(ir.getItem("Weather_SolarRadiation"), True).state.toString());

var DateTime = Java.type('org.joda.time.DateTime');

LogAction.logInfo("Rules", PersistenceExtensions.changedSince(ir.getItem("Weather_SolarRadiation"), DateTime.now().minusHours(1)));
LogAction.logInfo("Rules", PersistenceExtensions.maximumSince(ir.getItem("Weather_SolarRadiation"), DateTime.now().minusHours(1)).state.toString());
TODO
TODO

Use an Addon/Bundle Action

The binding or Action must be installed.

Telegram

from core.actions import Telegram
Telegram.sendTelegram("MyBot", "Test")

Mail

from core.actions import Mail
Mail.sendMail("someone@example.com", "This is the subject", "This is the message")

Astro

from core.actions import Astro
from core.log import logging, LOG_PREFIX
from java.util import Date

log = logging.getLogger("{}.astro_test".format(LOG_PREFIX))

# Use the Astro action to get the sunset start time.
log.info("Sunset: {}".format(Astro.getAstroSunsetStart(Date(2017, 7, 25), 38.897096, -77.036545).time))

MQTT2

# no import needed
actions.get("mqtt", "mqtt:systemBroker:embedded-mqtt-broker").publishMQTT("test/system/started", "true")

Telegram

var OPENHAB_CONF = Java.type('java.lang.System').getenv('OPENHAB_CONF');
load(OPENHAB_CONF + '/automation/lib/javascript/core/actions.js');

Telegram.sendTelegram("MyBot", "Test");

Mail

var OPENHAB_CONF = Java.type('java.lang.System').getenv('OPENHAB_CONF');
load(OPENHAB_CONF + '/automation/lib/javascript/core/actions.js');

Mail.sendMail("someone@example.com", "This is the subject", "This is the message");

Astro

var OPENHAB_CONF = Java.type('java.lang.System').getenv('OPENHAB_CONF');
load(OPENHAB_CONF + '/automation/lib/javascript/core/actions.js');

var Date = Java.type('java.util.Date')

// Use the Astro action to get the sunset start time.
LogAction.logInfo("Rules", "Sunset: {}".format(Astro.getAstroSunsetStart(Date(2017, 7, 25), 38.897096, -77.036545).time));

MQTT2

// no import needed
actions.get("mqtt", "mqtt:systemBroker:embedded-mqtt-broker").publishMQTT("test/system/started", "true");
TODO
TODO