As I decided to setup my new OpenHAB3 system from scratch instead of migrating my OpenHAB2 stuff I also want to migrate my DSL rules to ECMA Script.
May be this is a silly question, but for example I don’t find anything about how to get the status of a thing in ECMAscript as I have no clue where to look. May be it’s in front of me, but I don’t see it.
So what I’m looking for is kind of a reference where to find the methods and data structures available. It would be very nice if someone could give me just some hints where to look for what to understand what’s available
Example for sending a Telegram message:
In rules DSL it would be something like this
val telegramAction = getActions(“telegram”,“telegram:telegramBot:BOT”)
and in ECMA it would be something like this
var telegramAction = actions.get("telegram","telegram:telegramBot:telegram");
If not someone had told me in this thread, I never would have had the idea how to do it in ECMA Script.
Any help would gladly be appreciated and please forgive me if I just don’t see it.
Thanks a lot
For now, the Helper Libraries doc are your best source for information. I have a series of posts you can find by searching “getting started with ngre” but those are old and there might be some differences with what’s current. Also, looking at the Helper Library code can be helpful.
He @dolittle , agreed that more examples would be helpful.
Have a look here as this list might be helpful to identify the different modules to load.
Also this one as a start and this page helped me to get started.
Thanks very much for your replies. It’s good to see that I’m not too far off track.
@rlkoshak Thank you very much.
@chrismast The Javadoc was an important one.
I hope a lot of community members share their ECMA rules to help the ones looking for information.
Could you get that running? Even with the pages I’m a bit stuck
@bjoernbrings Yes. Actually it’s pretty simple like most things as soon as you know how to do it
This is my rule code
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var ThingUID = Java.type("org.openhab.core.thing.ThingUID");
var telegramAction = actions.get("telegram","telegram:telegramBot:Telegram_Bot_Default");
var triggeringThing = things.get(new ThingUID(event.thingUID)).getLabel();
telegramAction.sendTelegram(triggeringThing +': <strong>' + event.statusInfo + '</strong>');
logger.info(triggeringThing + " änderte den Status zu " + event.statusInfo );
It’s triggered when the thing changes to “ONLINE” or “OFFLINE”. The new state is in
event.statusInfo. You can see the available object on this page. It doesn’t seem to be accurate for OpenHAB 3 beacause I wasn’t able to use any of the “Scripted Automation” Objects that have no Rules DSL equivalent.
event.item didn’t work for me instead I had to use
Hope that helps
That worked. Thanks a lot