I am trying to install a DFRobot lux sensor, DFRobot_B_LUX_V30B as a custom component. The driver compiles and runs on a Arduino mini pro but when I compile under HA esphome it flags a error
In file included from src/main.cpp:30:
src/my_custom_sensor.h: In member function 'virtual void MyCustomSensor::setup()':
src/my_custom_sensor.h:11:5: error: invalid use of member function 'DFRobot_B_LUX_V30B MyCustomSensor::shedLux()' (did you forget the '()' ?)
11 | shedLux.begin();
| ^~~~~~~
| ()
src/my_custom_sensor.h: In member function 'virtual void MyCustomSensor::update()':
src/my_custom_sensor.h:15:23: error: invalid use of member function 'DFRobot_B_LUX_V30B MyCustomSensor::shedLux()' (did you forget the '()' ?)
15 | float outsideLux =shedLux.lightStrengthLux() ;
| ^~~~~~~
| ()
*** [.pioenvs/esphome-web-d02449/src/main.cpp.o] Error 1
The yaml configuration file is here
esphome:
name: esphome-web-d02449
friendly_name: Shed
includes:
- /config/esphome/lib/my_custom_sensor.h
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: xxxxx
ota:
i2c:
scl: GPIO14
sda: GPIO12
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
# could not get this to work in the shed when I changed the password
# got cold will try again
ap:
ssid: "Esphome-Web-D02449"
password: xxxxxx
captive_portal:
# Example configuration entry
sensor:
- platform: custom
lambda: |-
auto my_sensor = new MyCustomSensor();
App.register_component(my_sensor);
return {my_sensor};
sensors:
name: "Outside Lux"
unit_of_measurement: Lux
accuracy_decimals: 2
and the custom include file is
include "esphome.h"
#include "/config/esphome/lib/DFRobot_B_LUX_V30B.h"
class MyCustomSensor : public PollingComponent, public Sensor {
public:
DFRobot_B_LUX_V30B shedLux(); // GPIO16 is enable 14 scl, 12 sda
MyCustomSensor() : PollingComponent(15000) { }
void setup() override {
shedLux.begin();
}
void update() override {
float outsideLux =shedLux.lightStrengthLux() ;
publish_state(outsideLux);
}
Would appreciate some pointers of where I am going wrong. The target is an ESP8266