Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anemometer Integration & Improvements #2

Closed
bassicrob opened this issue Apr 16, 2020 · 18 comments
Closed

Anemometer Integration & Improvements #2

bassicrob opened this issue Apr 16, 2020 · 18 comments

Comments

@bassicrob
Copy link

I see that you are actively working on this integration as well. I used your yaml as a basis and made some improvements of my own. It, like yours, is still a work in progress, but I do have the anemometer working. I am working to reduce the readings and "average" the headings to account for the vane swinging wildly.

I also changed my units to imperial ;) I am also using a BME280 over 15' of CAT5 cable successfully on i2c inside the monitoring unit on the mast with a status LED.

An issue I discovered was although the total rain integration works, the my_rain sensor only measures upon the bucket tip then goes back to '0' between tips.

i2c:
  frequency: 100kHz #try for longer distance

sensor:
  - platform: pulse_counter
    pin: 
      # pin D5
      number: GPIO14
      mode: INPUT_PULLUP
    unit_of_measurement: 'mph' ##change to m/s if metric
    name: 'Wind sensor'
    icon: 'mdi:weather-windy'
    id: my_wind
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 50us
    update_interval: 60s 
    #rotations_per_sec = pulses/2/60
    #circ_m=0.09*2*3.14 = 0.5652
    #mps = 1.18*circ_m*rotations_per_sec  
    #mps = 1.18*0.5652/2/60 =0,0055578
    filters:
      # - multiply: 0.0055578 #use for m/s
      # - multiply: 2.237 #m/s to mph
      - sliding_window_moving_average:
          window_size: 4
          send_every: 1
      - multiply: 0.04973 #1.492mph switch to close 1/sec per spec, pulse/sec (/60/2)*1.492
      # - multiply: 0.0124327986 #m/s * mph conversion

  # - platform: template
  #   id: wind_mph
  #   name: 'Wind Speed'
  #   icon: 'mdi:weather-windy'
  #   filters:
  #     - lambda: return (id(my_wind).raw_state) * 2.237;
      
  # - platform: template
  #   id: wind_knots
  #   unit_of_measurement: 'knots'
  #   name: "Wind Speed Knots"
  #   lambda: return id(my_wind).state * 0.0055578 * 1.94384449
      
  - platform: pulse_counter
    pin: 
      # pin D6
      number: GPIO12
      mode: INPUT_PULLUP
    unit_of_measurement: 'in' ##change to mm if metric
    name: 'Rain gauge'
    icon: 'mdi:weather-rainy'
    id: my_rain
    internal: true
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 50us
    update_interval: 60s
    #buckets = pulses
    #mm_per_bucket=0.2794
    #rain = buckets*0.2794
    filters:
  #    - multiply: 0.2794 #for mm
      - multiply: 0.011 # to inches
    accuracy_decimals: 3

  - platform: integration
    name: "Rainfall per min"
    id: rain_per_min
    time_unit: min
    unit_of_measurement: 'in'
    sensor: my_rain
    
  - platform: total_daily_energy
    name: "Total Daily Rain"
    power_id: my_rain
    unit_of_measurement: 'in' ###change to mm if metric
    icon: 'mdi:weather-rainy'
    # x60 To convert to aggregated rain amount
    filters:
      - multiply: 60

# COMPLETE FOR WEATHER    
  - platform: bme280
    temperature:
      name: "WxSta Temperature"
      id: bme280_temperature
      oversampling: 1x
  
    pressure:
      name: "WxSta Pressure"
      id: bme280_pressure
      oversampling: 1x
      
    humidity:
      name: "WxSta Relative Humidity"
      id: bme280_humidity
      oversampling: 1x
    address: 0x76
    update_interval: 60s


### ADD WIND DIRECTION
  - platform: adc
    id: adc_sensor
    pin: A0
    name: ADC
    internal: true
    update_interval: 30s
    filters:
      # - multiply: 3.3 ##built into Wemos
      # - multiply: 0.0009775171   #1/1023
    accuracy_decimals: 3 ##IMPORTANT to get resolution for resistance sensor!

    
  - platform: resistance
    sensor: adc_sensor
    id: resistance_sensor
    configuration: DOWNSTREAM
    resistor: 10kOhm
    internal: true
    name: Resistance Sensor
    accuracy_decimals: 1
    filters:
      - heartbeat: 30s
    on_value:
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 3100
              below: 3200
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "N"
            - sensor.template.publish:
                id: wind_heading
                state: 0.0
                
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 1600
              below: 1700
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "NE"         
            - sensor.template.publish:
                id: wind_heading
                state: 45.0            
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 250
              below: 350
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "E"                
            - sensor.template.publish:
                id: wind_heading
                state: 90.0          
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 550
              below: 650
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "SE"    
            - sensor.template.publish:
                id: wind_heading
                state: 135.0             
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 900
              below: 1100
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "S"    
            - sensor.template.publish:
                id: wind_heading
                state: 180.0            
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 2300
              below: 2450
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "SW"    
            - sensor.template.publish:
                id: wind_heading
                state: 225.0              
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 3900
              below: 4100
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "W"    
            - sensor.template.publish:
                id: wind_heading
                state: 270.0          
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor
              above: 3500
              below: 3800
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "NW"    
            - sensor.template.publish:
                id: wind_heading
                state: 315.0

  - platform: template
    name: "Wind Heading"
    id: wind_heading
    unit_of_measurement: "°"

### ADD WIND CARIDNAL DIRECTION
### Your values may differ!
# Direction -- Resistance -- ADC Voltage
# N -- 3132Ω -- 0.79v
# NE -- 1643Ω -- 0.47v
# E -- 292Ω -- 0.10v
# SE -- 602Ω -- 0.19v
# S -- 974Ω -- 0.29v
# SW -- 2372Ω -- 0.63v
# W -- 3997Ω -- 0.94v
# NW -- 3657Ω -- 0.88v

  - platform: sun
    name: Sun Elevation
    type: elevation
    update_interval: 120s

  - platform: sun
    name: Sun Azimuth
    type: azimuth
    update_interval: 120s

## ADD Beufort

sun:
  latitude: <insert latitude>
  longitude: <insert longitude>

text_sensor:
  - platform: template
    name: "Wind Cardinal Direction"
    id: wind_dir_card
    
  - platform: sun
    name: Next Sunrise
    type: sunrise
    update_interval: 4h
  - platform: sun
    name: Next Sunset
    type: sunset
    update_interval: 4h
# light:
#   - platform: binary
#     id: status_light_remote
#     output: status_led_remote
    
output:
  - platform: gpio
    pin: D7
    id: status_led_remote
interval:
  - interval: 30s
    then:
      - output.turn_on: status_led_remote
      - delay: 150ms
      - output.turn_off: status_led_remote
  - interval: 60s
    then:
      - sensor.integration.reset: rain_per_min   
# Enable time component to reset energy at midnight
time:
  - platform: sntp
    id: my_time

Within Homeassistant, I created a "Average Wind Speed" sampling and record gusts. It worked pretty well for a few recent storms, and data is comparable to local PWS.

configuration.yaml

sensor:
  - platform: statistics
    entity_id: sensor.wind_sensor_2
    max_age:
      minutes: 2
    name: "WX Sta Wind Stats"
    sampling_size: 3

  - platform: statistics
    entity_id: sensor.wind_sensor_2
    max_age:
      minutes: 10
    name: "WX Sta Wind 10m Stats"
    sampling_size: 10
    
  - platform: statistics
    entity_id: sensor.wind_sensor_2
    max_age:
      minutes: 60
    name: "WX Sta Wind 60m Stats"
    sampling_size: 60

  - platform: template
    sensors:
      wx_sta_wind:
        friendly_name: "3m Avg Wind Speed"
        unit_of_measurement: 'mph'
        value_template: "{{ state_attr('sensor.wx_sta_wind_stats', 'mean') }}"    
      10m_wind_gust:
        friendly_name: "10m Wind Gust"
        unit_of_measurement: 'mph'
        value_template: "{{ state_attr('sensor.wx_sta_wind_10m_stats', 'max_value') }}"
      60m_wind_gust:
        friendly_name: "60m Wind Gust"
        unit_of_measurement: 'mph'
        value_template: "{{ state_attr('sensor.wx_sta_wind_60m_stats', 'max_value') }}"
@bassicrob
Copy link
Author

bassicrob commented Apr 16, 2020

Testing on the bench:
20200324_211133
"Final" Wiring With Keystone panel:
20200404_162320

I just need to finish the connections at the Wemos and put it all in an enclosure.

I combined the rain and wind RJ-11 into a single Cat5 run to the Wemos. Second Cat5 cable is for i2c communication (pair each for 3.3v-Gnd-SDL-SCA). Led is just single-pin out-wire to monitoring unit (ran out of wires!).
Fritzing:
wx-station_bb

@mbo18
Copy link

mbo18 commented May 2, 2020

Nice work @bassicrob!
Do you plan to do a post on Home Assistant forum? Would be nice.
I plan to do the same thing but only with Wind (gauge/direction) and rain using a SEN-15901 kit. Using a RJ45 cable is clever! So the ESP is inside your home and sensors are outside? Do you think that it will work with a 15m RJ45 cable?

@bassicrob
Copy link
Author

I think I may have just responded to your comment on the HA forum?

The sensors are outside on my garage. I replaced the guts of the transmitter and temperature with a PCB with an LED and i2c BME280. The LED is fed with its own wire, the i2c is run off about 15' of cat5e cable to the inside of my garage where the Wemos lives. The rain, wind, and anemometer are combined from a homemade patch panel where the wires enter into my garage, and then run back to the Wemos with a 25' CAT5 cable (I ran out of cable in the pull-box and had a pre-made one on hand). I used like-colored pairs for all connections. I found this was very important to prevent cross-talk.
15m run? maybe. try i on the bench and see if it works!

@mkuoppa
Copy link
Owner

mkuoppa commented May 3, 2020

Hey guys. Thanks for using this.
Will think about adding your wind direction part to the code, though I don’t have it my self. Regarding the rain pulse counter going to zero, we’ll that is how that component works. If you want another behavior I suggest using an integrator on top of that (like the total daily rain).
@bassicrob why not make a fork of my code to show and share your own contributions :)

@mkuoppa mkuoppa closed this as completed May 3, 2020
@stovedoctor
Copy link

Excuse my ignorance.
Can you tell me how to code calculate windspeed for a davis ?
According to the Davis Anemometer technical document 1 mile per hour is equal to 1600 revolutions per hour.

@mkuoppa
Copy link
Owner

mkuoppa commented Apr 2, 2021

Excuse my ignorance.

Can you tell me how to code calculate windspeed for a davis ?

According to the Davis Anemometer technical document 1 mile per hour is equal to 1600 revolutions per hour.

First of all you need to know Home many pulsen your sensor gives per revolution/rotation and per minute.
From this I have calculated my sensors rotations per second because I want to measure wind speed in meters per second.
#rotations_per_sec = pulses/2/60

Then you must calculate the circumference of the anemomenter.
The radius (r) of mine is 0.09m or 9cm.
Circumference formula is r2pi
#circ_m=0.0923.14 = 0.5652

Multiplying circumference and rotations per second gives roughly the wind speed. But I have added a calibration factor of 1.18 to compensate for the fact that the anemometer will not rotate at full wind speed but rather a bit slower due to friction drag and more.
#mps = 1.18circ_mrotations_per_sec

So basically your calculation must be adapted the size of you anemometer, pulses per revolution and losses.

@stovedoctor
Copy link

Thanks for the reply.
I get this from Arduino code site was trying to convert to Esphome yaml.

How to Measure the Wind Speed
The wind cups have a reed switch mounted inside near the shaft. This switch is activated once per revolution of the cups. To calculate the wind speed we apply a formula that converts the number of time the switch activates per period of time to miles per hour.

According to the Davis Anemometer technical document 1 mile per hour is equal to 1600 revolutions per hour.

Using the formula V = P(2.25/T) we can calculate the speed in miles per hour.
More here
http://cactus.io/hookups/weather/anemometer/davis/hookup-arduino-to-davis-anemometer-wind-speed

@mkuoppa
Copy link
Owner

mkuoppa commented Apr 3, 2021

Thanks for the reply.

I get this from Arduino code site was trying to convert to Esphome yaml.

How to Measure the Wind Speed

The wind cups have a reed switch mounted inside near the shaft. This switch is activated once per revolution of the cups. To calculate the wind speed we apply a formula that converts the number of time the switch activates per period of time to miles per hour.

According to the Davis Anemometer technical document 1 mile per hour is equal to 1600 revolutions per hour.

Using the formula V = P(2.25/T) we can calculate the speed in miles per hour.

More here

http://cactus.io/hookups/weather/anemometer/davis/hookup-arduino-to-davis-anemometer-wind-speed

To make it clearer I convert this to SI units. I suggest everyone to do all calculations in SI units and the convert to whatever you want to be displayed.

1600 rev/h = 1 miles/h = 1.609 km/h 1600 m/h
This implies that
1600rev = 1609 m
And
1 rev = 1609 / 1600 = 1.006 m
So the circumference is 1m. Use 1m as circumference in my code and skip the calibration factor.

So if you use update_interval: 60s
Your multiply filter is approximately 1/60 = 0.0167

@stovedoctor
Copy link

Thank you, You rock.
Now reading both of your replies I mostly get how the formula and code works.
At first I did not understand the formula on speed calculations. I am a dumb ass and always need real world hands on example.
In any of the example I have found online it was NOT explained that
#circ_m=0.09*2*3.14 = 0.5652
Is the calculation of the size of the wind cups rotation converted to time.
Every different design is going to be different size and I'm sure most will miss this fact if they just use your code that is linked in esphome.

One question so I understand how it works
What is the 2 in this line?
I think I get the 60 is a time factor seconds ?
rotations_per_sec = pulses/2/60
Thank you very much for taking the time to help me and others learn.
thestovedoc.com.

@mkuoppa
Copy link
Owner

mkuoppa commented Apr 3, 2021

Thank you, You rock.

Now reading both of your replies I mostly get how the formula and code works.

At first I did not understand the formula on speed calculations. I am a dumb ass and always need real world hands on example.

In any of the example I have found online it was NOT explained that

#circ_m=0.09*2*3.14 = 0.5652

Is the calculation of the size of the wind cups rotation converted to time.

Every different design is going to be different size and I'm sure most will miss this fact if they just use your code that is linked in esphome.

One question so I understand how it works

What is the 2 in this line?

I think I get the 60 is a time factor seconds ?

rotations_per_sec = pulses/2/60

Thank you very much for taking the time to help me and others learn.

thestovedoc.com.

When writing comments in code without review it tends not to be fully clarifying 😃
But hey, mistakes are part of being human and asking questions is a underestimated social activity 😉

By the way, my 2 is for 2 pulses per revolution...

@Kwiatjk
Copy link

Kwiatjk commented Oct 26, 2021

Thank you, You rock.
Now reading both of your replies I mostly get how the formula and code works.
At first I did not understand the formula on speed calculations. I am a dumb ass and always need real world hands on example.
In any of the example I have found online it was NOT explained that
#circ_m=0.09*2*3.14 = 0.5652
Is the calculation of the size of the wind cups rotation converted to time.
Every different design is going to be different size and I'm sure most will miss this fact if they just use your code that is linked in esphome.
One question so I understand how it works
What is the 2 in this line?
I think I get the 60 is a time factor seconds ?
rotations_per_sec = pulses/2/60
Thank you very much for taking the time to help me and others learn.
thestovedoc.com.

When writing comments in code without review it tends not to be fully clarifying 😃 But hey, mistakes are part of being human and asking questions is a underestimated social activity 😉

By the way, my 2 is for 2 pulses per revolution...

Hi , how will be if i have 3 magnes ?
and hall is connected to D7

''

  • platform: pulse_counter
    pin: D7
    unit_of_measurement: 'm/s'
    name: 'Predkość Wiatru'
    icon: 'mdi:weather-windy'
    id: wind_sensor
    count_mode:
    rising_edge: DISABLE
    falling_edge: INCREMENT
    internal_filter: 50us
    update_interval: 60s
    #rotations_per_sec = pulses/4/60
    #circ_m=0.0323.14 = 0.1884
    #mps = 1.18circ_mrotations_per_sec
    #mps = 1.18*0.1884/4/60 = 0.0009263
    filters:
    • multiply: 0.0009263
      ''
      Is ok ?

@mkuoppa
Copy link
Owner

mkuoppa commented Oct 26, 2021

If you have 3 pulsen per revolution (3 magnets)?
Then the calculation would be ...

rotations_per_sec = pulses/3/60

... rather than...

rotations_per_sec = pulses/4/60

... which would correspond to 4 pulsen per revolution.

@Kwiatjk
Copy link

Kwiatjk commented Oct 26, 2021

If you have 3 pulsen per revolution (3 magnets)? Then the calculation would be ...

rotations_per_sec = pulses/3/60

... rather than...

rotations_per_sec = pulses/4/60

... which would correspond to 4 pulsen per revolution.

THX will check

@Kwiatjk
Copy link

Kwiatjk commented Oct 31, 2021

Hi, thx its working. But i have another problem when is connected to Esp8266 , is restarting every random minutes

@mkuoppa
Copy link
Owner

mkuoppa commented Oct 31, 2021

Hi, thx its working. But i have another problem when is connected to Esp8266 , is restarting every random minutes

The restarts you have is not something I have experienced. Make sure you have configured your specific board correctly in esphome and seek general support in esphome forums and discord etc.

@Kwiatjk
Copy link

Kwiatjk commented Nov 1, 2021

I have set
platform: ESP8266
board: nodemcuv2

but i have ESP8266 nodemcuv3
th will try

@hugokernel
Copy link

Hi,
If anyone have an idea about the wind speed calculation explained in this comment hugokernel/esphome-weather-station#6 (comment)
Thx !

@Kwiatjk
Copy link

Kwiatjk commented Sep 27, 2022

So i have another question what will be multiply if i have only that informations ?
Resolution: 0.0875 m/s (that is, if 20 pulse detected in 1s, the wind speed is 1.75 m/s, and 3.5m/s if 40 pulse detected)

  • platform: pulse_counter
    pin:
    number: GPIO14
    mode: INPUT_PULLUP
    unit_of_measurement: 'm/s'
    name: 'Predkość Wiatru'
    icon: 'mdi:weather-windy'
    id: wind_sensor
    count_mode:
    rising_edge: DISABLE
    falling_edge: INCREMENT
    update_interval: 1s
    filters:
    • multiply: ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants