I have this situation
I would like to pass several H.A. entities value to the class of my custom component library into the YAML code
let’say the entity is given by a helper
her my C code
---C code---
my personal .h file
class cESPCustomDevice : public PollingComponent, public Sensor {
public:
float param1, param2, param3;
cESPCustomDevice(float p1, float p2, float p3) : PollingComponent(100) { //costructor
param1 = p1;
param2 = p2;
param3 = p3;
};
Sensor *MySensor = new Sensor();
....
MySensor->publish_state(val);
}
so once defined in H.A. a helper “input_number.param1”
I have this YAML
---YAML code---
#definition of a "local" entity 'par1' equal to the global H.A. entity input_number.param1
sensor:
- platform: homeassistant
name: "Param_1"
entity_id: input_number.param1
id: par1
- ...Param_2
- ...Param_3
#using the local entity id(par1).stateto pass at the my class "cESPCustomDevice" the value of
# global entity input_number.param1 (H.A. helper)
- platform: custom
lambda: |-
auto esp_customcomponent = new cESPCustomDevice(id(par1).state, ... , ...);
App.register_component(esp_customcomponent);
return {esp_customcomponent->MySensor};
This trick WORKS fine but my question is:
There is a EASIER and DIRECT solution to pass the entity value “input_number.param1” in the YAML file instead to define a local entity “par1” and passing it ???
I guess this is a bit redudant and there shoul be an simpler way.
I tried with
- platform: custom
lambda: |-
auto esp_customcomponent = new cESPCustomDevice(id(input_number.param1).state, ... , ...);
and also
auto esp_customcomponent = new cESPCustomDevice(id(input_number.param1).currentstate, ... , ...);
But it doensn’t work
Somebody have a suggenstion?