I’ve just received a 4 port Aoke relay from Aliexpress which I’m trying to get working with openhab.
Following information I found at
I’ve managed to get two of the relays on the board to toggle when setup as a Switch item, but to work with the rest of them I need to be able to send more than a simple OFF and ON Command to the board.
Using RFXMGR on windows I’ve managed to find the address, and just taking the most significant 5 sets of 4 binary numbers I have a working Hex and also Decimal number that I can plug into Items as a switch to get it working with the V1.9.0 binding. An item formatted similar to below works.
But this seems to send either 0001 or 0100 as the last 4 bits witch toggles the first and third relays on the board. To access the other 2 I need to replace the last byte with the decimal version of 0000-1111, as work with RFXMGR suggests that with the number I’ve found, the last 4 bits represents the individual relay states.
I’m assuming the switch item just sends either 0001 or 0100 meaning relay 3 on , relay 1 off, or relay 3 off, relay 1 on
So far I’ve tried replacing the word “Command” with “RawData” and also configuring the item as a string item.but this didn’t work.
Is there any chance of getting the binding modified so a number item can be added to the list of valid commands? I can then use a rule to create the correct number for the number of relays I want ON / OFF @Speeder can you help as you worked on the other problem?
This isn’t a binding problem but a switch problem. Use a String out Number Item and put it on your sitemap as a switch with mappings to convert the ON and OFF to the number or text you need.
Alternatively, create a proxy Switch Item and a rule to send the number or String to the String Item.
If you replaced the “real” Item with a proxy Item put the proxy on the sitemap like above. then create a rule:
rule "Send command"
when
Item ProxyItem received command
then
switch(ProxyItem.state as DecimalType) {
case 1: RealItem.sendCommnad("cmd for 1")
case 2: RealItem.sendCommand("cmd for 2")
}
end
Thanks - can you suggest what the item should be? The following 3 don’t seem to work and throw
"Invalid item type for value selector ‘Command’!" followed by many lines of text. Perhaps “Command” needs replacing with something else?
Can you advise what type “Item ProxyItem” should be?
With Switch I get “Received HTTP POST request at ‘items/RFXProxy’ with an invalid status value ‘2’.”
With Number I get “Error during the execution of rule ‘RFX Proxy’: Cannot cast org.openhab.core.library.items.NumberItem to org.openhab.core.library.types.DecimalType”
With String I get “Error during the execution of rule ‘RFX Proxy’: Cannot cast org.openhab.core.library.items.StringItem to org.openhab.core.library.types.DecimalType”
The items are one of
String RFXProxy
Number RFXProxy
Switch RFXProxy
The Rule is
rule "RFX Proxy"
when
Item RFXProxy received command
then
switch(RFXProxy as DecimalType) {
case 1: RFXTest.sendCommand(1)
case 2: RFXTest.sendCommand(2)
case 3: RFXTest.sendCommand(3)
case 4: RFXTest.sendCommand(4)
}
end
Thanks, now a numbered item, and the missing “,state” added to the rules. As it doesn’t yet work I added a log statement to the bottom of the rule and I now see that “RFXTest is uninitialized” after I send it a command. I can postUpdate(RFXTest, 0) from a rule which works but the proxy rule doesn’t change it. My other RFXCOM items seem to work so it must be something with the binding item?
I’ve added an additional rule to tell me what is going on
rule "Log RFXTest state"
when Item RFXTest changed then {
logInfo("RFXTest", "RFXTest is " +RFXTest.state) }
end
The main rule reads
rule "RFX Proxy"
when
Item RFXProxy received command
then
switch(RFXProxy as DecimalType) {
case 1: RFXTest.sendCommand("1")
case 2: RFXTest.sendCommand("2")
case 3: RFXTest.sendCommand("3")
case 4: RFXTest.sendCommand("4")
}
end
The items now read
String RFXTest { rfxcom=">123456.550:LIGHTING4.PT2262:RawData" }
Number RFXProxy
Nothing appears in the log, but adding log statements after the sendCommand suggest the rule is running, but the result seems to be just disappearing??
Also substituting RFXTest.sendCommand(“1)” etc for another of my items, for both a number and a string item successfully updates it, so I wonder if “RawData” is being ignored?
Nope, that didn’t work. I’ll take a look on the recent changes on GitHub to see if I can work out what its expecting. I believe @Speeder is the guy that did the recent changes, so I’ll send him a PM if he doesn’t catch this thread.
Thanks for your help!
rule "RFX Proxy"
when
Item RFXProxy received command
then
switch(RFXProxy.state as DecimalType) {
case 1: RFXTest.sendCommand("1")
case 2: RFXTest.sendCommand("2")
case 3: RFXTest.sendCommand("3")
case 4: RFXTest.sendCommand("4")
}
end
you even could use
switch(receivedCommand as DecimalType) {
as your trigger is received command, so receivedCommand will contain the command
String version:
rule "RFX Proxy"
when
Item RFXProxy received command
then
switch(receivedCommand.toString) {
case "1": RFXTest.sendCommand("1")
case "2": RFXTest.sendCommand("2")
case "3": RFXTest.sendCommand("3")
case "4": RFXTest.sendCommand("4")
}
end
When using logInfo, be aware that you have to use only strings to compose the output:
logInfo("RFXTest", "RFXTest is " + RFXTest.state.toString)
or use
logInfo("RFXTest", "RFXTest is {}", RFXTest.state)
which should convert the state to a string itself.
Thanks very much indeed!
I’ll have a go at compiling if you can point me to a set of easy instructions. I’ve got a spare pi that I can use without upsetting the live system.
Last time I tried it didn’t go that well, but I’ve learnt a bit more these days
@Speeder
I think the compile happened - I copy and pasted the text from the link you gave me into the same file in the binding in Eclilse. It had one item it was not happy with which was on line 294.
Your original text
} else if (instanceof DecimalType) {
I changed to
} else if (type instanceof DecimalType) {
This got rid of the error and I was able to right click the binding and choose export, I then replaced the binding on my openhab system with it.
The item was set as
Number RFXTest { rfxcom=">123456.550:LIGHTING4.PT2262:Command" }
But after a reboot I got the following after Loading model ‘default.items’
[i.internal.GenericItemProvider] - Binding configuration of type ‘rfxcom’ of item ?RFXTest? could not be parsed correctly.
org.openhab.model.item.binding.BindingConfigParseException: Invalid item type for value selector ‘Command’!
Changing "Number for “String” didn’t work either. Changing it back to “Switch” makes the item work albeit only as ON and OFF type.
I think something deeper than the added line may need to change to allow it to accept something other than “Command” at the end of the item, RFXTest.sendCommand(“3”) and RFXTest.sendCommand(3) didn’t work either.
Which file defines inside the IDE binding what form the items can take?
@Speeder
Further update, I spent a while looking at it, and I ended up changing the section around line 290 to read
case COMMAND:
if (type instanceof OnOffType) {
command = (type == OnOffType.ON ? Commands.ON_1 : Commands.OFF_4);
commandId = (command.ordinal());
} else {
throw new RFXComException("Can't convert " + type + " to Command");
}
break;
case NUMBER:
if (type instanceof DecimalType) {
commandId = ((DecimalType) type).intValue();
} else {
throw new RFXComException("Can't convert " + type + " to Command");
}
break;
Once I’d done this I clicked on the red unhappy type message which gave me a clue that I also needed to add “Number” as an allowed item elsewhere in the Binding. Once I did this and saved both files it exported sucessfully and I now have a working item similar to
Number RFXTest { rfxcom=">123456.550:LIGHTING4.PT2262:Number" }
and from a rules file I can send commands like
RFXTest.sendCommand("15")
I’m happy to share what I’ve done if someone can talk me through how to do the sharing
Hi @kevin
You’re right, the same valueSelector (“Command”) can not be used for 2 different item types.
A new valueSelector has to be defined in RFXComValueSelector.java and in RFXComLighting4Message.java.
If you want to merge your modification in the main Openhab stream, you have to create a fork of the main github repository, update the 2 files in a new branch and then propose a pull request in Openhab.
Hi @Speeder
I’ve created a new branch, updated the files and created 1 Pull request for each file with the description in the message. Can you let me know if this is correct?