kipe / enocean

Python library for EnOcean serial protocol
MIT License
72 stars 103 forks source link

Switching on a light to replicate a PTM215 switch #126

Open rnusser opened 3 years ago

rnusser commented 3 years ago

Although this project might be abandoned, I was hoping someone would be able to help me getting this code to work.

I am unable to get any lights to switch on or off. I have changed the assemble_radio_packet function in enocean_example.py to the following:

def assemble_radio_packet(transmitter_id):
    return RadioPacket.create(
            rorg=0xF6,
            rorg_func=0x02,
            rorg_type=0x02,
            sender=[0xfe, 0xf2, 0x86, 0x22],
            R1='Button AI',
            EB='pressed',
            T21=True,
            NU=True)

When I run the program the output is almost identical to the actual debug info I get when physically activating the switch:

This is the output wen the function is called to switch off the light:

2021-11-16 17:24:27,323 - enocean.protocol.packet - WARNING - Replacing destination with broadcast address.
2021-11-16 17:24:27,429 - enocean.communicators.SerialCommunicator - INFO - Sending packet
2021-11-16 17:24:27,432 - enocean.communicators.SerialCommunicator - DEBUG - FE:F2:86:22->FF:FF:FF:FF (-255 dBm): 0x01 ['0xf6', '0x10', '0xfe', '0xf2', '0x86', '0x22', '0x30'] ['0x3', '0xff', '0xff', '0xff', '0xff', '0xff', '0x0'] OrderedDict([
('R1', {'description': 'Rocker 1st action', 'unit': '', 'value': 'Button AI', 'raw_value': 0}), 
('EB', {'description': 'Energy bow', 'unit': '', 'value': 'pressed', 'raw_value': 1}), 
('R2', {'description': 'Rocker 2nd action', 'unit': '', 'value': 'Button AI', 'raw_value': 0}), 
('SA', {'description': '2nd action', 'unit': '', 'value': 'No 2nd action', 'raw_value': 0}), 
('T21', {'description': 'T21', 'unit': '', 'value': True, 'raw_value': 1}), 
('NU', {'description': 'NU', 'unit': '', 'value': True, 'raw_value': 1})])
2021-11-16 17:24:27,542 - enocean.communicators.SerialCommunicator - DEBUG - 0x02 ['0x0'] [] OrderedDict()

And here is the debug output when pressing the switch manually to switch off the light:

2021-11-16 17:16:27,938 - enocean.communicators.SerialCommunicator - DEBUG - FE:F2:86:22->FF:FF:FF:FF (-64 dBm): 0x01 ['0xf6', '0x10', '0xfe', '0xf2', '0x86', '0x22', '0x30'] ['0x0', '0xff', '0xff', '0xff', '0xff', '0x40', '0x0'] OrderedDict()
R1: {'description': 'Rocker 1st action', 'unit': '', 'value': 'Button AI', 'raw_value': 0}
EB: {'description': 'Energy bow', 'unit': '', 'value': 'pressed', 'raw_value': 1}
R2: {'description': 'Rocker 2nd action', 'unit': '', 'value': 'Button AI', 'raw_value': 0}
SA: {'description': '2nd action', 'unit': '', 'value': 'No 2nd action', 'raw_value': 0}
T21: {'description': 'T21', 'unit': '', 'value': True, 'raw_value': 1}
NU: {'description': 'NU', 'unit': '', 'value': True, 'raw_value': 1}

The second list of values start with a 0x0 when coming from the light switch, and a 0x3 when sent by the function. This could be the repeater_count, but I am not sure.

Has anyone got one of these switches working?

zpfvo commented 3 years ago

You can't set the sender id to anything you want. You need to read out your base id and set the sender id in the range of BASE_ID -> BASE_ID + 0x80. You need to teach in your actor with the base id of your enocean dongle + transmitter offset.

rnusser commented 3 years ago

I thought the sender ID is the ID of the switch I saw in the debug output FE:F2:86:22->FF:FF:FF:FF.

So the address is not spoofed, is is actually the address of the hardware sending the message that counts (the dongle)?

I see, so for the second point if I teach the actor the ID, I suppose I can no longer use the mechanical switch. I would probably have to received messages sent by the switch and send them out from the dongle?

zpfvo commented 3 years ago

So the address is not spoofed, is is actually the address of the hardware sending the message that counts (the dongle)?

Yes, you can only send with your EURID (unique id) or within the range of your base id + 0x80. Iam not sure if the dongle sends something anything out if the sender id is not set correctly.

I see, so for the second point if I teach the actor the ID, I suppose I can no longer use the mechanical switch. I would probably have to received messages sent by the switch and send them out from the dongle?

Most actors can learn multiple sender ids they react to. If not, then yes you'll have to listen for the switch and then send the command again with the id of your dongle.