pdmangel / node-red-contrib-openhab2

Other
20 stars 14 forks source link

Can OpenHAB2-in capture group state change events as well please #20

Closed TheOriginalMrWolf closed 6 years ago

TheOriginalMrWolf commented 6 years ago

Hi,

It would be fabulous if openhab2-in could capture group state change events as well as those for items. My OH setup has many groups of items (eg switches, motion sensors, etc) on which I need logic to trigger in NR if any one of those items turns on / is triggered (ie the GROUP in OH changes state when any one item changes). For example, 'turn off all lights when no motion detected in public areas for more than 30 mins' -- where public areas is an OH group of motion sensor items.

Openhab-2 monitor shows that NR receives the events for groups, but openhab2-in doesn't trigger. Seems that openhab2-in registers a listener for smarthome/items/\<itemname>/statechanged, whereas for a group it needs to listen for smarthome/items/\<groupname>/\<itemname - should be wildcard>/statechanged.

Would this be hard to do?

Thanks!!!

TheOriginalMrWolf commented 6 years ago

Um... poked it with vaguely sharpened sticks... think I might have done it.

Two small changes in node.es.onmessage = function(msg).... :

Changed:
    var item = msg.topic.substring(("smarthome/items/").length, msg.topic.lastIndexOf('/'));

To:
    const itemStart = ("smarthome/items/").length;
    var item = msg.topic.substring(itemStart, msg.topic.indexOf('/',itemStart));

And -

Changed:
    if ( (msg.type == "ItemStateEvent") || (msg.type == "ItemStateChangedEvent") )  node.emit(item + "/StateEvent", {type: msg.type, state: msg.payload.value});

To:
     if ( (msg.type == "ItemStateEvent") || (msg.type == "ItemStateChangedEvent") || (msg.type == "GroupItemStateChangedEvent")) node.emit(item + "/StateEvent", {type: msg.type, state: msg.payload.value});

Do you see any problem with that? If not, could you please include in the next revision?

Cheers!

pdmangel commented 6 years ago

Thanks for the constructive feedback. It'll probably need some more changes, but seems feasible. I'll work on it the coming week.

pdmangel commented 6 years ago

Just published an update ... give it a try ?