ff-akwarium-plug-01.yaml 4.5 KB

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