def switch_toggle_loop(): """Toggle the switch on all devices in the directory""" global switch_state if Registry.size() > 0 and sendSwitchTimer.check(): print("transmit") radio.transmitter() for sensorid in Registry.get_sensorids(): # Only try to toggle the switch for devices that actually have a switch header = Registry.get_info(sensorid)["header"] mfrid = header["mfrid"] productid = header["productid"] if Devices.hasSwitch(mfrid, productid): request = OpenThings.alterMessage(Messages.SWITCH, header_sensorid=sensorid, recs_0_value=switch_state) p = OpenThings.encode(request) print("Sending switch message to %s %s" % (hex(productid), hex(sensorid))) # Transmit multiple times, hope one of them gets through radio.transmit(p, inner_times=2) radio.receiver() switch_state = (switch_state + 1) % 2 # toggle
def switch_toggle_loop(): """Toggle the switch on all devices in the directory""" global switch_state if Registry.size() > 0 and sendSwitchTimer.check(): print("transmit") radio.transmitter() for sensorid in Registry.get_sensorids(): # Only try to toggle the switch for devices that actually have a switch header = Registry.get_info(sensorid)["header"] mfrid = header["mfrid"] productid = header["productid"] if Devices.hasSwitch(mfrid, productid): request = OpenThings.alterMessage(Messages.SWITCH, header_sensorid=sensorid, recs_0_value=switch_state) p = OpenThings.encode(request) print("Sending switch message to %s %s" % (hex(productid), hex(sensorid))) # Transmit multiple times, hope one of them gets through radio.transmit(p, inner_times=2) radio.receiver() switch_state = (switch_state+1) % 2 # toggle
def send_join_ack(mfrid, productid, sensorid): # send back a JOIN ACK, so that join light stops flashing response = OpenThings.alterMessage(Messages.JOIN_ACK, header_mfrid=mfrid, header_productid=productid, header_sensorid=sensorid) p = OpenThings.encode(response) radio.transmitter() radio.transmit(p) radio.receiver()
# # NOTE: This is only a test harness. # If you really want a nice way to control these devices, wait for the 'device classes' # issues to be implemented and tested on top of the raw radio interface, as these # will be much nicer to use. import time from energenie import Messages, OpenThings, radio, encoder, Devices # build FSK messages for MiHome purple OpenThings.init(Devices.CRYPT_PID) PURPLE_ID = 0x68B # captured from a real device using Monitor.py m = OpenThings.alterMessage( Messages.SWITCH, header_sensorid=PURPLE_ID, recs_0_value=1) purple_on = OpenThings.encode(m) m = OpenThings.alterMessage( Messages.SWITCH, header_sensorid=PURPLE_ID, recs_0_value=0) purple_off = OpenThings.encode(m) # build OOK messages for legacy green button GREEN_ON = encoder.build_switch_msg(True, device_address=1) GREEN_OFF = encoder.build_switch_msg(False, device_address=1)
radio.receiver() switch_state = (switch_state + 1) % 2 # toggle if __name__ == "__main__": trace("starting switch tester") radio.init() OpenThings.init(Devices.CRYPT_PID) # Seed the registry with a known device, to simplify tx-only testing SENSOR_ID = 0x68B # captured from a real device device_header = OpenThings.alterMessage( Messages.REGISTERED_SENSOR, header_mfrid=Devices.MFRID, header_productid=Devices.PRODUCTID_MIHO005, # adaptor plus header_sensorid=SENSOR_ID) Registry.update(device_header) sendSwitchTimer = Timer(TX_RATE, 1) # every n seconds offset by initial 1 switch_state = 0 # OFF radio.receiver() try: while True: switch_sniff_loop() switch_toggle_loop() finally: radio.finished()
radio.transmit(p, inner_times=2) radio.receiver() switch_state = (switch_state+1) % 2 # toggle if __name__ == "__main__": trace("starting switch tester") radio.init() OpenThings.init(Devices.CRYPT_PID) # Seed the registry with a known device, to simplify tx-only testing SENSOR_ID = 0x68B # captured from a real device device_header = OpenThings.alterMessage(Messages.REGISTERED_SENSOR, header_mfrid = Devices.MFRID, header_productid = Devices.PRODUCTID_MIHO005, # adaptor plus header_sensorid = SENSOR_ID) Registry.update(device_header) sendSwitchTimer = Timer(TX_RATE, 1) # every n seconds offset by initial 1 switch_state = 0 # OFF radio.receiver() try: while True: switch_sniff_loop() switch_toggle_loop() finally: radio.finished()