I have a header .h file and I’m trying to bring a new module to esphome (TX510).
There I read the serial, get the data packets and then do some actions like sending text and state to Sensors.
In this file I have:
class UARTSensor : public Component, public UARTDevice {
public:
UARTSensor(UARTComponent *parent) : UARTDevice(parent) {}
Sensor* presence_sensor = new Sensor();
TextSensor* text_userid = new TextSensor();
TextSensor* text_reply = new TextSensor();
and then when I publish the state for the sensors like:
presence_sensor->publish_state(0);
text_userid->publish_state("None");
text_reply->publish_state("Failed");
In yaml I have:
sensor:
- platform: custom
lambda: |-
auto my_sensor = new UARTSensor(id(uart_bus));
App.register_component(my_sensor);
return {my_sensor->presence_sensor};
sensors:
- id: presence_sensor
name: "internal_presense_sensor_to_binary_template"
internal: true
on_value:
- binary_sensor.template.publish:
id: presence_template
state: !lambda return x > 0;
binary_sensor:
- platform: template
id: presence_template
name: "${device_name_pretty} Presence"
device_class: presence
Which always works, but the text sensors never get the values and stay unknown:
text_sensor:
- platform: custom
lambda: |-
auto my_text_sensor = new UARTSensor(id(uart_bus));
App.register_component(my_text_sensor);
return {my_text_sensor->text_userid, my_text_sensor->text_reply};
text_sensors:
- name: "text_userid"
internal: true
on_value:
then:
- text_sensor.template.publish:
id: user_id_template
state: !lambda 'return x;'
- name: "text_reply"
internal: true
on_value:
then:
- text_sensor.template.publish:
id: reply_template
state: !lambda 'return x;'
- platform: template
id: user_id_template
name: "${device_name_pretty} User ID"
- platform: template
id: reply_template
name: "${device_name_pretty} Responce"
In the logs I see something like:
[text_sensor:xx] '' : Published state: 'Failed'
So it gets the value but no sending it anywhere.
What am I doing wrong?
Everything else works as intended and that’s the only missing part to finish the component.