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.
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.
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 ?
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.
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.
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
#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 = "";
}
};