I’m either having a mental block or doing something wrong. I’m prepping for a project on ESP home so I am just running through some features that I will need which include both subscribing and registering services. I’ve created a test component that inherits public CustomAPIDevice. I have no issue subscribing to a service.
I cannot get a registered service on the ESP board to appear in HA. From what little documentation I can find, the register_service call should take care of everything and it should show up in the entity in HA.
void setup() override {
// This will be called by App.setup()
register_service(&HotTub::on_hello_world, "hello_world");
subscribe_homeassistant_state(&HotTub::on_state_changed, "switch.window_fan");
}
on_state_changed works fine, hello_world never appears in HA.
void on_state_changed(std::string state)
{
ESP_LOGD("custom", "Window fan state changed");
}
void on_hello_world() {
ESP_LOGD("custom", "Hello World!");
}
zoogara
(Daryl)
August 12, 2023, 5:01am
2
I assume you are writing a custom component and thus calling the api service in code rather than yaml?
The devs may be better to ask - find them on Discord:
Yes this is going to be a highly customized component.
There was a breaking change not long ago which makes it necessary for new esphome (node) integrations to manually allow service calls
home-assistant:dev
← home-assistant:esphome_service_calls_turn_on
opened 07:11PM - 23 Jun 23 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Breaking change
<!--
If your PR contains a breaking change for existing users, it is important
to tell them what breaks, how to make it work again and why we did this.
This piece of text is published with the release notes, so it helps if you
write it towards our users, not us.
Note: Remove this section if this PR is NOT a breaking change.
-->
As a security hardening measure, the default for allowing ESPHome devices to make service calls has changed. If you want to permit the ESPHome device to make service calls, it must be enabled in the options flow.
- For existing devices, calling Home Assistant services continues to be allowed.
- For newly configured devices, it must now be enabled in the options flow.
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [x] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request:
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [ ] Local tests pass. **Your PR cannot be merged unless tests pass**
- [ ] There is no commented out code in this PR.
- [ ] I have followed the [development checklist][dev-checklist]
- [ ] I have followed the [perfect PR recommendations][perfect-pr]
- [ ] The code has been formatted using Black (`black --fast homeassistant tests`)
- [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/development_checklist/
[manifest-docs]: https://developers.home-assistant.io/docs/creating_integration_manifest/
[quality-scale]: https://developers.home-assistant.io/docs/integration_quality_scale_index/
[docs-repository]: https://github.com/home-assistant/home-assistant.io
[perfect-pr]: https://developers.home-assistant.io/docs/review-process/#creating-the-perfect-pr
1 Like
Thank you so much for the information, I honestly would have never found that. So my takeaway is that somewhere I either need to define “allow_service_calls” or allow_service_calls: True? I have no idea where though. I would assume in the yaml for that specific ESP device. Is there any documentation to go with this change?
Rudd-O
(Rudd-O)
August 13, 2023, 1:21am
7
you have to tick a box in the device config page for the integration
Ok this has unveiled some new information. My version of HA was old enough that the option didnt exist. I updated to the latest and now I see the option “Allow the device to make Home Assistant service calls”. Since I set up the ESP home on the old HA version this box was already checked. That makes sense since the breaking change mentions that it only applies on new devices going forward.
So I guess this brings me back to my original question of how to get registered services to show up in HA. The breaking change seems to have not been relevant.
Developer Tools > Services
If you start type esphome
into the box only esphome services will show
gaz99
(Gaz)
August 14, 2023, 12:58am
10
I’m still lost here, where in the Esphome integration did you find this option ?
I have a new test device using Esphome 2023.7.1 and it is configured in HAOS 2023.8.1 and can’t find it.
Once you have the latest HA. Its in setting → devices & services → ESP home → configure
gaz99
(Gaz)
August 14, 2023, 1:57am
12
Thanks, I was going too far and clicking on the 3 dots and going to system options