Hello,
I am testing how I can read out my TX23 wind sensor and transmit the values of the cardinal points.
The degrees are transmitted and the wind speed as well, the cardinal directions are correctly output in the log protocol, but I cannot create a sensor / template that it is transmitted to HA.
Enclosed my wind.yaml
esphome:
name: wind
platform: ESP8266
board: d1_mini
includes:
- tx23_custom_sensor.h
libraries:
- "https://github.com/egzumer/Arduino-LaCrosse-TX23-Library"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
mqtt:
broker: !secret mqtt_broker
username: !secret mqtt_user
password: !secret mqtt_password
web_server:
port: 80
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 0s
ota:
i2c:
sda: D1
scl: D2
################ Zeiteinstellung und Timer #########################
time:
- platform: homeassistant
id: homeassistant_time
####################### Laufzeitinformationen ##################
text_sensor:
- platform: wifi_info
ip_address:
name: IP
############ Sensorik ##########################
sensor:
- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: 60s
- platform: custom
id: tx23_id
lambda: |-
auto TX23 = new TX23CustomSensor();
App.register_component(TX23);
return {TX23->speed_sensor, TX23->direction_sensor};
sensors:
- name: "Widgeschwindigkeitt"
unit_of_measurement: "m/s"
accuracy_decimals: 1
icon: "mdi:weather-windy"
- name: "Windrichtung"
unit_of_measurement: "°"
icon: "mdi:compass-outline"
######################## Schalter/Taster ######################
switch:
- platform: restart
name: "Reboot"
and the tx23_custom_sensor.h
#include "esphome.h"
#include "LaCrosse_TX23.h"
#define DATAPIN D6
class TX23CustomSensor : public PollingComponent, public Sensor {
public:
LaCrosse_TX23 anemometer = LaCrosse_TX23(DATAPIN);
Sensor *speed_sensor = new Sensor();
Sensor *direction_sensor = new Sensor();
TX23CustomSensor() : PollingComponent(3000) {}
void setup() override {
}
void update() override {
static const char *dirTable[] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"};
float speed;
int direction;
bool reading;
reading = anemometer.read(speed, direction);
speed_sensor->publish_state(speed);
direction_sensor->publish_state(direction*22.5);
ESP_LOGD("custom", "reading is: %d", reading);
ESP_LOGD("custom", "speed is: %3.2f", speed);
ESP_LOGD("custom", "direction is: %s", dirTable[direction]);
}
};
my debug.log:
[sensor:099]: 'Windgeschwindigkeit': Sending state 0.00000 m/s with 1 decimals of accuracye
[sensor:099]: 'Windrichtung': Sending state 337.50000 ° with 0 decimals of accuracye
[custom:026]: reading is: 1e
[custom:027]: speed is: 0.00e
[custom:028]: direction is: NNWe
What can I try? The solutions I have found here, I get no solution, only error messages.
Thanks!
Greetings Gerald