I’m trying to figure out how to call a custom function in a switch.
I have a custom uart polling component where I pass some sensor values that it reads. I also want to be able to send some uart commands that are implemented in a function in the custom component.
I can’t figure out how to do this. Now I’m a hardware guy and know enough software to be dangerous!
My switch is define like this:
switch:
- platform: gpio
pin: GPIO26
id: generic_switch
name: 'on_off_mppt'
on_turn_on:
- logger.log: "Switch on"
- lambda: "id(mppt_jb).send_CC_ON()"
on_turn_off:
- logger.log: "Switch off"
it’s complaining about no send_CC_ON being defined.
my custom component is instantiated here:
custom_component:
- id: mppt_jb
lambda: |-
auto my_mppt2 = new BlueSkyWiFi(id(uart3),id(Bvol),id(PVvol),id(Bcur),id(Bwatts));
App.register_component(my_mppt2);
return {my_mppt2};
My customer component looks like this:
class BlueSkyWiFi : public PollingComponent, public UARTDevice
{
Sensor *xsensor1{nullptr};
Sensor *xsensor2{nullptr};
Sensor *xsensor3{nullptr};
Sensor *xsensor4{nullptr};
Switch *xsw1{nullptr};
mppt_controller myMppt;
int count;
int last_milli;
int new_milli;
public:
BlueSkyWiFi(UARTComponent *parent, Sensor *sensor1, Sensor *sensor2, Sensor *sensor3, Sensor *sensor4) : UARTDevice(parent), xsensor1(sensor1), xsensor2(sensor2), xsensor3(sensor3), xsensor4(sensor4) {}
byte buf[32];
void init_count() {
this->count=0;
this->last_milli = 0;
}
void send_CC_ON(){
write_byte(0xAA);
write_byte(0xCC);
write_byte(0x02);
write_byte(0x00);
write_byte(0x00);
write_byte(0xCE);
}
How do I get it call a function from like a switch action. I’m either missing something simple or I’m going about it the wrong way!
Thanks,
Jim