bchmura

Untitled

Sep 19th, 2025
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. esphome:
  2. name: esphome-web-259684
  3. friendly_name: CatWheel
  4. min_version: 2025.5.0
  5. name_add_mac_suffix: false
  6.  
  7. esp32:
  8. board: esp32dev
  9. framework:
  10. type: arduino
  11.  
  12.  
  13. # Enable logging
  14. logger:
  15. level: VERBOSE
  16. logs:
  17. i2s_audio: VERBOSE
  18. media_player: VERBOSE
  19.  
  20. # Enable Home Assistant API
  21. api:
  22.  
  23. # Allow Over-The-Air updates
  24. ota:
  25. - platform: esphome
  26.  
  27. wifi:
  28. ssid: !secret wifi_ssid
  29. password: !secret wifi_password
  30.  
  31. ### These globals are unrelated to the audio problem
  32. globals:
  33. - id: inch_this_run_counter
  34. type: int
  35. restore_value: no
  36. initial_value: '0'
  37.  
  38. - id: inch_total_run_counter
  39. type: int
  40. restore_value: yes
  41. initial_value: '0'
  42.  
  43. output:
  44. - platform: gpio
  45. pin: GPIO21 # or whatever GPIO pin your LED is on
  46. id: status_led
  47.  
  48. # - platform: ledc
  49. # pin: GPIO27
  50. # id: test_tone
  51. # frequency: 1000Hz
  52.  
  53. i2s_audio:
  54. - id: i2s_bus_out
  55. i2s_lrclk_pin: GPIO27 # These are just clock signals, any available GPIO
  56. i2s_bclk_pin: GPIO26 # These don't go to your amplifier
  57.  
  58.  
  59. speaker:
  60. - platform: i2s_audio
  61. id: my_speaker
  62. dac_type: external
  63. i2s_audio_id: i2s_bus_out
  64. i2s_dout_pin: GPIO22 # This goes to L or R input on amplifier
  65. channel: mono
  66. bits_per_sample: 16bit
  67. sample_rate: 16000 # And optionally this
  68. #i2s_mode: secondary # Claude suggested some boards need this during troubleshooting
  69.  
  70.  
  71. #media_player:
  72. # - platform: i2s_audio
  73. # id: media_out
  74. # dac_type: external
  75. # i2s_audio_id: i2s_bus_out
  76. # i2s_dout_pin: GPIO27
  77. # mode: mono
  78.  
  79. binary_sensor:
  80. - platform: gpio
  81. pin: GPIO19
  82. name: "Hall Effect Sensor"
  83. id: hall_sensor
  84. device_class: opening
  85. filters:
  86. - delayed_on: 5ms
  87. #on_state:
  88. # - logger.log:
  89. # format: "Hall sensor state changed to: %s"
  90. # args: [ 'x ? "ON" : "OFF"' ]
  91. on_press:
  92. - globals.set:
  93. id: inch_this_run_counter
  94. value: !lambda 'return id(inch_this_run_counter) + 135;'
  95. - globals.set:
  96. id: inch_total_run_counter
  97. value: !lambda 'return id(inch_total_run_counter) + 135;'
  98. - light.turn_on:
  99. id: led
  100. flash_length: 500ms # blink for 500ms then turn off
  101. - binary_sensor.template.publish:
  102. id: wheel_moving
  103. state: ON
  104. - delay: 30s
  105. - binary_sensor.template.publish:
  106. id: wheel_moving
  107. state: OFF
  108. - delay: 90s
  109. - globals.set:
  110. id: inch_this_run_counter
  111. value: '0'
  112. - component.update: inches_run_this_run_sensor
  113. - component.update: feet_run_this_run_sensor
  114.  
  115. - platform: template
  116. name: "WheelMoving"
  117. id: wheel_moving
  118. device_class: motion
  119.  
  120. - platform: gpio
  121. pin:
  122. number: 03
  123. mode:
  124. input: true
  125. pullup: true
  126. id: reset_button
  127. name: "Reset button"
  128. #use_interrupt: true # Default - uses interrupts
  129. #interrupt_type: FALLING # Only detect low-to-high transitio
  130. on_press:
  131. - speaker.play:
  132. id: my_speaker
  133. data: !lambda |-
  134. std::vector<uint8_t> data;
  135. for (int i = 0; i < 10000; i++) {
  136. int freq = i / 50; // Increasing frequency
  137. data.push_back((i / (20 - freq/10)) % 2 ? 250 : 5);
  138. }
  139. return data;
  140. # - media_player.play_media:
  141. # id: media_out
  142. # #media_url: "https://birdnet.cornell.edu/files/2019/01/BirdNET_01_XC169082.wav"
  143. # media_url: "https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3"
  144. - globals.set:
  145. id: inch_this_run_counter
  146. value: '0'
  147. - globals.set:
  148. id: inch_total_run_counter
  149. value: '0'
  150. - logger.log:
  151. format: "Reset pressed"
  152. - light.turn_on:
  153. id: led
  154. flash_length: 500ms # blink for 500ms then turn off
  155. - delay: 700ms
  156. - light.turn_on:
  157. id: led
  158. flash_length: 500ms # blink for 500ms then turn off
  159. - delay: 700ms
  160. - light.turn_on:
  161. id: led
  162. flash_length: 500ms # blink for 500ms then turn off
  163.  
  164. light:
  165. - platform: binary
  166. output: status_led
  167. id: led
  168. name: "Status LED"
  169.  
  170. # Wheel is 42.5 inches on the inside diameter
  171. # 2 pi R is 2 * 3.14 * 21.25 = 135 inches long for each trip
  172.  
  173.  
  174.  
  175. sensor:
  176. - platform: template
  177. name: "Inches run this run"
  178. id: inches_run_this_run_sensor
  179. accuracy_decimals: 0
  180. lambda: 'return id(inch_this_run_counter);'
  181.  
  182. - platform: template
  183. name: "Feet run this run"
  184. id: feet_run_this_run_sensor
  185. accuracy_decimals: 1
  186. lambda: 'return id(inch_this_run_counter) / 12.0;'
  187.  
  188. - platform: template
  189. name: "Inches total run"
  190. id: inches_total_run_sensor
  191. accuracy_decimals: 0
  192. lambda: 'return id(inch_total_run_counter);'
  193.  
  194. - platform: template
  195. name: "Feet total run"
  196. id: feet_total_run_sensor
  197. accuracy_decimals: 1
  198. lambda: 'return id(inch_total_run_counter) / 12.0;'
  199.  
  200. interval:
  201. - interval: 1s
  202. then:
  203. - if:
  204. condition:
  205. binary_sensor.is_on: wheel_moving
  206. then:
  207. - component.update: inches_run_this_run_sensor
  208. - component.update: feet_run_this_run_sensor
  209. - component.update: inches_total_run_sensor
  210. - component.update: feet_total_run_sensor
  211.  
Advertisement
Add Comment
Please, Sign In to add comment