Trigger rule via datetime item

Dear all,
i do have a datetime item of my next upcoming amazon echo alarm.
At the time of the alarm i want to trigger a sunrise light routine rule.
However, i dont know how to fire the rule at the value time of the datetime item (2021-10-26T06:15:00.000+0200).

Can someone give me a hint?
Do i need an additional rule for that?

Thank you a lot!

I have a rule (ECMA) that triggers on each change of the next alarm in order to switch on my hotwater.

var logger = Java.type(‘org.slf4j.LoggerFactory’).getLogger(‘org.openhab.rule.’ + ctx.ruleUID);
var ScriptExecution = Java.type(“org.openhab.core.model.script.actions.ScriptExecution”);
var ZonedDateTime = Java.type(“java.time.ZonedDateTime”);
var ZoneId = Java.type(“java.time.ZoneId”);
var Instant=Java.type(“java.time.Instant”);
= (this.OPENHAB_CONF === undefined) ? java.lang.System.getenv(“OPENHAB_CONF”) : this.OPENHAB_CONF;
load(OPENHAB_CONF+’/automation/lib/javascript/community/timeUtils.js’);
//var Exec = Java.type(“org.openhab.core.model.script.actions.Exec”);
//var timerAlarm;
this.timerAlarm = (this.timerAlarm === undefined) ? null: this.timerAlarm;
var AlarmTime =items[‘NaechsterAlarm’];
//var WarmWasserSollTemperature = items[‘WarmWasserSollTemperatur’];
logger.info(“AlarmTime: {}”, AlarmTime);
try {
if (AlarmTime == UNDEF) {
if (this.timerAlarm != undefined) {
this.timerAlarm.cancel;
this.timerAlarm = undefined;
}
events.postUpdate(‘Naechster_Alarm’,UNDEF);
logger.info(“All alarms are canceled”);
} else {
var epoch = AlarmTime - 600000; // 10 Minuten vorher!!
logger.info("Scheduling Alarm for: "+ epoch);
var zdt=Instant.ofEpochMilli(epoch).atZone(ZoneId.systemDefault());
logger.info ("Converted AlarmTime: " + zdt);
events.postUpdate(‘Naechster_Alarm’,epoch);
if (timerAlarm !== null) {
logger.info(“Reschedule Alarm”);
this.timerAlarm.reschedule(zdt);
} else {
logger.info(“New Alarm”);
this.timerAlarm = ScriptExecution.createTimer(zdt, function(){
if (itemRegistry.getItem(‘ActiveMode’).getState()!=“standby”) {
if (itemRegistry.getItem(‘DhwPumpsCirculation’).getState()==“off”) {
var HTTP=Java.type(“org.openhab.core.model.script.actions.HTTP”);
var client_id = “cca64a97484842923a3d05b52325da8e”;
var installationID=“137038”;
var gatewaySerial=“7571381700298105”;
var token=items[“Viessmann_Token”];
//logger.info(“token: {}”,token);
var headers = [];
headers[“Authorization”] = “Bearer “+ token;
var url =“https://api.viessmann.com/iot/v1/equipment/installations/”+ installationID +”/gateways/” +gatewaySerial + “/devices/0/features/heating.dhw.oneTimeCharge/commands/activate”;
//logger.info(“url: {}”, url);
var returnvalue = HTTP.sendHttpPostRequest(url,“application/json”, “{}”,headers,10*1000);
logger.info(“returnvalue: {}”,returnvalue);
} else {
logger.info(“Umwälzpume ist an, also wird Warmwasser schon erzeugt!”);
}
} else {
logger.info(“Anlage ist im StandBy, Warmwasser wird nicht erzeugt!”);
}
logger.info(“Alarm is expired”);
this.timerAlarm.cancel;
this.timerAlarm = null;
});
}
}
}
catch(e) {
logger.info("Error observed : " + e.getMessage);
}

Yes you do need a rule for that. Trigger the rule when the DateTime Item changes and schedule a timer to run at the time in the DateTime Item.

If on a recent version (3.2 M3 or later) you can install just such a rule from the Marketplace.

You don’t need to code this yourself.

1 Like