RfxTrx motion sensor is always on

Hi!

I had about 10 RfxTrx motion sensors set up in Home Assistant at the beginning of 2020. During the summer I neglected my Home Assistant. Now, that I have time for it again, checked how things are, and, of course, it all fell apart, as it usually happens with the passing of time.

The way RfxTrx is handled has changed. Used to be set up from yaml config, now it’s an “integration”. By setting the integration into a mode when devices are added automatically I can get my RfxTrx motion sensors recognized, however they are always on, they never turn off. This is a problem which existed before, but in the yaml I used ot be able to specify an “off_delay” which turned them off after 20 seconds of no motion. On the RfxTrx integration UI this cannot be done (and a lot of other things either).

So I tried to also add the RfxTrx into the yaml, like this:

rfxtrx:
  device: /dev/ttyUSB0
  devices:
    binary_sensor.living_room_motion_sensor:
      off_delay: 20
      device_class: motion

The config is valid and there are no erros in the log, but this does not do a darn thing, like it used to in the past. Note that the device id (binary_sensor.living_room_motion_sensor) was taken from the developer tools -> states section after I have renamed the binary sensor in the list of devices of the RfxTrx integration.

So does anybody know how to correctly configure an RfxTrx motion sensor with the new Home Assistant?

It looks like Off Delay is an option you can configure via the GUI if you go back to using the config-flow version of the integration. Have you tried configuring it like this?
(Link below is to the Device Configuration options part of the documentation, where this option is)



Alternatively, you can create Template Binary Sensors for all of your RfxTrx motion sensors, since those also have a delay_off parameter which does the same thing. However this is a bit of an ugly way to do it.

Thank you! What is “the config flow version of the integration”? Can you elaborate a bit? Do you mean configuring from the yaml, not from the UI? If yes, how do I “go back” to it?

So you called the new GUI based method an “integration”. In really, they’ve always been called integrations. Whether you can figure it via the GUI or via YAML, it’s still an integration.
The new method of configuring an integration via the GUI is called configuration flow, or config flow.

To go back to config flow, you should just be able to delete the YAML configuration that you have, restart home assistant, then add it back in the way you did the first time via the GUI.

@Silicon_Avatar Thank you for explaining! Yes, it makes sense, an integration is just what the name says, an integration with a type of hardware or with a service, and then you can configure it either via yaml ot via GUI.

I have deleted the RfxTrx related configurations from yaml, restarted HA. If I try to configure any RfxTrx device from the GUI (Configuration -> Integrations -> RfxTrx -> Options -> Select device to configure), I always get this:

Unknown error occured

RfxTrxConfigureUnknownError

In the log I see this:

Logger: aiohttp.server
Source: components/rfxtrx/__init__.py:335
First occurred: 9:22:22 AM (4 occurrences)
Last logged: 9:51:30 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 172, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 233, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 106, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 153, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 201, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/rfxtrx/config_flow.py", line 96, in async_step_prompt_options
    return await self.async_step_set_device_options()
  File "/usr/src/homeassistant/homeassistant/components/rfxtrx/config_flow.py", line 285, in async_step_set_device_options
    devices = {
  File "/usr/src/homeassistant/homeassistant/components/rfxtrx/config_flow.py", line 288, in <dictcomp>
    if self._can_replace_device(entry.id)
  File "/usr/src/homeassistant/homeassistant/components/rfxtrx/config_flow.py", line 363, in _can_replace_device
    rfx_obj = get_rfx_object(event_code)
  File "/usr/src/homeassistant/homeassistant/components/rfxtrx/__init__.py", line 335, in get_rfx_object
    binarypacket = bytearray.fromhex(packetid)
TypeError: fromhex() argument must be str, not None

The reason why I did not find earlier this way of configuring the RfxTrx devices from the GUI is that (in my opinion) the GUI is extremely counterintuitive. I mean that UIs that normal users are used to don’t do configuration like this:

RfxTrxConfigUI1

Instead a “normal” intuitive UI would work like this:

Having an “Options” button on the integration widget suggests that you can configure the global integration options, not the devices individually. It’s just not good UI design, if you ask me. I understand that the current approach has the advantage of being able to configure or delete multiple devices together, but buttons next to each device should still be available to configure or delete a single device. I have wasted hours because of this counterintuitive UI design…

2 Likes

I agree it would be more intuitive to have it somewhere at the device list or maybe device page. That however needs infrastructure in the core which someone needs to make…

@Raarr mentioned here a similar issue you encounter: RFXTRX - Unknown error occurred when trying to configure (existing) device - update 0.117
Your logging is more detailed. I can see where it goes wrong, that is a bug and needs fixing. If you want you can submit an issue to Github (for traceability), but I’ll make a PR anyway to fix it.

2 Likes

@RobBie1221 Thank you very much for confirming that this is a bug and for reporting it “officially”. while it’s getting fixed, I’ll try to delete the whole RfxTrx integration, re-add it and start from scratch, see if it solves the problem…

You’d have to rename everything again. There is is “workaround”, go to the devices that you can configure and determine which ones are missing between that list and the list of devices in the UI. The ones that are missing you need to manually add again through the UI with the event code (from e.g. old configuration.yaml). When the device list there is complete (number of devices matches that in the UI) you won’t get the error anymore.

I have deleted the whole integration and added it again form the UI, now it works! The one thing that I can’t seem to be able to set from the UI is the device class. Eg. the motion sensors are just binary sensors, canot specify that they are motion sensors.

Still problems… If I add a single RfxTrx PT2262 motions sensor and I configure the off delay for it, everything works fine. But as soon as a second one is added, things stop working. HA does not show the motion sensors turning on and off, moreover, the motion sensors themselves physically seem to get confused, some of them don’t physically work anymore (the LED is not lighting up on them when there is motion). Something is really fishy here…

Setting device class from the integration is deprecated since 0.117, it should be set using customization:

1 Like

Anything in the logs here?
Could you check in the .storage folder what is in core.config_entries for the rfxtrx integration?

Thanks! Yes, the Customization solves the device class problem.

Multple RfxTrx PT2622 motion sensors still don’t work.

After adding just the living room sensor, I set the off delay like this:

Turns on and off as expected, both in HA and physically (The LED on the sensor).

After adding a second one, the kitchen motion sensor, both of them get screwed up:

  1. Living room sensor is always off both in HA and physically.
  2. Kitchen sensor is always on in HA, turns on/off normally physically.

Nothing in the HA logs about this.

.storage/core.config_entires for RfxTrx looks like this:

{
	"entry_id": "70ff11bc920c1c79abeeca2a7c956e10",
	"version": 1,
	"domain": "rfxtrx",
	"title": "RFXTRX",
	"data": {
		"host": null,
		"port": null,
		"device": "/dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1R3NR7-if00-port0",
		"automatic_add": true,
		"devices": {
			"0a520a00660100c5340189": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"a",
					"66:01"
				]
			},
			"0a520d01880300c93d0189": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"d",
					"88:03"
				]
			},
			"0a520a027f0100e02b0179": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"a",
					"7f:01"
				]
			},
			"0a520d03bc0200c1390179": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"d",
					"bc:02"
				]
			},
			"0a520d04870300b33b0179": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"d",
					"87:03"
				]
			},
			"0a520d06f30100b23e0179": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"d",
					"f3:01"
				]
			},
			"0a520d04430300b03d0169": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"d",
					"43:03"
				]
			},
			"0b11000165bc0cfe01010f70": {
				"device_id": [
					"11",
					"0",
					"65bc0cfe:1"
				],
				"fire_event": false,
				"signal_repetitions": 3
			},
			"0b11000448bc0cfe09010f70": {
				"device_id": [
					"11",
					"0",
					"48bc0cfe:9"
				],
				"fire_event": false,
				"signal_repetitions": 3
			},
			"09130001481c46019180": {
				"device_id": [
					"13",
					"0",
					"481c46"
				],
				"fire_event": true,
				"signal_repetitions": 1,
				"off_delay": 10
			},
			"0a520d04400181f4f10369": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"d",
					"40:01"
				]
			},
			"0a520d0c400381f4f90369": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"52",
					"d",
					"40:03"
				]
			},
			"0913001e8c3446019180": {
				"device_id": [
					"13",
					"0",
					"8c3446"
				],
				"fire_event": true,
				"signal_repetitions": 1,
				"off_delay": 10
			},
			"0913002393f846018e70": {
				"fire_event": false,
				"signal_repetitions": 1,
				"device_id": [
					"13",
					"0",
					"93f846"
				]
			}
		}
	}
	"options": {},
	"system_options": {
		"disable_new_entities": false
	},
	"source": "user",
	"connection_class": "local_push",
	"unique_id": "rfxtrx"
},

The ones that matter are the ones with off_delay set to 10:

			"09130001481c46019180": {
				"device_id": [
					"13",
					"0",
					"481c46"
				],
				"fire_event": true,
				"signal_repetitions": 1,
				"off_delay": 10
			},			
			"0913001e8c3446019180": {
				"device_id": [
					"13",
					"0",
					"8c3446"
				],
				"fire_event": true,
				"signal_repetitions": 1,
				"off_delay": 10
			},

What do you see when enabling debugging (see below)? Do you still see the events from both sensors? If yes, could you post debug output?

logger:
  logs:
    RFXtrx: debug

I think I might have figured it out… the motion sensors start behaving as expected after taking the RfxTrx integration out of “learning mode”. I mean after unchecking the option to auto-add new devices. Not sure, I think it might also be necessary to restart HA. In the “learning mode” new RfxTrx devices get added, but the whole system gets confused and they don’t work properly.

As for why the sensors physically stop working for a while, I found the explanation in their manual: after 3 consecutive detections within a short period of time, they go into sleep mode for 3 minutes, to save battery (and they don’t detect anything). After 3 minutes they start working normally again.

I’ve noticed that after every small update 0.117.2, 0.117.3 etc the RFX devices become unavailable.

A full reboot doesn’t work. Restarting the VM worked last time… going to try it again.

From 0.117.4 to 0.117.5 the same thing happened. A reboot of the entire VM is necessary!

Also it looks like after the update from 117.4 to 1117.5 (or after a reboot?) all custom entity names for RfxTrx have been reset to default and all automations and everything that used those entity names have broken. For example I renamed the “Living room motion sensor” simply to “Living room motion”, now it’s reset.