Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- esphome:
- name: esphome-web-259684
- friendly_name: CatWheel
- min_version: 2025.5.0
- name_add_mac_suffix: false
- esp32:
- board: esp32dev
- framework:
- type: arduino
- # Enable logging
- logger:
- level: VERBOSE
- logs:
- i2s_audio: VERBOSE
- media_player: VERBOSE
- # Enable Home Assistant API
- api:
- # Allow Over-The-Air updates
- ota:
- - platform: esphome
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- ### These globals are unrelated to the audio problem
- globals:
- - id: inch_this_run_counter
- type: int
- restore_value: no
- initial_value: '0'
- - id: inch_total_run_counter
- type: int
- restore_value: yes
- initial_value: '0'
- output:
- - platform: gpio
- pin: GPIO21 # or whatever GPIO pin your LED is on
- id: status_led
- # - platform: ledc
- # pin: GPIO27
- # id: test_tone
- # frequency: 1000Hz
- i2s_audio:
- - id: i2s_bus_out
- i2s_lrclk_pin: GPIO27 # These are just clock signals, any available GPIO
- i2s_bclk_pin: GPIO26 # These don't go to your amplifier
- speaker:
- - platform: i2s_audio
- id: my_speaker
- dac_type: external
- i2s_audio_id: i2s_bus_out
- i2s_dout_pin: GPIO22 # This goes to L or R input on amplifier
- channel: mono
- bits_per_sample: 16bit
- sample_rate: 16000 # And optionally this
- #i2s_mode: secondary # Claude suggested some boards need this during troubleshooting
- #media_player:
- # - platform: i2s_audio
- # id: media_out
- # dac_type: external
- # i2s_audio_id: i2s_bus_out
- # i2s_dout_pin: GPIO27
- # mode: mono
- binary_sensor:
- - platform: gpio
- pin: GPIO19
- name: "Hall Effect Sensor"
- id: hall_sensor
- device_class: opening
- filters:
- - delayed_on: 5ms
- #on_state:
- # - logger.log:
- # format: "Hall sensor state changed to: %s"
- # args: [ 'x ? "ON" : "OFF"' ]
- on_press:
- - globals.set:
- id: inch_this_run_counter
- value: !lambda 'return id(inch_this_run_counter) + 135;'
- - globals.set:
- id: inch_total_run_counter
- value: !lambda 'return id(inch_total_run_counter) + 135;'
- - light.turn_on:
- id: led
- flash_length: 500ms # blink for 500ms then turn off
- - binary_sensor.template.publish:
- id: wheel_moving
- state: ON
- - delay: 30s
- - binary_sensor.template.publish:
- id: wheel_moving
- state: OFF
- - delay: 90s
- - globals.set:
- id: inch_this_run_counter
- value: '0'
- - component.update: inches_run_this_run_sensor
- - component.update: feet_run_this_run_sensor
- - platform: template
- name: "WheelMoving"
- id: wheel_moving
- device_class: motion
- - platform: gpio
- pin:
- number: 03
- mode:
- input: true
- pullup: true
- id: reset_button
- name: "Reset button"
- #use_interrupt: true # Default - uses interrupts
- #interrupt_type: FALLING # Only detect low-to-high transitio
- on_press:
- - speaker.play:
- id: my_speaker
- data: !lambda |-
- std::vector<uint8_t> data;
- for (int i = 0; i < 10000; i++) {
- int freq = i / 50; // Increasing frequency
- data.push_back((i / (20 - freq/10)) % 2 ? 250 : 5);
- }
- return data;
- # - media_player.play_media:
- # id: media_out
- # #media_url: "https://birdnet.cornell.edu/files/2019/01/BirdNET_01_XC169082.wav"
- # media_url: "https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3"
- - globals.set:
- id: inch_this_run_counter
- value: '0'
- - globals.set:
- id: inch_total_run_counter
- value: '0'
- - logger.log:
- format: "Reset pressed"
- - light.turn_on:
- id: led
- flash_length: 500ms # blink for 500ms then turn off
- - delay: 700ms
- - light.turn_on:
- id: led
- flash_length: 500ms # blink for 500ms then turn off
- - delay: 700ms
- - light.turn_on:
- id: led
- flash_length: 500ms # blink for 500ms then turn off
- light:
- - platform: binary
- output: status_led
- id: led
- name: "Status LED"
- # Wheel is 42.5 inches on the inside diameter
- # 2 pi R is 2 * 3.14 * 21.25 = 135 inches long for each trip
- sensor:
- - platform: template
- name: "Inches run this run"
- id: inches_run_this_run_sensor
- accuracy_decimals: 0
- lambda: 'return id(inch_this_run_counter);'
- - platform: template
- name: "Feet run this run"
- id: feet_run_this_run_sensor
- accuracy_decimals: 1
- lambda: 'return id(inch_this_run_counter) / 12.0;'
- - platform: template
- name: "Inches total run"
- id: inches_total_run_sensor
- accuracy_decimals: 0
- lambda: 'return id(inch_total_run_counter);'
- - platform: template
- name: "Feet total run"
- id: feet_total_run_sensor
- accuracy_decimals: 1
- lambda: 'return id(inch_total_run_counter) / 12.0;'
- interval:
- - interval: 1s
- then:
- - if:
- condition:
- binary_sensor.is_on: wheel_moving
- then:
- - component.update: inches_run_this_run_sensor
- - component.update: feet_run_this_run_sensor
- - component.update: inches_total_run_sensor
- - component.update: feet_total_run_sensor
Advertisement
Add Comment
Please, Sign In to add comment