[SOLVED] Rule to show window as open or closed when wifi contact sensor sends RF data

I dont believe this will work if you have more than 1 sensor for the Kerui D026, as it also has 4 different RF outputs

Thanks for your reply. I have sorted out the correct setup now but I appreciate your input :grinning:

Hey guys,

Following the method @vzorglub is mentioning above I stumbled into a problem and I would really appreciate any advice you have to offer.

The JS transformation solution is working fine, but after adding a second JS transformation file along with the proper channel and items, I get this warning even though everything is still working fine:

[WARN ] [eneric.internal.generic.ChannelState] - Command ‘317F0A’ not supported by type ‘OpenCloseValue’: No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.317F0A

After some digging, I discovered what is causing the error !

Every RF code received by the RF Bridge is being forwarded for every single channel (things file) to all the JS transformation files (as many as the physical contacts).
The warning occurs because each transformation file includes only 2 RF codes (open/closed) for a specific device. So any unknown RF code to that specific JS transformation file is not transforming and remains a string (eg. ‘F2670E’) which gives the warning message.

I’m really struggling to find a solution for some time now, but so far no luck…

This is my setup:

home.items

Contact LivingRoom_Window       "Living Room Window [%s]"        <window>    (gLivingRoom, gWindow, MagicMirror) [ "ContactSensor" ] { channel="mqtt:topic:mosquitto:rf_bridge:livingroomwindow" }
Contact Office_Window           "Office Window [%s]"             <window>    (gOffice, gWindow, gMagicMirror)    [ "ContactSensor" ] { channel="mqtt:topic:mosquitto:rf_bridge:officewindow" }

home.things

Type contact:livingroomwindow "Living Room Window"   [ stateTopic="tele/rf_bridge/RESULT", transformationPattern="JS:livingroom_window.js" ]
Type contact:officewindow     "Office Window"        [ stateTopic="tele/rf_bridge/RESULT", transformationPattern="JS:office_window.js" ]

livingroom_window.js

(function(jsonString) {
    var data = JSON.parse(jsonString);
    var window = data.RfReceived.Data;
    if (window === null) window = UNDEF;
    if (window == '317F0A') window = 'OPEN';
    if (window == '317F0E') window = 'CLOSED';
    return window;
})(input)

officewindow_window.js

(function(jsonString) {
    var data = JSON.parse(jsonString);
    var window = data.RfReceived.Data;
    if (window === null) window = UNDEF;
    if (window == '31910A') window = 'OPEN';
    if (window == '31910E') window = 'CLOSED';
    return window;
})(input)

In my case, RF Code ‘317F0A’ is not included in “officewindow.js” (but only in “livingroom_window.js”) and that returns the string and not a stare which is causing the warning.

Any help would be appreciated :slight_smile:
Thank you in advance !

This looks like a similar wheel being invented, by rule instead of transform

Thanks for your reply!
Indeed, quite similar situation. With this solution though I’m loosing the “contact” thing and start using the “string” instead. I’m just wild guessing but there might be another “hybrid” way through the channel or thing configuration, to filter out and send out relevant (included) RF codes to every JS.

What do you think?

Don’t think there is a clean way for a transform to say “hey I got some incoming data on this channel but you can’t have any”. (Which is what your WARN means)

Not sure what you see the problem with String as. The general technique there is to pull all messages into a working String, then analyze for magic codewords and postUpdate whatever Item of whichever yype you wish.

I see what you mean.
Actually the reason I initially turned my things to from string to contact was because I was trying to interrogate with google home and apple’s homekit but with no luck.
I mean the lights and switches are all working fine as well as temperature and humidity readings but not the magnetic contacts or motion sensors.
As you can see in my initial post I use the [ “ContactSensor” ] tag as described by the documentation but it’s not working despite my thing is a contact.

I guest it’s time for me to abandon this approach and set up every RF as string along with the proper json transformation. :sweat_smile: