I need some help with ESPHome, uart port and a Windsonic anemonemeter

[01:42:45][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy

Have you changed the config? You were previously getting

00:58:40][D][sensor:092]: 'Vindretning': Sending state 0.00000 °Grader with 3 decimals of accuracy

Also, you are getting disconnects from the api, fix your networking, or whatever is causing that.

Also I believe from some reading that the anemometer operates at 9600 baud, which may be why you are getting al those uart read failures.

My networking i sworking as it should, have have 2 other esphome setup thats working perfectly on this instance off Home Assistant.

And I changeg from norwegian to english in my code.

The windsonic are working on 19200 baud, I set it up to do that. With the tool from Gill.
Here you can find out more on this sensor http://gillinstruments.com/products/anemometer/windsonic.htm

I have made python software on other system that works with this sensor earlier.

Well you’ll need to concentrate on fixing your api issue.

I suggest an upgrade to the dev version of esphome would be a good start.

I have looked into the custom sensor source code, is there any limitation in custom sensor regarding type off sensor and attribute setup ? To me it’s lookis like it is.

Mate if your uptime sensor isn’t showing in home assistant you have a serious problem with even getting esphome connected to homeassistant.

Is this esphome device integrated in home assistant via it’s ip address or hostname?

If via IP, has it’s IP address changed?

If via hostname, has the hostname or changed? Is it resolvable from your hass machine?

Have you changed the api password in your esphome yaml file?

It’s resolved by its name.
It’s connected via OTA

If I couldn’t connect to this ESP, I wouldn’t be able to se this in the ESP’s log view.

ESPHome Dashboardmore_vert
OTA (Over-The-Air)
memory
cam1more_vert
 . Full path: /config/esphome/cam1.yaml

UPLOAD EDIT SHOW LOGS VALIDATE
memory
lcd2more_vert
 . Full path: /config/esphome/lcd2.yaml

UPLOAD EDIT SHOW LOGS VALIDATE
memory
temperaturmore_vert
 . Full path: /config/esphome/temperatur.yaml

UPLOAD EDIT SHOW LOGS VALIDATE
memory
vindmore_vert
 . Full path: /config/esphome/vind.yaml

UPLOAD EDIT SHOW LOGS VALIDATE
Show Logs vind.yaml
INFO Reading configuration /config/esphome/vind.yaml...
INFO Starting log output from vind.local using esphome API
INFO Connecting to vind.local:6053 (192.168.2.155)
INFO Successfully connected to vind.local
[10:50:57][I][app:100]: ESPHome version 1.14.3 compiled on Apr 11 2020, 01:18:25
[10:50:57][C][wifi:415]: WiFi:
[10:50:57][C][wifi:283]:   SSID: [redacted]
[10:50:57][C][wifi:284]:   IP Address: 192.168.2.155
[10:50:57][C][wifi:286]:   BSSID: [redacted]
[10:50:57][C][wifi:287]:   Hostname: 'vind'
[10:50:57][C][wifi:291]:   Signal strength: -51 dB ▂▄▆█
[10:50:57][C][wifi:295]:   Channel: 1
[10:50:57][C][wifi:296]:   Subnet: 255.255.255.0
[10:50:57][C][wifi:297]:   Gateway: 192.168.2.1
[10:50:57][C][wifi:298]:   DNS1: 192.168.2.1
[10:50:57][C][wifi:299]:   DNS2: 0.0.0.0
[10:50:58][E][uart:096]: Reading from UART timed out at byte 0!
[10:50:58][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:50:58][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
[10:50:58][C][uart:040]: UART Bus:
[10:50:58][C][uart:042]:   TX Pin: GPIO1
[10:50:58][C][uart:045]:   RX Pin: GPIO3
[10:50:58][C][uart:047]:   Baud Rate: 19200 baud
[10:50:58][C][uart:048]:   Stop bits: 1
[10:50:59][E][uart:096]: Reading from UART timed out at byte 0!
[10:50:59][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:50:59][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
[10:50:59][C][uptime.sensor:030]: Uptime Sensor 'Uptime Sensor'
[10:50:59][C][uptime.sensor:030]:   Unit of Measurement: 's'
[10:50:59][C][uptime.sensor:030]:   Accuracy Decimals: 0
[10:50:59][C][uptime.sensor:030]:   Icon: 'mdi:timer'
[10:51:00][E][uart:096]: Reading from UART timed out at byte 0!
[10:51:00][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:51:00][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
[10:51:00][C][logger:175]: Logger:
[10:51:00][C][logger:176]:   Level: DEBUG
[10:51:00][C][logger:177]:   Log Baud Rate: 0
[10:51:00][C][logger:178]:   Hardware UART: UART0
[10:51:01][E][uart:096]: Reading from UART timed out at byte 0!
[10:51:01][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:51:01][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
[10:51:02][E][uart:096]: Reading from UART timed out at byte 0!
[10:51:02][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:51:02][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
[10:51:03][E][uart:096]: Reading from UART timed out at byte 0!
[10:51:03][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:51:03][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
[10:51:03][D][api.connection:583]: Client 'Home Assistant 0.108.2 (192.168.2.42)' connected successfully!
[10:51:03][C][captive_portal:169]: Captive Portal:
[10:51:04][E][uart:096]: Reading from UART timed out at byte 0!
[10:51:04][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:51:04][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
[10:51:05][C][ota:029]: Over-The-Air Updates:
[10:51:05][C][ota:030]:   Address: vind.local:3232
[10:51:05][C][ota:032]:   Using Password.
[10:51:06][E][uart:096]: Reading from UART timed out at byte 0!
[10:51:06][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:51:06][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
[10:51:06][C][api:095]: API Server:
[10:51:06][C][api:096]:   Address: vind.local:6053
[10:51:06][D][sensor:092]: 'Uptime Sensor': Sending state 34319.70703 s with 0 decimals of accuracy
[10:51:07][E][uart:096]: Reading from UART timed out at byte 0!
[10:51:07][D][sensor:092]: 'Wind direction': Sending state 0.00000 °Degrees with 3 decimals of accuracy
[10:51:07][D][sensor:092]: 'Wind speed': Sending state 0.00000 ms with 3 decimals of accuracy
© 2019 Copyright ESPHome, Made with MaterializeESPHome 1.14.3 Documentation

I don’t even know whether you are using esphome on the same machine as home assistant, so I didn’t make an assumption.

Try commenting out all the custom sensor code and upload the resulting firmware. On the off chance that there is some problem with your custom code that is preventing esphome working, at least we will know because your uptime sensor should show.

Done this now, Now this uptime is showing up in the integration. So there must be som kind off problem in the setup or code I made.

The setup is using UART0 if that is any problem, logger is ste to baud 0.
Then I’m left with the windsonic.h file. if I done anything wrong there ?

#include "esphome.h"

class Windsonic : public Component, public Sensor, public UARTDevice {
 public:
  Windsonic(UARTComponent *parent) : UARTDevice(parent) {}
  Sensor *winddirection_sensor = new Sensor();
  Sensor *windspeed_sensor = new Sensor();
  float winddirection;
  float windspeed;
  
  
  void setup() override {
    // nothing to do here
  }
  void loop() override {
    // Use Arduino API to read data, for example
	String line = readStringUntil('\n');
    String r = line.substring(7, 10);
	String s = line.substring(14, 19);
	winddirection = r.toFloat();
	windspeed = s.toFloat();
    winddirection_sensor->publish_state(winddirection);
    windspeed_sensor->publish_state(windspeed);
	
	winddirection = 0;
	windspeed = 0;
	r = "";
	s = "";
  }
  
};

I ses that I need a class that can be off sensor type but communicate with hardware off type UART. And take the setup off the UART as an value when constructed.
Not so different from the sds011 sensor.

After reading up on the dev version off ESPHome, I will make a full sensor integration for the windsonic, then post the result here in a few days

It’s the reading of the uart port that’s the reason I have problems with this custom setup. reporting a lot of empty strings.
The idea is to let the sensor that reporting once each second to govern the pace off this reading off the uart port. Is there some way to let the uart wait until it recives a “\n” and not dounig nothing until the next one is recived ?

Edit:
Is it possible to set UART timeout to 2s ?

This is soved by using UART1 instead off UARt0.
The rest is unchanged.

Well done! Would be good to debug why that worked, but at least you got it to go.

Could you please post your final config to esphome-configs.io?

Cheers.

I will do that, is just checking this out for stability, And fine tuning.

Current YAML, som strange behavior detected.

sensor:

  - platform: custom 
    lambda: |-
      auto my_windsonic = new Windsonic(id(wind));
      App.register_component(my_windsonic);
      return {my_windsonic->winddirection_sensor, my_windsonic->windspeed_sensor};
      

    sensors:
    - name: "Wind direction"
      unit_of_measurement: "gr"
      accuracy_decimals: 3
      icon: mdi:compass-rose
    - name: "Wind speed"
      unit_of_measurement: "ms"
      accuracy_decimals: 3
      icon: mdi:weather-windy 
    

There are a few strange behaviors when using this as an custom sensor:

1, The accuracy_decimals must be set at 3, anything else an it won’t show up the entities off the sensor. The sensor sends 5 decimal off accuracy for the moment. It’s only neded 2 on the wind speed sensor and 0 on the wind direction sensor.

  1. after setup and the sensor had have time to do an reboot, and the integration is setup, you need to do a hard reboot off the sensor ESP and sensor itself to get the data going.
1 Like

How did you end up going with this? I recently aquired a windsonic option 3 and would love to use it with HA.

I have so far an Windsonic Option 1 connected via an RS232 to TTL adapter to an Adafruit HUZZAH32 ESP32 unit. I’m using the ESPHome project to setup this ESP32 to shop out speed and direction from fixed lenght NMEA sentenses from the sensor.

I’m currently working to make it a little more stable and reconnect to HA after reboot off the HA. Most off the times it’s stable for now.

So is that using the code you supplied above? Also wonder about UART1 you mentioned earlier. I skimmed through the code and could not find where to change it, or is it hardware related? Sorry Im no good with code :rofl:

The code consist off to parts:

Windsonic.h

#include "esphome.h"
#include "sensor.h"

class Windsonic : public Component, public UARTDevice {
 public:
  Windsonic(UARTComponent *parent) : UARTDevice(parent) {}
  Sensor *winddirection_sensor = new Sensor();
  Sensor *windspeed_sensor = new Sensor();
  
  
  
  void setup() override {
    // nothing to do here
  }
  void loop() override {
    // Use Arduino API to read data, for example
  //String line = "";  
  
  String line = readStringUntil('\n');
  String r = line.substring(7, 10);
  String s = line.substring(13, 19);
  float winddirection = r.toFloat();
  float windspeed = s.toFloat();
  winddirection_sensor->publish_state(winddirection);
  windspeed_sensor->publish_state(windspeed);
  winddirection = 0;
  windspeed = 0;
  r = "";
  s = "";
	
	
  }
  
};


And
windsonic.YAML

esphome:
  name: windsonic
  platform: ESP32
  board: featheresp32
  includes:
    - windsonic.h
wifi:
  ssid: "xxxxxx"
  password: "xxxxxxx"
  fast_connect: true
#  reboot_timeout: 45min

# Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "windsonic Fallback Hotspot"
    password: "xxxxxxxx"

captive_portal:

# Enable logging
logger:
  baud_rate: 9600
  
# Enable Home Assistant API
api:
  password: "xxxxxxxxxx"
  reboot_timeout: 60s
  
ota:
  password: "xxxxxxxxx"

uart:
  id: wind
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 19200


sensor:
  - platform: custom 
    lambda: |-
      auto my_windsonic = new Windsonic(id(wind));
      App.register_component(my_windsonic);
      return {my_windsonic->winddirection_sensor, my_windsonic->windspeed_sensor};
      
    sensors:
    - name: "Wind direction"
      unit_of_measurement: "gr"
#      accuracy_decimals: 3
      icon: mdi:compass-rose
    - name: "Wind speed"
      unit_of_measurement: "m/s"
      accuracy_decimals: 3
      icon: mdi:weather-windy 
      

On ESP32 based boards you must use UART1 to avoid conflict with the logger component.

1 Like