generate.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import yaml
  2. DELAY_RESEND = 488400
  3. DELAY_HOLD_1 = 39800
  4. DELAY_HOLD_N = 95200
  5. PREAMBLE = 9000
  6. PREPAUSE = 4400
  7. PREHOLD = 2200
  8. SIGNAL = 500
  9. PAUSE_1 = 1700
  10. PAUSE_0 = 600
  11. rgbButtonsSingle = {
  12. "on": 0x407F807F,
  13. "off": 0x407F40BF,
  14. "candle": 0x407F8877,
  15. "warm white": 0x407F6897,
  16. "white": 0x407F50AF,
  17. "cold white": 0x407FC03F,
  18. "night": 0x407F48B7,
  19. "sleep": 0x407FE817,
  20. "reading": 0x407FD02F,
  21. "yoga": 0x407F20DF,
  22. "morning": 0x407FC837,
  23. "color wheel": 0x407F18E7,
  24. "random": 0x407F30CF,
  25. "evening": 0x407FA05F,
  26. "trees": 0x407F28D7,
  27. "water": 0x407F9867,
  28. "fire": 0x407FB04F,
  29. "hearts": 0x407F609F,
  30. }
  31. rgbButtonsRepeat = {
  32. "saturate": 0x407F58A7,
  33. "lighter": 0x407FF00F,
  34. "blue": 0x407FA857,
  35. "red": 0x407F708F,
  36. "orange": 0x407FE01F,
  37. "green": 0x407F10EF,
  38. }
  39. def ir_send_rgb(value):
  40. irSignal = [0] * 67
  41. irRepeatDelay = DELAY_RESEND
  42. irSignal[0] = PREAMBLE
  43. irSignal[1] = -PREPAUSE
  44. irSignal[2] = SIGNAL
  45. for i in range(32):
  46. irSignal[65-i*2] = -PAUSE_1 if value & 1<<i else -PAUSE_0
  47. irSignal[66-i*2] = SIGNAL
  48. return irSignal
  49. data = {
  50. 'button': [
  51. {
  52. 'platform': "template",
  53. 'name': key,
  54. 'on_press': [
  55. {
  56. 'remote_transmitter.transmit_raw': {
  57. 'code': ir_send_rgb(value),
  58. 'carrier_frequency': 38_000,
  59. 'repeat': {
  60. 'times': 3,
  61. 'wait_time': "0.5s",
  62. },
  63. }
  64. }
  65. ]
  66. } for key, value in rgbButtonsSingle.items()
  67. ] + [
  68. {
  69. 'platform': "template",
  70. 'name': key,
  71. 'on_press': [
  72. {
  73. 'remote_transmitter.transmit_raw': {
  74. 'code': ir_send_rgb(value),
  75. 'carrier_frequency': 38_000,
  76. 'repeat': {
  77. 'times': 5,
  78. 'wait_time': "0.5s",
  79. },
  80. }
  81. }
  82. ]
  83. } for key, value in rgbButtonsRepeat.items()
  84. ]
  85. }
  86. with open('data.yaml', 'w') as outfile:
  87. yaml.dump(data, outfile, default_flow_style=None)