I’ve got an extremely simple fan template setup right now. For some reason, whenever I turn this template fan off and on again, the fan speed percentage becomes 1%, even though the input_number
helper still has its old value. For example, I would set the fan speed to 33% (my fan has 9 speeds), then turn the fan off. When I turn the fan back on, the fan speed for the fan would show up as 1% instead of 33%. When I check the input_number entity, it still shows as 33%.
Does anyone know why that might be?
Here’s my really simple template:
- platform: template
fans:
living_room_fan:
friendly_name: "Living Room Fan"
unique_id: "living_room_fan"
value_template: "{{ states('input_boolean.ceiling_fan_state') }}"
speed_template: "{{ states('input_number.ceiling_fan_speed') }}"
speed_count: 9
turn_on:
service: input_boolean.turn_on
target:
entity_id: input_boolean.ceiling_fan_state
turn_off:
service: input_boolean.turn_off
target:
entity_id: input_boolean.ceiling_fan_state
set_percentage:
service: input_number.set_value
target:
entity_id: input_number.ceiling_fan_speed
data:
value: "{{ percentage }}"
My input_number
is set to have a minimum of 0 and a maximum of 100, with a step size of 1. I’m currently detecting the change in the input_number and input_boolean to control the fan, which is why you don’t see me calling any services in the template.
koying
(Chris B)
July 24, 2021, 11:06am
2
That’s likely important to include as well
I resolved the problem! It turns out I was using speed_template
instead of percentage_template
in the config! Once the config was updated, the percentage no longer resets. Perhaps the reason why it always “resets” was that speed_template
expected a much smaller value than the percentage value in my input_number.
Only noticed this as I was re-reading my post. I guess this was a case of rubber ducky debugging haha.
brunoap
(Bruno)
February 9, 2022, 3:50am
4
Hi. I do have percentage_template and the same erratic behavior occurs. When turned off and back to on, percentage slider goes to 0. Input number keeps the correct states.
brunoap
(Bruno)
March 11, 2022, 10:52pm
5
Fan toggle missing percentage has been fixed:
home-assistant:dev
← home-assistant:frenck-2022-0511
opened 03:56PM - 04 Mar 22 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
Fixes an issue reported in #67266.
Template fans update their preset/percentage based on template changes (e.g., a used entity in that template changes). However, in the current situation, when turning off a template fan, it will also reset the internal preset/percentage values.
This causes issues when turning on the fan later, as it would have reset preset/percentage, which isn't corrected until the template rendering re-triggers.
This change makes it behave consistently and as expected.
![2022-03-03 15 09 22](https://user-images.githubusercontent.com/195327/156796336-23545859-13f1-4a2e-b1eb-6ea88e8fc510.gif)
## 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
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] 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 #67266
- 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.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] The code has been formatted using Black (`black --fast homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] 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`.
The integration reached or maintains the following [Integration Quality Scale][quality-scale]:
<!--
The Integration Quality Scale scores an integration on the code quality
and user experience. Each level of the quality scale consists of a list
of requirements. We highly recommend getting your integration scored!
-->
- [x] No score or internal
- [ ] 🥈 Silver
- [ ] 🥇 Gold
- [ ] 🏆 Platinum
<!--
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:
- [x] 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/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io