Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
5.8 kB
15
Indexable
Never
# # I used an esp8266 in esphome and these hall thingies off amazon
# HiLetgo 2pcs NJK-5002C Hall Effect Sensor Proximity Switch NPN 3-Wires Normally Open

#Most recent (seems to work for me now ) is tge uncommented beliw.
# I also pasted older stuff that got me to the final redult.
# all credit goes to chatGPT. Me and her do some good work sometimes. Lol

web_server:
  port: 80



# binary_sensor:
  # - platform: gpio
    # pin:
      # number: D1
      # mode: INPUT_PULLUP
      # inverted: True
    # name: "Wheel Rotation Sensor"
    # id: wheel_sensor
    # filters:
      # - delayed_on: 10ms
    # on_click:
      # then:
        # - pulse_counter.increment: wheel_rpm_sensor

# binary_sensor:
  # - platform: gpio
    # pin:
      # number: D1  # Replace with your GPIO pin number
      # mode: INPUT_PULLUP
      # inverted: True
    # name: "Wheel Rotation Sensor"
    # id: wheel_sensor
    # filters:
      # - delayed_on: 10ms
    # on_click:
      # then:
        # - lambda: |-
            # id(revolutions_counter)++;
            # // Increment the revolutions counter whenever a click is detected

sensor:
  - platform: pulse_counter
    pin: D1
    unit_of_measurement: 'RPM'
    name: 'Wheel RPM Sensor'
    id: windmill_rpm_sensor  
    on_value:
      then:
        - logger.log: "Pulse detected on pin D1"

    # total:
      # unit_of_measurement: 'RPM'
      # name: 'Total RPM'
      # # filters:
        # # - multiply: 0.001  # (1/1000 pulses per kWh)
 
  - platform: template
    name: "Average RPM"
    id: average_rpm_sensor
    unit_of_measurement: 'RPM'
    update_interval: 5s  # Update every 5 seconds
    lambda: |-
      float total_rpm = 0;
      float count = 0;
      for (uint32_t i = 0; i < 5; ++i) {
        total_rpm += id(windmill_rpm_sensor).state;
        delay(1000);  // Wait for 1 second
        count++;
      }
      return total_rpm / count;
      
  - platform: template
    name: "Wind Speed"
    id: wind_speed
    unit_of_measurement: "mph"
    accuracy_decimals: 2
    update_interval: 5s
    lambda: |-
      // Diameter of the circle formed by the windmill's rotation
      float diameter_inches = 22;  // Adjust as needed
      // Circumference of the circle
      float circumference_inches = PI * diameter_inches;
      // Calculate wind speed in inches per minute
      float wind_speed_inches_per_minute = id(windmill_rpm_sensor).state * circumference_inches;
      // Convert wind speed to miles per hour
      float wind_speed_mph = wind_speed_inches_per_minute / 63360 * 60;  // 1 mile = 63360 inches
      return wind_speed_mph;


 # - platform: pulse_counter
    # pin: D1
    # unit_of_measurement: 'rpm'
    # name: 'Wheel Turn'
    # # filters:
      # # - multiply: 0.06  # (60s/1000 pulses per kWh)

    # total:
      # unit_of_measurement: 'rpm'
      # name: 'Wheel Turns Total'
      # # filters:
        # # - multiply: 0.001  # (1/1000 pulses per kWh)


  # - platform: template
    # name: "Battery Level"
    # id: battery_level
    # update_interval: 60s  # Adjust the update interval as needed
    # unit_of_measurement: '%'
    # accuracy_decimals: 1
    # lambda: |-
      # float voltage = id(battery_voltage).state;
      # // Assuming your battery voltage divider scales to 3.3V max
      # float battery_level = (voltage / 3.3) * 100;
      # return battery_level;
      
  # - platform: adc
    # pin: A0  # Replace with the actual GPIO pin number connected to the battery voltage divider
    # name: "Battery Voltage"
    # id: battery_voltage
    # update_interval: 60s  # Adjust the update interval as needed

  # - platform: template
    # id: esp_memory
    # icon: mdi:memory
    # name: 208 Free Memory
    # #lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
    # unit_of_measurement: 'kB'
    # state_class: measurement
    # entity_category: "diagnostic"

  # - platform: template
    # id: sys_esp_temperature
    # name: 208 Internal Temperature
    # #lambda: return temperatureRead();
    # unit_of_measurement: °C
    # device_class: TEMPERATURE
    # entity_category: "diagnostic"

  - platform: uptime
    name: 208 Uptime
    id: sys_uptime
  - platform: wifi_signal 
    name: 208 RSSI
    id: wifi_signal_db
    entity_category: "diagnostic"
 
switch:
  - platform: restart
    name: "Restart"
    
text_sensor:
  # - platform: template
    # name: "Battery Level Text"
    # id: battery_level_text
    # icon: "mdi:battery"
    # update_interval: 60s  # Adjust the update interval as needed
    # lambda: |-
      # float voltage = id(battery_voltage).state;
      # // Assuming your battery voltage divider scales to 3.3V max
      # float battery_level = (voltage / 3.3) * 100;
      # if (battery_level > 20) {
        # return optional<std::string>("Good");
      # } else if (battery_level > 10) {
        # return optional<std::string>("Low");
      # } else {
        # return optional<std::string>("Critical");
      # }

  - platform: wifi_info
    ip_address:
      name: 208 IP Address
    ssid:
      name: 208 Connected SSID
    bssid:
      name: 208 Connected BSSID
    mac_address:
      name: 208 Mac Wifi Address
    scan_results:
      name: 208 Latest Scan Results
    dns_address:
      name: 208 DNS Address


# Define a time trigger to wake up the device every 10 minutes
# time:
  # - platform: homeassistant
    # id: time_trigger
    # on_time:
      # - seconds: 0
        # minutes: 0  # Adjust the minutes here
        # then:
          # - deep_sleep.enter: deep_sleep_trigger


  
# time:
  # - platform: homeassistant
    # id: time_trigger
    # on_time:
      # - seconds: 0
        # minutes: "*/10"
        # then:
          # - deep_sleep.enter: deep_sleep_trigger

# deep_sleep:
  # id: deep_sleep_trigger
Leave a Comment