Skip to content

Commit

Permalink
Revert "[rfxcom] Add ability to properly receive configured command i…
Browse files Browse the repository at this point in the history
…ds, deprecated hard-coded guesses. (openhab#10940)"

This reverts commit 8352f7a.

Signed-off-by: dw-8 <davy.wong.on+github@gmail.com>
  • Loading branch information
dw-8 committed Jul 25, 2021
1 parent bdb6eea commit 9492e4d
Show file tree
Hide file tree
Showing 72 changed files with 591 additions and 916 deletions.
150 changes: 76 additions & 74 deletions bundles/org.openhab.binding.rfxcom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ Bridge rfxcom:tcpbridge:sunflower [ host="sunflower", port=10001 ] {

## Thing Configuration

Configuration parameters are listed alongside each thing type. Most devices only require a deviceId and
a subType, but some things require additional configuration. The deviceId is used both when receiving and
transmitting messages, the subType is mainly used when sending messages, but it can vary between device
types.
Available configuration parameters are:

| Applies to | Parameter Label | Parameter ID | Description | Required | Default |
|------------|-----------------|--------------|----------------------------------------------------------------------|----------|---------|
| All things | Device ID | deviceId | (Unique) id of the device, for example "100001.1", "B.8" or "286169" | true | |
| All things | Sub type | subType | Sub type, note that every thing-type has its own sub types | true | |
| Lighting4 | Pulse | pulse | Pulse length used by the device, only used when sending | false | 350 |
| Lighting4 | On command ID | onCommandId | Id of the command which should be send to turn the device ON | false | 1 |
| Lighting4 | Off command ID | offCommandId | Id of the command which should be send to turn the device OFF | false | 4 |

## Channels

Expand Down Expand Up @@ -685,27 +690,7 @@ A Lighting2 device

### lighting4 - RFXCOM Lighting4 Actuator

A Lighting4 device. The specification for the PT2262 protocol includes 3 bytes for data. By
convention, the first 20 bits of this is used for deviceId, and the last 4 bits is used for
command, which gives us a total of 16 commands per device.

Depending on your device, you may have only one command, one pair of commands (on/off), or
any other multiple, for example, a set of 4 sockets with an on/off pair for each and an
additional pair for "all".

Different device manufactures using this protocol will use different schemes for their
commands, so to configure a thing using the lighting4 protocol, you must specify at least
one commandId in the thing configuration. If a device has multiple sets of commands, you
can configure multiple things with the same device id, but different commandIds.

Some devices will expect a specific pulse length. If required, that can also be specified
as a thing configuration parameter.

Previously, openHAB would attempt to guess at the meaning of a commandId if it was not
specified in the thing configuration based on devices seen in the wild. Due to the varying
nature of devices, this behaviour is deprecated and will be removed in a future openHAB
version. Until then, commands 1, 3, 5-13 and 15 are considered ON and 0, 2, 4 and 14 are
considered OFF when the `onCommandId` or `offCommandId` for a device is not specified.
A Lighting4 device

#### Channels

Expand All @@ -724,78 +709,95 @@ considered OFF when the `onCommandId` or `offCommandId` for a device is not spec
* subType - Sub Type
* Specifies device sub type.

* PT2262 - PT2262
* PT2262 - PT2262

* pulse - Pulse length
* Pulse length of the device

* onCommandId - On command
* Specifies command that represents ON for this device.
* Specifies command to be send when ON must be transmitted

* 0 - OFF (value 0)
* 1 - ON (value 1)
* 2 - OFF (value 2)
* 3 - ON (value 3)
* 4 - OFF (value 4)
* 5 - ON (value 5)
* 6 - value 6
* 7 - ON (value 7)
* 8 - value 8
* 9 - ON (value 9)
* 10 - ON (value 10)
* 11 - ON (value 11)
* 12 - ON (value 12)
* 13 - value 13
* 14 - OFF (value 14)
* 15 - value 15

* offCommandId - Off command
* Specifies command that represents OFF for this device.

* openCommandId - Open command
* Specifies command that represents OPEN for this device.

* closedCommandId - Closed command
* Specifies command that represents CLOSED for this device.

#### Discovering commandId values
* Specifies command to be send when OFF must be transmitted

* 0 - OFF (value 0)
* 1 - ON (value 1)
* 2 - OFF (value 2)
* 3 - ON (value 3)
* 4 - OFF (value 4)
* 5 - ON (value 5)
* 6 - value 6
* 7 - ON (value 7)
* 8 - value 8
* 9 - ON (value 9)
* 10 - ON (value 10)
* 11 - ON (value 11)
* 12 - ON (value 12)
* 13 - value 13
* 14 - OFF (value 14)
* 15 - value 15

There are a number of ways to detect the commandId values for your device.
#### Examples

- You can turn on DEBUG messages for the rfxcom binding by adding the line
`<Logger level="DEBUG" name="org.openhab.binding.rfxcom"/>`
to your `log4j2.xml`. You will then be able to see the commandId in the log
file when you trigger the device.

- You can link a Number Item to the commandId channel. The item will be updated with the
detected commandId when you trigger the device.

- You can use RFXmngr to look at the data from the device. Use the last letter/number
of the hexadecimal "Code", and convert it from hexadecimal to decimal.
The support for lighting 4 in RFXCOM is less complete because a lot of different devices use the same chips and can not easily be distinguished.

#### Examples
So some extra configuration can be used for fine tuning the behavior of your Lighting4 devices.
When configuring, three extra fields are available, being the the pulse length, and a separate command id for both on and off.
If your item is auto-discovered normally the on or off command should be recognized properly.

For a USB attached RFXCOM on Windows the configuration could look like this (note the `pulse` is optional):
For a USB attached RFXCOM on Windows the configuration could look like this (note that the `onCommandId`, `offCommandId` and `pulse` are all optional):

```
Bridge rfxcom:bridge:238adf67 [ serialPort="COM4" ] {
Thing lighting4 17745a [deviceId="17745", subType="PT2262", onCommandId=7, offCommandId=4]
Thing lighting4 17745b [deviceId="17745", subType="PT2262", onCommandId=10, offCommandId=2]
Thing lighting4 17745 [deviceId="17745", subType="PT2262", onCommandId=7, offCommandId=4, pulse=800]
Thing lighting4 motion [deviceId="286169", subType="PT2262", onCommandId=9, pulse=392]
}
```

Your items file could look like this:

```
Number SocketCommandId {channel="rfxcom:lighting4:238adf67:17745a:commandId"}
Switch SocketA {channel="rfxcom:lighting4:238adf67:17745a:command"}
Switch SocketB {channel="rfxcom:lighting4:238adf67:17745b:command"}
Switch Switch {channel="rfxcom:lighting4:238adf67:17745:command"}
Number SwitchCommandId "Command ID [%d]" {channel="rfxcom:lighting4:238adf67:17745:commandId"}
```

#### Known commandIds

These are some commandIds from the field that may match your devices.

| Brand | What | Action | Command ID | Source |
|-------|---------------|-------------|------------|--------|
| Kerui | Motion Sensor | Motion | 10 | [#3103](https://github.com/openhab/openhab-addons/issues/3103) |
| Kerui | Door Contact | door open | 14 | [#3103](https://github.com/openhab/openhab-addons/issues/3103) |
| Kerui | Door Contact | door closed | 7 | [#3103](https://github.com/openhab/openhab-addons/issues/3103) |
| Kerui | Door Contact | tamper | 11 | [#3103](https://github.com/openhab/openhab-addons/issues/3103) |
| Energenie | 4 Socket Power Bar | Socket 1 on | 15 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | Socket 1 off | 14 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | Socket 2 on | 7 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | Socket 2 off | 6 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | Socket 3 on | 11 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | Socket 3 off | 10 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | Socket 4 on | 3 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | Socket 4 off | 2 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | All on | 13 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
| Energenie | 4 Socket Power Bar | All off | 12 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) |
And if you want random actions on your relay you could for example do like this:

```
rule "Set random relay variations"
when
System started or
Time cron "/20 * * * * ?"
then
SwitchCommandId.sendCommand((Math::random * 15.9).intValue)
end
```

#### Devices:

| Brand | What | Action | Command ID | Supported | Source |
|-------|---------------|-------------|------------|-----------|--------|
| Kerui | Motion Sensor | Motion | 10 | as ON | [#3103](https://github.com/openhab/openhab-addons/issues/3103) |
| Kerui | Door Contact | door open | 14 | as OFF | [#3103](https://github.com/openhab/openhab-addons/issues/3103) |
| Kerui | Door Contact | door closed | 7 | as ON | [#3103](https://github.com/openhab/openhab-addons/issues/3103) |
| Kerui | Door Contact | tamper | 7 | as ON | [#3103](https://github.com/openhab/openhab-addons/issues/3103) |

### lighting5 - RFXCOM Lighting5 Actuator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ public class RFXComLighting4DeviceConfiguration extends RFXComGenericDeviceConfi
public static final String PULSE_LABEL = "pulse";
public static final String ON_COMMAND_ID_LABEL = "onCommandId";
public static final String OFF_COMMAND_ID_LABEL = "offCommandId";
public static final String OPEN_COMMAND_ID_LABEL = "openCommandId";
public static final String CLOSED_COMMAND_ID_LABEL = "closedCommandId";
public Integer pulse;
public Integer onCommandId;
public Integer offCommandId;
public Integer openCommandId;
public Integer closedCommandId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ public synchronized void send() throws IOException {
RFXComBaseMessage msg = queue.peek();

try {
logger.debug("Transmitting message '{}'", msg);
byte[] data = msg.decodeMessage();
if (logger.isDebugEnabled()) {
logger.debug("Transmitting bytes '{}' for message '{}'", HexUtils.bytesToHex(data), msg);
}
connector.sendMessage(data);
break;
} catch (RFXComException rfxe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ public void handleCommand(ChannelUID channelUID, Command command) {
PacketType packetType = RFXComMessageFactoryImpl
.convertPacketType(getThing().getThingTypeUID().getId().toUpperCase());

RFXComMessage msg = messageFactory.createMessage(packetType, config, channelUID, command);
RFXComMessage msg = messageFactory.createMessage(packetType);

msg.setConfig(config);
msg.convertFromState(channelUID.getId(), command);

bridgeHandler.sendMessage(msg);
} catch (RFXComMessageNotImplementedException e) {
Expand Down Expand Up @@ -177,9 +180,9 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComDeviceMessage message
try {
if (config.matchesMessage(message)) {
String receivedId = PACKET_TYPE_THING_TYPE_UID_MAP.get(message.getPacketType()).getId();
logger.debug("Received message from bridge: {} message: {}", bridge, message);

if (receivedId.equals(getThing().getThingTypeUID().getId())) {
logger.debug("Message from bridge [{}] matches thing [{}] message: {}", bridge,
getThing().getUID().toString(), message);
updateStatus(ThingStatus.ONLINE);

for (Channel channel : getThing().getChannels()) {
Expand All @@ -191,21 +194,19 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComDeviceMessage message
case CHANNEL_COMMAND:
case CHANNEL_CHIME_SOUND:
case CHANNEL_MOOD:
postNullableCommand(uid, message.convertToCommand(channelId, config, this));
postNullableCommand(uid, message.convertToCommand(channelId, this));
break;

case CHANNEL_LOW_BATTERY:
updateNullableState(uid,
isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL, config, this)));
isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL, this)));
break;

default:
updateNullableState(uid, message.convertToState(channelId, config, this));
updateNullableState(uid, message.convertToState(channelId, this));
break;
}
} catch (RFXComInvalidStateException e) {
logger.trace("{} not configured for {}", channelId, message);
} catch (RFXComUnsupportedChannelException e) {
} catch (RFXComException e) {
logger.trace("{} does not handle {}", channelId, message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;

import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
Expand Down Expand Up @@ -126,14 +124,13 @@ public String getDeviceId() {
}

@Override
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
if (CHANNEL_FOOD_TEMPERATURE.equals(channelId)) {
return new DecimalType(foodTemperature);
} else if (CHANNEL_BBQ_TEMPERATURE.equals(channelId)) {
return new DecimalType(bbqTemperature);
} else {
return super.convertToState(channelId, config, deviceState);
return super.convertToState(channelId, deviceState);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_BATTERY_LEVEL;

import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
import org.openhab.core.library.types.DecimalType;
Expand All @@ -38,14 +36,13 @@ abstract class RFXComBatteryDeviceMessage<T> extends RFXComDeviceMessageImpl<T>
}

@Override
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
switch (channelId) {
case CHANNEL_BATTERY_LEVEL:
return convertBatteryLevelToSystemWideLevel(batteryLevel);

default:
return super.convertToState(channelId, config, deviceState);
return super.convertToState(channelId, deviceState);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;

import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
Expand Down Expand Up @@ -176,12 +174,11 @@ public String getDeviceId() {
}

@Override
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
if (CHANNEL_COMMAND.equals(channelId)) {
return (command == Commands.CLOSE ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
} else {
return super.convertToState(channelId, config, deviceState);
return super.convertToState(channelId, deviceState);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_CHIME_SOUND;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;

import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
Expand Down Expand Up @@ -135,12 +133,11 @@ public String getDeviceId() {
}

@Override
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
if (CHANNEL_CHIME_SOUND.equals(channelId)) {
return new DecimalType(chimeSound);
} else {
return super.convertToState(channelId, config, deviceState);
return super.convertToState(channelId, deviceState);
}
}

Expand Down
Loading

0 comments on commit 9492e4d

Please sign in to comment.