Danielhiversen/pyRFXtrx

lighting4 switch never actually sending commands

Closed this issue · 4 comments

tldr; clicking a switch with id 09130001155155019c70 in home assistant doesn't result in commands being sent.

I have a few Chacon RF outlets that seem to use the lighting4 protocol. If I enabled that protocol and set automatic add to true in Home Assistant, the switches show up in the panel, but they don't work.

I verified the received commands using RFXmngr:
The id of the switch in HA was 0913 0001 15 51 55 01 9c70
in RFXmngr, I got this matching output:

Packettype = Lighting4
subtype = PT2262
Code = 155155
Pulse: 412 usec
signal level = 8

If I enter the code in the lighting4 tab and toggle the last bit (155154/155155), I can toggle my light on and off.

I then enabled debugging in HA and noticed that no send events occur when I click the switch in HA.
To eliminate a general issue with my setup, I added a switch with an id I found in some example online (0b1100ce3213c7f210010f70). If I click that switch, a send command shows up in the logs.

I'd be happy to help debugging this.

Some HA log output:

Recv: 0x09 0x13 0x00 0x01 0x15 0x51 0x55 0x01 0x9c 0x70
INFO:homeassistant.components.rfxtrx:Automatic add 155155 rfxtrx device (Class: LightingDevice Sub: 0 Packet_id: 09130001155155019c70)
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=switch.09130001155155019c70, old_state=None, new_state=<state switch.09130001155155019c70=off; friendly_name=09130001155155019c70, assumed_state=True @ 2017-08-01T16:55:31.032072+02:00>>

Note: sometimes an 09130002155557019c70 event shows up in the logs, both after on and off commands.

Some more debugging: when clicking "on", this is the internal event which seems ok:

<class 'RFXtrx.ControlEvent'> device=[<class 'RFXtrx.LightingDevice'> type='PT2262' id='155155'] values=[('Command', 'Unknown command (0x155155)'), ('Rssi numeric', 7)]

Digging deeper, it seems that Lighting4 support is missing in https://github.com/Danielhiversen/pyRFXtrx/blob/master/RFXtrx/__init__.py#L187 which then exits silently.

The following changes seem to be enough to get it working:
To the LightingDevice constructor:

        if isinstance(pkt, lowlevel.Lighting4):
            self.cmd = pkt.cmd
            self.pulse = pkt.pulse

To the send_onoff

        elif self.packettype == 0x13:  # Lighting4
            pkt = lowlevel.Lighting4()
            code = self.cmd & ~1
            code |= 0x1 if turn_on else 0x0
            pkt.set_transmit(self.subtype, 0, code, self.pulse)
            transport.send(pkt.data)

I believe the issue I just opened here might be related to this case?

@sunflowerABB yes indeed, there are 2 reasons why so many switches show up when you use autodetect:

  • the sequence number increases each time you press the button and a new switch is created each time
  • after (long) pressing the on or off button, sometimes an extra command is sent which is the same for both buttons.

If you make the changes I presented in my previous comment, and use one of the auto detect codes when pressing the on button (that is not present when pressing off), everything should work.

If there is no response from the author, I'll create a Home Assistant pull request with the changes myself.