ff-akwarium-plug-01.yaml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. inverted: true
  69. mode:
  70. input: true
  71. pullup: true
  72. name: "Power Button"
  73. on_press:
  74. # - output.toggle: relay
  75. - select.next:
  76. id: light_mode
  77. cycle: true
  78. light:
  79. - platform: binary
  80. name: Red LED
  81. id: red_led
  82. output: led_1
  83. internal: True
  84. restore_mode: ALWAYS_OFF
  85. output:
  86. - platform: gpio
  87. # RED
  88. id: led_1
  89. pin:
  90. number: P6
  91. inverted: false
  92. # - platform: gpio
  93. # # BLUE
  94. # id: led_2
  95. status_led:
  96. pin:
  97. number: P26
  98. inverted: false
  99. button:
  100. - platform: restart
  101. id: restart_button
  102. name: Restart
  103. entity_category: diagnostic
  104. globals:
  105. - id: current_light
  106. type: int
  107. initial_value: "0"
  108. select:
  109. - platform: template
  110. name: "Light Mode"
  111. id: light_mode
  112. options:
  113. - "Off"
  114. - "Day"
  115. - "Daybreak"
  116. - "Night"
  117. optimistic: true
  118. on_value:
  119. then:
  120. - if:
  121. condition:
  122. - lambda: |-
  123. return(id(light_mode).state) == "Off";
  124. then:
  125. - switch.turn_off: relay
  126. - if:
  127. condition:
  128. - lambda: |-
  129. return(id(light_mode).state) == "Day";
  130. then:
  131. - switch.turn_off: relay
  132. - delay: 20s
  133. - switch.turn_on: relay
  134. - if:
  135. condition:
  136. - lambda: |-
  137. return(id(light_mode).state) == "Daybreak";
  138. then:
  139. - switch.turn_off: relay
  140. - delay: 20s
  141. - switch.turn_on: relay
  142. - delay: 200ms
  143. - switch.turn_off: relay
  144. - delay: 200ms
  145. - switch.turn_on: relay
  146. - if:
  147. condition:
  148. - lambda: |-
  149. return(id(light_mode).state) == "Night";
  150. then:
  151. - switch.turn_off: relay
  152. - delay: 20s
  153. - switch.turn_on: relay
  154. - delay: 200ms
  155. - switch.turn_off: relay
  156. - delay: 200ms
  157. - switch.turn_on: relay
  158. - switch.turn_off: relay
  159. - delay: 200ms
  160. - switch.turn_on: relay
  161. - lambda: |-
  162. id(current_light) == id(light_mode).active_index();
  163. switch:
  164. - platform: gpio
  165. pin: P8
  166. id: relay
  167. internal: true
  168. restore_mode: ALWAYS_OFF
  169. # Turn off red LED to show blue when turned on
  170. on_turn_on:
  171. - light.turn_on: red_led
  172. # - switch.turn_off: led_1
  173. # Turns on the red LED once the plug is turned off
  174. on_turn_off:
  175. - light.turn_off: red_led
  176. # - switch.turn_on: led_1
  177. # - platform: template
  178. # name: mode
  179. # output: relay
  180. # internal: True
  181. # effects:
  182. # - lambda:
  183. # name: Day
  184. # - lambda:
  185. # name: Daybreak
  186. # - lambda:
  187. # name: Night