My configuration broke (long time ago) (custom_component Sensor)

Hello,

Almost 10 years ago, I’ve built a Aquarium Controller based on and Arduino Mega. This has a TON of in Outpots from dimmable lights to time, to fertilizer and runs smooth since then. But is was local - only way to interact and do changes on the settings was via the Touchscreen.

Later I built and raspberry PI running website and communication via UART with the arduino mega to control it. (Parsing strings,… it was a nightmare but came to live and was runnig great for years)

Then I moved on and jumped into homeassistant. Removed the Raspi and attached a nodemcu to do the controls via UART. Worked / Works gread… but at some point an ESPHome update killed it and I can’t get it to work with newer version

It was working with version 2023.3.0 and broke with 2023.4 or 2023.5 - I’m not sure.

Who is willing to help with this nightmare of code?

What is happening: Most of the sensors are greyed out now in Homeassistant. Some are displaying wrong data

Error logs aren’t showing much apart from

[22:07:01][W][component:214]: Component took a long time for an operation (0.36 s).
[22:07:01][W][component:215]: Components should block for at most 20-30ms.

Any help would be highly appretiated

Not sure if it hurts when the ESP is not USB connected, but

You're using the same serial port for logging and the UART component. Please disable logging over the serial port by setting logger->baud_rate to 0.

Furthermore, you don’t seem to give an initial/assumed/current state to your switches, so I assume they show greyed in HA because their status is unknown.
What state do you see?

The baud_rate: 0 was in the initial config but I removed everything in hope to get most out of the log. But it didn’t change anyways

The template switches are working (and updating) while the sensors are grey

I’m confused. If I take, e.g. “Co2”, it is a template switch in esphome, but then you register a binary sensor under the same name

     App.register_binary_sensor(my_custom_sensor->Co2);
    // Change for the name you want
    my_custom_sensor->Co2->set_name("Co2");    

What is the definition of your “UartReadLineSensor”’ custom component, btw?

At first - I wanted to geht all the informations into HA - hence all the cusom sensors.

Later when I started to control it I added the template switches.

So basically when I flip the Switch for Co2 the ESPhome sends an uart message to the arduino. Which triggers a valve to shutdown. After that it would send a Uart message to esphome - which would be reflected via the initial uart sensor. Later I found a way to reflect it right into the template switch.

As you can see in the code, this is more frankensteins monster then good code with a lot of copy and tries from the ESPHome support site to get something working.

So if you’ve got suggestion, I’m more then willing to make it better and learn something.

uartReadLine Sensor is here

I got it fixed finally:

2 things needed to be changed
my_custom_sensor->nF->set_internal(false);

and on the return statement I added all the sensors instead of just {my_custom_sensor}

return {my_custom_sensor->temp,my_custom_sensor->ph,my_custom_sensor->npkF,my_custom_sensor->nF,my_custom_sensor->feF};

I took the opportunity and your advice and remove all the stuff that was doubled (switches AND sensors) so no everything is either or. Temperature is a sensor, while Light is a switch. Not both

1 Like