A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.0 KiB

  1. import time
  2. from alarmdecoder import AlarmDecoder
  3. from alarmdecoder.devices import SerialDevice
  4. # Configuration values
  5. TARGET_ZONE = 41
  6. WAIT_TIME = 10
  7. SERIAL_DEVICE = '/dev/ttyUSB0'
  8. BAUDRATE = 115200
  9. def main():
  10. """
  11. Example application that periodically faults a virtual zone and then
  12. restores it.
  13. This is an advanced feature that allows you to emulate a virtual zone. When
  14. the AlarmDecoder is configured to emulate a zone expander we can fault and
  15. restore those zones programmatically at will. These events can also be seen by
  16. others, such as home automation platforms which allows you to connect other
  17. devices or services and monitor them as you would any physical zone.
  18. For example, you could connect a ZigBee device and receiver and fault or
  19. restore it's zone(s) based on the data received.
  20. In order for this to happen you need to perform a couple configuration steps:
  21. 1. Enable zone expander emulation on your AlarmDecoder device by hitting '!'
  22. in a terminal and going through the prompts.
  23. 2. Enable the zone expander in your panel programming.
  24. """
  25. try:
  26. # Retrieve the first USB device
  27. device = AlarmDecoder(SerialDevice(interface=SERIAL_DEVICE))
  28. # Set up an event handlers and open the device
  29. device.on_zone_fault += handle_zone_fault
  30. device.on_zone_restore += handle_zone_restore
  31. with device.open(baudrate=BAUDRATE):
  32. last_update = time.time()
  33. while True:
  34. if time.time() - last_update > WAIT_TIME:
  35. last_update = time.time()
  36. device.fault_zone(TARGET_ZONE)
  37. time.sleep(1)
  38. except Exception as ex:
  39. print('Exception:', ex)
  40. def handle_zone_fault(sender, zone):
  41. """
  42. Handles zone fault messages.
  43. """
  44. print('zone faulted', zone)
  45. # Restore the zone
  46. sender.clear_zone(zone)
  47. def handle_zone_restore(sender, zone):
  48. """
  49. Handles zone restore messages.
  50. """
  51. print('zone cleared', zone)
  52. if __name__ == '__main__':
  53. main()