I bought some wind speed sensors to use within esphome, but they are not currently a supported sensor. The creator of the sensor provided a sample config to use the sensors within arduino IDE, so I have been trying to adapt it into esphome. So far, I am not having much luck.
The sensor is very simple; all it is is two analog outputs that gives you wind speed, and temperature. The problem is trying to get the lambdas to work in esphome (although I am a very beginner level user when it comes to writing scripts in both arduino and esphome).
This is the sample config for use in arduino:
#define analogPinForRV 1
#define analogPinForTMP 0
// to calibrate your sensor, put a glass over it, but the sensor should not be
// touching the desktop surface however.
// adjust the zeroWindAdjustment until your sensor reads about zero with the glass over it.
const float zeroWindAdjustment = .2; // negative numbers yield smaller wind speeds and vice versa.
int TMP_Therm_ADunits; //temp termistor value from wind sensor
float RV_Wind_ADunits; //RV output from wind sensor
float RV_Wind_Volts;
unsigned long lastMillis;
int TempCtimes100;
float zeroWind_ADunits;
float zeroWind_volts;
float WindSpeed_MPH;
void setup() {
Serial.begin(57600); // faster printing to get a bit better throughput on extended info
Serial.println("start");
pinMode(A2, INPUT); // GND pin
pinMode(A3, INPUT); // VCC pin
digitalWrite(A3, LOW); // turn off pullups
}
void loop() {
if (millis() - lastMillis > 200){
TMP_Therm_ADunits = analogRead(analogPinForTMP);
RV_Wind_ADunits = analogRead(analogPinForRV);
RV_Wind_Volts = (RV_Wind_ADunits * 0.0048828125);
TempCtimes100 = (0.005 *((float)TMP_Therm_ADunits * (float)TMP_Therm_ADunits)) - (16.862 * (float)TMP_Therm_ADunits) + 9075.4;
zeroWind_ADunits = -0.0006*((float)TMP_Therm_ADunits * (float)TMP_Therm_ADunits) + 1.0727 * (float)TMP_Therm_ADunits + 47.172; // 13.0C 553 482.39
zeroWind_volts = (zeroWind_ADunits * 0.0048828125) - zeroWindAdjustment;
// This from a regression from data in the form of
// Vraw = V0 + b * WindSpeed ^ c
// V0 is zero wind at a particular temperature
// The constants b and c were determined by some Excel wrangling with the solver.
WindSpeed_MPH = pow(((RV_Wind_Volts - zeroWind_volts) /.2300) , 2.7265);
Serial.print(" TMP volts ");
Serial.print(TMP_Therm_ADunits * 0.0048828125);
Serial.print(" RV volts ");
Serial.print((float)RV_Wind_Volts);
Serial.print("\t TempC*100 ");
Serial.print(TempCtimes100 );
Serial.print(" ZeroWind volts ");
Serial.print(zeroWind_volts);
Serial.print(" WindSpeed MPH ");
Serial.println((float)WindSpeed_MPH);
lastMillis = millis();
}
}
And this is what I have in esphome so far:
captive_portal:
sensor:
- platform: adc
pin: 35
id: temp_f #analog_tmp
name: "Temperature"
update_interval: 60s
filters:
- multiply: 0.018
- lambda: |-
return (x - 32.0) * 5.0 / 9.0;
unit_of_measurement: "°F"
- platform: adc
pin: 34
id: wind_speed #analog_rv
name: "Wind Speed"
update_interval: 60s
filters:
- lambda: |-
float zeroWindAdjustment = 0.02;
float RV_Wind_ADunits = x;
float RV_Wind_Volts = RV_Wind_ADunits * 0.0048828125;
// Calibrate the sensor
float TMP_Therm_ADunits = id(temp_f).state * 100.0;
float zeroWind_ADunits = -0.0006 * (TMP_Therm_ADunits * TMP_Therm_ADunits) + 1.0727 * TMP_Therm_ADunits + 47.172;
float zeroWind_volts = zeroWind_ADunits * 0.0048828125 + zeroWindAdjustment; // change '-' to '+'
// Calculate the wind speed
float WindSpeed_MPH = pow(((RV_Wind_Volts - zeroWind_volts) / 0.2300), 2.7265);
return WindSpeed_MPH;
unit_of_measurement: "mph"
So far, all I am seeing in the logs when using this config is:
[23:25:26][D][sensor:127]: 'Wind Speed': Sending state 152375.67188 mph with 2 decimals of accuracy
[23:25:31][D][sensor:127]: 'Temperature': Sending state -17.76721 °F with 2 decimals of accuracy
Running the sensors on an arduino using the provided sketch returns the correct values, so I know the sensors are working correctly. Can anybody see where I am messing this up?
EDIT: I forgot to add, I have been receiving help from someone with arduino experience, but they have never used esphome. So if something seems to make no sense, that may be why.