Hi all,
I want to make an ESP in ESPhome that functions both as a sensor and as an output. It’s communication with my car charger via RS485, and I’ve got the sensor part working (simulated through an arduino for now) but I’m having a lot of trouble with the output part.
In short, I want a number entity which I will control in a Node-RED flow. This number should be sent to the ESP and the ESP will construct a message via its UART. The number entity is working, so there’s that. But I can’t find a working way to send its value to my custom output.
The yaml below is what I’ve got so far:
esphome:
name: esp-cp
includes:
- protocolMAXreceiver.h
- protocolMAXcontroller.h
esp8266:
board: esp01_1m
# Enable logging
logger:
level: VERBOSE
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: "**************"
ota:
password: "****************"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "***************"
password: "****************"
captive_portal:
uart:
id: uart_bus
rx_pin:
number: 3
inverted: false
baud_rate: 38400
sensor:
- platform: custom
lambda: |-
auto chargepoint_sensor = new ProtocolMAXReader(id(uart_bus));
App.register_component(chargepoint_sensor);
return {
chargepoint_sensor->allowableInterval,
chargepoint_sensor->minimalCurrent,
chargepoint_sensor->currentL1,
chargepoint_sensor->cosPhiL1,
chargepoint_sensor->cumulativePowerConsumption
};
sensors:
- name: "CP Allowable time interval for setpoint"
unit_of_measurement: s
accuracy_decimals: 0
- name: "CP Minimal Current"
unit_of_measurement: A
accuracy_decimals: 1
- name: "CP Momentary Current"
unit_of_measurement: A
accuracy_decimals: 1
- name: "CP Momentary Cos Phi"
accuracy_decimals: 3
- name: "CP Total Power Consumption"
unit_of_measurement: kWh
device_class: "energy"
state_class: total_increasing
output:
- platform: custom
type: float
lambda: |-
auto chargepoint_output = new ProtocolMAXController(id(uart_bus));
App.register_component(chargepoint_output);
return {chargepoint_output};
outputs:
id: CP_setpoint
number:
- platform: template
name: "CP Maximum Current Setpoint"
id: CP_current_setpoint
min_value: 0
max_value: 32
step: 0.1
set_action:
then:
- lambda:
id(CP_setpoint).write_state(x);
but that gives me an error
.\esp-cp.yaml:97:33: error: 'virtual void esphome::output::FloatOutput::write_state(float)' is protected within this context
Let’s say the method write_state() just prints the value as text on the UART for now…
I’ve tried 100 different combinations so far but I haven’t had it working yet.
Thanks for any advice!
Regards,
Tars