ff-akwarium-plug-01.yaml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. substitutions:
  2. devicename: ff-akwarium-plug-01
  3. low_devicename: ff-akwarium-plug-01
  4. friendly_devicename: FF Akwarium Light 01
  5. esphome:
  6. name: $devicename
  7. friendly_name: $friendly_devicename
  8. bk72xx:
  9. board: generic-bk7231t-qfn32-tuya
  10. #framework:
  11. # version: dev
  12. # Enable logging
  13. logger:
  14. web_server:
  15. port: 80
  16. # Enable Home Assistant API
  17. api:
  18. encryption:
  19. key: "ejeMnlF5M60w/yuYwAWn/kIBz701xLwVkUGf9iN8uLA="
  20. ota:
  21. password: "2c27af3ab81f992e23745c20ab5dfc02"
  22. wifi:
  23. ssid: !secret iot_ssid
  24. password: !secret iot_password
  25. domain: .int.mmax.cloud
  26. sensor:
  27. - platform: wifi_signal
  28. name: "WiFi Signal Sensor"
  29. update_interval: 60s
  30. - platform: uptime
  31. name: Uptime Sensor
  32. id: uptime_sensor
  33. update_interval: 60s
  34. on_raw_value:
  35. then:
  36. - text_sensor.template.publish:
  37. id: uptime_human
  38. state: !lambda |-
  39. int seconds = round(id(uptime_sensor).raw_state);
  40. int days = seconds / (24 * 3600);
  41. seconds = seconds % (24 * 3600);
  42. int hours = seconds / 3600;
  43. seconds = seconds % 3600;
  44. int minutes = seconds / 60;
  45. seconds = seconds % 60;
  46. return (
  47. (days ? to_string(days) + "d " : "") +
  48. (hours ? to_string(hours) + "h " : "") +
  49. (minutes ? to_string(minutes) + "m " : "") +
  50. (to_string(seconds) + "s")
  51. ).c_str();
  52. text_sensor:
  53. - platform: template
  54. name: Uptime Human Readable
  55. id: uptime_human
  56. icon: mdi:clock-start
  57. - platform: wifi_info
  58. ip_address:
  59. name: IP Address
  60. entity_category: diagnostic
  61. binary_sensor:
  62. - platform: status
  63. name: Status
  64. entity_category: diagnostic
  65. - platform: gpio
  66. pin:
  67. number: P7
  68. mode:
  69. input: true
  70. pullup: true
  71. inverted: true
  72. name: "Power Button"
  73. on_press:
  74. - switch.toggle: relay
  75. - select.next:
  76. id: mode
  77. cycle: true
  78. switch:
  79. - platform: gpio
  80. # RED
  81. id: led_1
  82. pin:
  83. number: P6
  84. inverted: false
  85. - platform: gpio
  86. # BLUE
  87. id: led_2
  88. pin:
  89. number: P26
  90. inverted: false
  91. - platform: gpio
  92. pin: P8
  93. id: relay
  94. internal: true
  95. # Turn off red LED to show blue when turned on
  96. on_turn_on:
  97. - switch.turn_on: led_2
  98. - switch.turn_off: led_1
  99. # Turns on the red LED once the plug is turned off
  100. on_turn_off:
  101. - switch.turn_off: led_2
  102. - switch.turn_on: led_1
  103. button:
  104. - platform: restart
  105. id: restart_button
  106. name: Restart
  107. entity_category: diagnostic
  108. globals:
  109. - id: current_light
  110. type: select
  111. restore_value: True
  112. initial_value: "0"
  113. select:
  114. - platform: template
  115. name: "Light Mode"
  116. id: mode
  117. options:
  118. - "Off"
  119. - "Day"
  120. - Daybreak
  121. - Night
  122. optimistic: true
  123. on_value:
  124. then:
  125. - if:
  126. condition:
  127. - lambda: |-
  128. return(id(mode).state) == "Off";
  129. then:
  130. - switch.turn_off: relay
  131. - if:
  132. condition:
  133. - lambda: |-
  134. return(id(mode).state) == "Day";
  135. then:
  136. - switch.turn_off: relay
  137. - delay: 20s
  138. - switch.turn_on: relay
  139. - if:
  140. condition:
  141. - lambda: |-
  142. return(id(mode).state) == "Daybreak";
  143. then:
  144. - switch.turn_off: relay
  145. - delay: 20s
  146. - switch.turn_on: relay
  147. - delay: 200ms
  148. - switch.turn_off: relay
  149. - delay: 200ms
  150. - switch.turn_on: relay
  151. - if:
  152. condition:
  153. - lambda: |-
  154. return(id(mode).state) == "Night";
  155. then:
  156. - switch.turn_off: relay
  157. - delay: 20s
  158. - switch.turn_on: relay
  159. - delay: 200ms
  160. - switch.turn_off: relay
  161. - delay: 200ms
  162. - switch.turn_on: relay
  163. - switch.turn_off: relay
  164. - delay: 200ms
  165. - switch.turn_on: relay
  166. light:
  167. - platform: template
  168. name: None
  169. restore_mode: RESTORE_AND_OFF
  170. effects:
  171. - lambda:
  172. name: Day
  173. - lambda:
  174. name: Daybreak
  175. - lambda:
  176. name: Night