Platform information: Pi3
openHAB version: openhabian
Hi guys, I am just trying to move over some DSL rules to scripts.
I am trying to send a notification of a battery level. The items is reading fine.
Is state.toString the way to send an item value to a broadcast notification? I can’t seem to get it to work.
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var NotificationAction = org.openhab.io.openhabcloud.NotificationAction;
var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");
if (itemRegistry.getItem('Test_Sw').getState() == 'ON')
{
NotificationAction.sendBroadcastNotification("GW battery is {}" + GPSTrackerGW_BatteryLevel.state.toString );
}
binderth
(Thomas Binder)
January 12, 2021, 8:55am
#2
see the following information for that.
easiest for ECMA is events.sendCommand("ITEMNAME", VALUE);
or events.postUpdate("ITEMNAME", VALUE);
to read the value it’s just items["ITEMNAME"]
your line should read:
...
NotificationAction.sendBroadcastNotification("GW battery is " + items["GPSTrackerGW_BatteryLevel"] );
...
https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Event%20Object%20Attributes.html
Check here for all available event properties:
I use this as my template rule script:
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var NotificationAction = org.openhab.io.openhabcloud.NotificationAction;
var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");
var ZonedDateTime = Java.type("java.time.ZonedDateTime");
this.myVar = (this.myVar === undefined) ? "whatever": this.myVar;
this.myTimer = (this.mytim…
Thanks Thomas. That really helped.
I am still getting the hang of the script type solutions.
Thanks again.
1 Like