Rule for FOB

zwave
keyfob
Tags: #<Tag:0x00007fe053396210> #<Tag:0x00007fe053396080>

(Robert) #1

System: RaspBerry Pi, Openhab 2.3
Z-Wave devices:
Fibaro keyfob zwave:device:ad9e47cf:node4:scene_number
Telldus switch zwave:device:ad9e47cf:node3:switch_binary
Telldus switch zwave:device:ad9e47cf:node6:switch_binary

Goal: using the fob to control switches.
I’ve created the rule below, but it doesn’t work. What am I doing wrong?

Thank’s in advance for help/guidance.

Rule (fob.rule):

var String drState

rule “fob”
when
Item zwave_device_ad9e47cf_node4_scene_number received update
then
var swState = wave_device_ad9e47cf_node4_scene_number.state
var name = “wave_device_ad9e47cf_node4_scene_number”
logInfo(name, "Update: " + swState)

switch swState {
    case 1.0: {logInfo(name, "Square1xClick") 
    zwave_device_ad9e47cf_node3_switch_binary.sendCommand(ON)
    }
    
}                

end

The above is based on:

rule “KeyFob1”
when
Item KeyFob1 received update
then
var swState = KeyFob1.state
var name = “KeyFob1Rule”
logInfo(name, "Update: " + swState)

switch swState {
    case 1.0: {logInfo(name, "Square1xClick") 
    }
    case 1.3: {logInfo(name, "Square2xClick") 
    }
    case 1.4: {logInfo(name, "Square3xClick") 
    }
    case 1.2: {logInfo(name, "SquareHoldDown")
    }
    case 1.1: {logInfo(name, "SquareRelease")
    }
    case 2.0: {logInfo(name, "O1xClick") 
    }
    }
    case 2.3: {logInfo(name, "O2xClick") 
    }
    case 2.4: {logInfo(name, "O3xClick") 
    }
    case 2.2: {logInfo(name, "OHoldDown")
    }
    case 2.1: {logInfo(name, "ORelease")
    }
    case 3.0: {logInfo(name, "X1xClick") 
    }
    case 3.3: {logInfo(name, "X2xClick") 
    }
    case 3.4: {logInfo(name, "X3xClick") 
    }
    case 3.2: {logInfo(name, "XHoldDown")
    }
    case 3.1: {logInfo(name, "XRelease")
    }
    case 4.0: {logInfo(name, "Triangle1xClick") 
    }
    case 4.3: {logInfo(name, "Triangle2xClick") 
    }
    case 4.4: {logInfo(name, "Triangle3xClick") 
    }
    case 4.2: {logInfo(name, "TriangleHoldDown")
    }
    case 4.1: {logInfo(name, "TriangleRelease")
    }
    case 5.0: {logInfo(name, "-1xClick") 
    }
    case 5.3: {logInfo(name, "-2xClick") 
    }
    case 5.4: {logInfo(name, "-3xClick") 
    }
    case 5.2: {logInfo(name, "-HoldDown")
    }
    case 5.1: {logInfo(name, "-Release")
    }
    case 6.0: {logInfo(name, "+1xClick") 
    }
    case 6.3: {logInfo(name, "+2xClick") 
    }
    case 6.4: {logInfo(name, "+3xClick") 
    }
    case 6.2: {logInfo(name, "+HoldDown")
    }
    case 6.1: {logInfo(name, "+Release")
    }
}                

end


(Vincent Regaud) #2

First, please use code fences

Did you try:

var swState = wave_device_ad9e47cf_node4_scene_number.state as Number


(Scott Rushworth) #3

You haven’t provided an error log or described what isn’t working, so you’re not making it easy to be helpful! :wink:

Your device, which I’m guessing is this one, does have CENTRAL_SCENE, so the format for the values for the scene_number channel are correct. The first thing that stands out to me, is that you are trying to do string concatenation with a state in your logging.

I’d expext this will throw an error. You’ll need to use…

logInfo(name, "Update: " + swState.toString)

or

logInfo(name, "Update: {}".swState)

or define swState as a String…

var swState = KeyFob1.state.toString

With swState as a String, it fixes the logging issue, but then you’d need to change your switch/case to use Strings too…

switch swState {
    case "1.0" : {
        logInfo(name, "Square1xClick") 
        zwave_device_ad9e47cf_node3_switch_binary.sendCommand(ON)
    }
}    

(Robert) #4

First of all, thank you for your input and sorry for the code mess in in the post.
Im using the following fob (like 5iver guessed): Fibaro keyfob (Fibaro FGKF-601)
The switches are Telldus switches of type TZWP-100

I’ve now created the following rule:

var String drState

rule "fob" 
when
        Item zwave:device:ad9e47cf:node4:scene_number received update
then 
    var swState = zwave:device:ad9e47cf:node4:scene_number.state as Number
    var name = "FobRule" 
    logInfo(name, "Update:" + swState.toString)
    
    switch swState {
        case "1.0": {
        logInfo(name, "Square1xClick") 
        zwave:device:ad9e47cf:node3:switch_binary.sendCommand(ON)
        }        
    }                
end

Pressing the square button on the fob produces the following output in the log entries: [vent.ItemStateChangedEvent] - zwave_serial_zstick_ad9e47cf_serial_sof changed from 2503 to 2504
[vent.ItemStateChangedEvent] - zwave_device_ad9e47cf_node4_scene_number changed from 2.0 to 1.0

However, the switch doesn’t do anything :frowning:


(Daniel Walters) #5

Hi @archie_n

You have Items and Channels confused.

zwave:device:ad9e47cf:node4:scene_number is a Channel - link.
zwave_device_ad9e47cf_node4_scene_number is an Item - link.

Item's don’t have colons in the identifier.

You haven’t given enough information for me to say this will definitively work (I don’t know what your relevant Items are actually called or what the ItemType is) but if you re-write your rule as below, you will probably get a bit further:

rule "fob" 
when
        Item zwave_device_ad9e47cf_node4_scene_number received update
then 
    var swState = zwave_device_ad9e47cf_node4_scene_number.state as Number
    var name = "FobRule" 
    logInfo(name, "Update:" + swState.toString)
    
    switch swState {
        case 1.0: {
        logInfo(name, "Square1xClick") 
        zwave_device_ad9e47cf_node3_switch_binary.sendCommand(ON)
        }        
    }                
end

(Robert) #6

THANK YOU! Your input really got me pointed in the right direction!
The code below is now working as follows:

  • switch “on” by pressing “square”
  • switch “off” by pressing “circle”

The next step will be using the same button for switching on/off. Let’s see how that goes :slight_smile:

var String drState

rule "fob" 

when
        Item zwave_device_ad9e47cf_node4_scene_number received update

then 
    var swState = zwave_device_ad9e47cf_node4_scene_number.state as Number
    var name = "FobRule" 
    logInfo(name, "Update:" + swState.toString)

    switch swState {
        case 1.0: {
        logInfo(name, "Square1xClick") 
        zwave_device_ad9e47cf_node3_switch_binary.sendCommand(ON)
        }
        
        case 2.0: {
        logInfo(name, "O1xClick") 
        zwave_device_ad9e47cf_node3_switch_binary.sendCommand(OFF)
        }    
    }                
end

Having trouble getting fibaro keyfob working