Ahhh yes. You’re using the action there. I went a bit deeper for simplicity.
Keep in mind Otto is a refactor ninja and this is not documented/supported api. So be ready to face a compilation error in future versions.
In the current version set_service and set_data seems to be absent. Rather there is add_data, add_data_template, add_variable functions.
api::HomeAssistantServiceCallAction<> *ha_service;
ha_service = new api::HomeAssistantServiceCallAction<>(&*api_apiserver, true);
ha_service->add_data("entity_id", "input_boolean.cycle1_enable");
ha_service->play();
I made it this far but can’t figure out how to set the service to call. There seems to function called TEMPLATABLE_STRING_VALUE but I couldn’t get it to work. I would have set the service variable directly but it is private.
Also, I tried this in desperation, doesn’t work and makes it disconnect from HA and reconnect.
Hi, I’m having this exact problem. I have a custom component that defines a callback function. Inside this callback I want to call a HA service, but all this logic is defined as a lambda. Is there some new info about how to do that?
I’m also trying to call a home assistant service from within a lambda in ESPHome.
I’ve tried the various snippets of code in this topic but couldn’t get anything working.
Does anybody have a working example of how to call a home assistant service from within lambda code in ESPHOME?
Thanks!
I’m trying to call the service light.turn_on with rgb_color parameter, which requires an array of integers (I’ve tested and it also works with an array of strings of numbers).
This is how to call the service in Home Assistant:
Any idea on how to pass the array thru the API in a lambda call?
The resp.data.push_back(entity_id_kv); works fine with strings or numbers (converted to strings), but I’m struggling with this array for rgb_color.
Compiling .pioenvs/esphome-web-6a0ed4/src/main.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:2024:52: error: 'MY_API_KEY' was not declared in this scope
api_id = new globals::GlobalsComponent<char[50]>(MY_API_KEY);
I have searched the forums and done web searches, and I don’t see where/how api_id is supposed to be set.
Which error message do you have when compiling?
Could you please share that and also your whole yaml, please?
Please remove any sensitive information before sharing.
Wow - it must have been a temporary thing – I compiled again today, and it worked and installed. And, it does what I want it to do: I can control my house lights using the buttons on the m5stack.