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

Change your js transformations EXACTLY as above

Ok. Left and Centre ok now. But still having this error with Right

(function(jsonString) {
    var data = JSON.parse(jsonString);
    var window = data.RfReceived.Data;
    if (window === null) window = UNDEF;
    if (window == '18F80A') window = 'OPEN';
    if (window == '18F80E') window = 'CLOSED';
    return window;
})(input)
2019-01-06 20:40:44.957 [WARN ] [eneric.internal.generic.ChannelState] - Command '18F80A' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.18F80A

2019-01-06 20:40:45.034 [WARN ] [eneric.internal.generic.ChannelState] - Command '18F80A' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.18F80A

Change your items to:

Contact Bridge1_Left_Window  "Left Window: [%s]"            <none>          (Bridge1) { channel="mqtt:topic:bridge1:leftwindow" }
Contact Bridge1_Centre_Window  "Centre Window: [%s]"            <none>          (Bridge1) { channel="mqtt:topic:bridge1:centrewindow" }
Contact Bridge1_Right_Window  "Right Window: [%s]"            <none>          (Bridge1) { channel="mqtt:topic:bridge1:rightwindow" }

What error do you get?

1 Like

Show me your things again

I copy and paste your items over mine and now all 3 contacts are ok.
I cannot find where my typo/error was but I guess every alphabet counts.
This is my final thing file:

Type contact : leftwindow   "Left Window"          [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:LeftWindow.js"]
        Type contact : centrewindow "Centre Window"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:CentreWindow.js"]
        Type contact : rightwindow  "Right Window"         [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:RightWindow.js"]

My final item file

Contact Bridge1_Left_Window  "Left Window: [%s]"            <none>          (Bridge1) { channel="mqtt:topic:bridge1:leftwindow" }
Contact Bridge1_Centre_Window  "Centre Window: [%s]"            <none>          (Bridge1) { channel="mqtt:topic:bridge1:centrewindow" }
Contact Bridge1_Right_Window  "Right Window: [%s]"            <none>          (Bridge1) { channel="mqtt:topic:bridge1:rightwindow" }

Including the 3 transformation js files you kindly gave me. It all works now.

Yeah, we got there
Now review the changes we made a try to understand your errors

  • Things channels of the wrong type and 3 of them with the same name
  • Items types incorrect
  • Misunderstanding of the js transformation
1 Like

Roger that . Thanks again!

Im at my witts end with trying to fingure this out. copied your solution and altered to suit my situation but still not working. please advise!!!

things file,

Type contact : FrontDoor   "Front Door"          [ stateTopic="tele/Sonoff_Bridge/RESULT", transformationPattern="JS:FrontDoor.js"]
Type contact : RearDoor "Rear Door"        [ stateTopic="tele/Sonoff_Bridge/RESULT", transformationPattern="JS:RearDoor.js"]
}```

items file,

Contact Sonoff_Bridge_Front_Door  "Front Door: [%s]"            <frontdoor>           { channel="mqtt:topic:Sonoff_Bridge:FrontDoor" }
Contact Sonoff_Bridge_Rear_Door  "Rear Door: [%s]"            <door>           { channel="mqtt:topic:Sonoff_Bridge:RearDoor" }

sitemap,

Frame label="Security"   {
               Text item=Sonoff_Bridge_Front_Door
               Text item=Sonoff_Bridge_Rear_Door
         }

transform file

(function(jsonString) {
    var data = JSON.parse(jsonString);
    var door = data.RfReceived.Data;
    if (door === null) door = UNDEF;
    if (door == '2BC00A') door = 'OPEN';
    if (door == '2BC00E') door = 'CLOSED';
    return door;
})(input

anybody?

Any errors in the log?
Is the JS transformation installed?

No errors on log at all. Had to double check that the mqtt was working! Yeah all transformations services are installed. Do I need to add the rf bridge itself as a item or thing?

Yes, the RF bridge must be added as a things file (along with your mqtt broker)

You also need items file for all your channels.

Hi Vincent,
I now have a Kerui D026 which gives out 4 distinct RF codes, not just for open and close like the previous one:
abcdEE open
abcdE7 close
abcdEB tamper
abcdEF low battery

Using your JS transformation example does not work anymore as I guess its not 1 code or the other. Can you help me with the right transformations/rules to get this contact sensor functional in OH?

A lot of people are starting using the Kerui D026 door sensors. I am currently implementing 6 sensors.

So, i tried using this

Type contact : kerui01		[ stateTopic="tele/WIFIRF/RESULT", 			transformationPattern="JSONPATH:$.RfReceived.Data", open="64D72E", closed="64D727" ]	

which would be ideal.

On the log it gives

2019-05-10 21:19:15.765 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘64D72E’ not supported by type ‘OpenCloseValue’: No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.64D72E

Why do we need the javascript transformation ?

Well, i just found it

Channel Type “contact”, “switch”

  • on : A optional number (like 1, 10) or a string (like “ON”/“Open”) that is recognized as on/open state.
  • off : A optional number (like 0, -10) or a string (like “OFF”/“Close”) that is recognized as off/closed state.

The contact channel by default recognizes "OPEN" and "CLOSED" . You can connect this channel to a Contact item. The switch channel by default recognizes "ON" and "OFF" . You can connect this channel to a Switch item.

If on and off are not configured it publishes the strings mentioned before respectively.

You can connect this channel to a Contact or Switch item

It seems that the contact item uses the on/off settings as the switch item.

So, this works!

	Type contact : kerui01		[ stateTopic="tele/WIFIRF/RESULT", 			transformationPattern="JSONPATH:$.RfReceived.Data", on="64D72E", off="64D727" ]	

No need for the classic rules example!

Hi Nick,
Are you using MQTT 2.4 binding for your example?

How did you cater for the battery and tamper RF data?

thanks!

This is for the 2.4 mqtt binding.
This way can’t control the other 2 signal codes. For tampering and battery you should use the rules file.
Btw, how can i test the low battery function without an empty battery ? :slight_smile:

HI Nick
If you look at the 4 RF codes typically given out by the kerui d026 eg.
abcdeE open
abcde7 closed
abcdeB tamper
abcdeF low battery

almost certainly, the last characters F is for low battery, whilst B is for tamper

1 Like

Nick,
Would you have an example of the rules file for the battery and tamper data for each sensor?

thanks

no, i haven’t implemented the battery and tamper notifications yet

Hey @Taffy,
I know it’s been a long time since you’ve posted that, but just in case you still haven’t figure this out


Change your sitemap from this:

Text item=Sonoff_Bridge_Front_Door
Text item=Sonoff_Bridge_Rear_Door

To this:

Default item=Sonoff_Bridge_Front_Door
Default item=Sonoff_Bridge_Rear_Door

As for the transformation js, you should use 2 separate files, one for each door contact.
You should also be careful with your syntax. If you look more closely to the last line of the code, you forgot to close the last parenthesis.

So, use the one bellow to make 2 files, “FrontDoor.js” and “RearDoor.js” and just change the RF codes accordingly to match to your devices codes.

(function(jsonString) {
var data = JSON.parse(jsonString);
var door = data.RfReceived.Data;
if (door === null) door = UNDEF;
if (door == ‘2BC00A’) door = ‘OPEN’;
if (door == ‘2BC00E’) door = ‘CLOSED’;
return door;
})(input)

Hope this helps your situation :slight_smile: