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

Yes that one

You also need to install the transformation service in the paperUI

Yes, transformation service already installed. Same result. What am I missing?

This one?

I have install json transformation. I need the java one as well?

Yes you need to javascript transformation service

1 Like

The javascript transformation was the missing piece. Thanks so much!
Can I assume if I have more of these sensors to just put in more of the same files, eg windows1.js, windows2.js windows3.js etc, in things and transform ?

Correct

Great. What if I have more RF bridges connected to more contacts? Would not the “var window = data.RfReceived.Data;” part be the same for all the bridges?

The code will remain the same except for the 1D280E and 1D280A which will be different for all windows
So you only need to change this

awesome. Thanks again, I have learnt much from this example

Please tick the solution post
And add some likes, thanks

How do I show all the status of all my windows at the same time, not just the ones that open or close?

This is my current windows.js file

(function(jsonString) {
    var data = JSON.parse(jsonString);
    var window = data.RfReceived.Data;
    if (window === null) window = UNDEF;
    if (window == '1D280A') window = 'MB Left Window OPEN';
    if (window == '1D280E') window = 'MB Left Window CLOSED';
    if (window == '14D70A') window = 'MB Centre Window OPEN';
    if (window == '14D70E') window = 'MB Centre Window CLOSED';
    if (window == '18F80A') window = 'MB Right Window OPEN';
    if (window == '18F80E') window = 'MB Right Window CLOSED';
    return window;
})(input)

That’s wrong
You need 3 js files one for each window

LeftWindow.js

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

CentreWindow.js

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

RightWindow.js

(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)

And change the transformation pattern in each channel

1 Like

“and change the transformation pattern in each channel”

Sorry, how do I do this in my thing and item ? Just add these in things?

Type string : receiveddata  "Received Data"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:leftwindow.js"]
Type string : receiveddata  "Received Data"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:centrewindow.js"]
Type string : receiveddata  "Received Data"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:rightwindow.js"]

Hint: see post 19

What I did with the 3 things entries didnt work.

Oh dear oh dear

Post your things file

Thing mqtt:topic:bridge1 "RF Bridge 1" @ "Master Bedroom" {
        Type string : reachable     "Reachable"            [ stateTopic="tele/sonoff/bridge1/LWT" ]
        Type string : receiveddata  "Received Data"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:leftwindow.js"]
        Type string : receiveddata  "Received Data"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:centrewindow.js"]
        Type string : receiveddata  "Received Data"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:rightwindow.js"]
        Type string : receivedsync  "Received Sync"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"]
        Type string : receivedlow   "Received Low"         [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"]
        Type string : receivedhigh  "Received High"        [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"]
        Type string : receivedrfkey "Received RfKey"       [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]
        Type switch : button1       "Button 1"             [ stateTopic="stat/sonoff/bridge1/RESULT", commandTopic="cmnd/sonoff/bridge1/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]
        Type switch : button2       "Button 2"             [ stateTopic="stat/sonoff/bridge1/RESULT", commandTopic="cmnd/sonoff/bridge1/RFKEY2", transformationPattern="JSONPATH:$.RfKey2" ]
        Type switch : button3       "Button 3"             [ stateTopic="stat/sonoff/bridge1/RESULT", commandTopic="cmnd/sonoff/bridge1/RFKEY3", transformationPattern="JSONPATH:$.RfKey3" ] 
        Type switch : button4       "Button 4"             [ stateTopic="stat/sonoff/bridge1/RESULT", commandTopic="cmnd/sonoff/bridge1/RFKEY4", transformationPattern="JSONPATH:$.RfKey4" ]
        Type number : rssi          "WiFi Signal Strength" [ stateTopic="tele/sonoff/bridge1/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
        Type string : version   "Current Firmware"     [ stateTopic="stat/sonoff/bridge1/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]

Oh dear oh dear:

Type string : receiveddata "Received Data" [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:leftwindow.js"]
Type string : receiveddata "Received Data" [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:centrewindow.js"]
Type string : receiveddata "Received Data" [ stateTopic="tele/sonoff/bridge1/RESULT", transformationPattern="JS:rightwindow.js"]

Change to:

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"]
1 Like

Roger. For my item file, this is what I have originally:

String Bridge1_Received_Data  "RF Bridge Received Data: [%s]"            <none>          (Bridge1) { channel="mqtt:topic:bridge1:receiveddata" }

This is my amended one:

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

Is that right?

Ooops , just got a bunch of errors in the log

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

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

2019-01-06 20:18:56.558 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JS-transformation failed: An error occurred while executing script.

2019-01-06 20:18:56.561 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfReceived":{"Sync":13900,"Low":460,"High":1340,"Data":"1D280E","RfKey":2}}' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.{"RfReceived":{"Sync":13900,"Low":460,"High":1340,"Data":"1D280E","RfKey":2}}

Change the “String” to “Contact” in the item for these 3 files. Now only the first contact (left) shows Open and Closed. The other 2 still having these log errors:

2019-01-06 20:25:30.546 [WARN ] [eneric.internal.generic.ChannelState] - Command '14D70A' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.14D70A

2019-01-06 20:25:30.646 [WARN ] [eneric.internal.generic.ChannelState] - Command 'MB Centre Window OPEN' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.MB Centre Window OPEN

2019-01-06 20:25:33.057 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JS-transformation failed: An error occurred while executing script.

2019-01-06 20:25:33.062 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfReceived":{"Sync":13980,"Low":460,"High":1350,"Data":"14D70E","RfKey":"None"}}' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.{"RfReceived":{"Sync":13980,"Low":460,"High":1350,"Data":"14D70E","RfKey":"None"}}
2019-01-06 20:26:07.270 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JS-transformation failed: An error occurred while executing script.

2019-01-06 20:26:07.274 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfReceived":{"Sync":13910,"Low":470,"High":1340,"Data":"18F80A","RfKey":"None"}}' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.{"RfReceived":{"Sync":13910,"Low":470,"High":1340,"Data":"18F80A","RfKey":"None"}}

==&gt; /var/log/openhab2/events.log &lt;==

2019-01-06 20:26:07.293 [vent.ItemStateChangedEvent] - Bridge1_Received_Sync changed from 13980 to 13910

2019-01-06 20:26:07.301 [vent.ItemStateChangedEvent] - Bridge1_Received_High changed from 1350 to 1340

==&gt; /var/log/openhab2/openhab.log &lt;==

2019-01-06 20:26:07.363 [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:26:07.428 [WARN ] [eneric.internal.generic.ChannelState] - Command '18F80A' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.18F80A

==&gt; /var/log/openhab2/events.log &lt;==

2019-01-06 20:26:09.928 [vent.ItemStateChangedEvent] - Bridge1_Received_Low changed from 470 to 460

==&gt; /var/log/openhab2/openhab.log &lt;==

2019-01-06 20:26:10.000 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JS-transformation failed: An error occurred while executing script.

2019-01-06 20:26:10.003 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"RfReceived":{"Sync":13930,"Low":460,"High":1360,"Data":"18F80E","RfKey":"None"}}' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.{"RfReceived":{"Sync":13930,"Low":460,"High":1360,"Data":"18F80E","RfKey":"None"}}

==&gt; /var/log/openhab2/events.log &lt;==

2019-01-06 20:26:10.016 [vent.ItemStateChangedEvent] - Bridge1_Received_Sync changed from 13910 to 13930

2019-01-06 20:26:10.021 [vent.ItemStateChangedEvent] - Bridge1_Received_High changed from 1340 to 1360

==&gt; /var/log/openhab2/openhab.log &lt;==

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

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