-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add template extension coordinates #30019
Conversation
this is very nice indeed! thanks for working on this, highly anticipated functionality!. might I suggest 2 further improvements ?
cheers, thanks for considering. |
@Mariusthvdb to your suggestions:
This was not done for several reasons:
|
yes on both accounts. about needing _template or not: not really sure tbh if there are other integrations. I do know several custom Lovelace cards simply accept templates or fixed values regardless. I know that is not the same, but one easily gets used to that friendly configuration.. about the other question, you might be right on track! Suppose it would be best if HA system wide would simply accept templates on all config fields... as long as that is not the case, your solution might be wisest. |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Keep open |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Still open |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, please fix the conflict
fafb720
to
4c015b7
Compare
homeassistant/helpers/template.py
Outdated
return None | ||
|
||
|
||
def _entity_state_is_valid_coordinate_set(state: str) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only used once, you can also use:
try:
cv.gps(state.split(","))
except vol.Invalid:
_LOGGER.error(...)
else:
return entity.state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the function
Done |
return _get_location_from_attributes(entity) | ||
|
||
# Check if device is in a zone | ||
zone_entity = _resolve_state(hass, f"zone.{entity.state}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zone_entity = _resolve_state(hass, f"zone.{entity.state}") | |
zone_entity = hass.states.get(entity.state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting your state to the entity ID of a zone is not an official supported "thing", we shouldn't encode it in our template helper unless we want to adopt this.
Let's remove this support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this PR is to put logic in the template helper to make passing a parameter to a sensor easier. That doesn't make sense.
If this is something that the sensor wants to support, they should just implement it.
As I explained in the description this functionality was discussed several times already. My preference would still be to implement it directly into |
I think it's fine to add a helper to It's not fine to hijack templates for a one-off function. |
I opened a new PR #37234 to add the function under |
Description:
This template extension will allow for a clean and reusable way to enable dynamic
travel_time
sensors. The issue was discussed several times in the forum here and here as well as in the PRs #27237 #28716.Using this template the following config is possible:
The simple case
{{ coordinates('device_tracker.myphone') }}
can already be accomplished with existing methods but now the user does not have to know that adevice_tracker
storeslatitude
andlongitude
as attributes.The nested case
{{ coordinates('input_select.here_destination_preset') }}
is currently only possible by creating a complex structure of dependenttemplate_sensors
using complex templates.Related issue (if applicable): fixes #TBD
Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#11482
Example entry for
configuration.yaml
(if applicable):See above.
Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest
.requirements_all.txt
by runningpython3 -m script.gen_requirements_all
..coveragerc
.If the code does not interact with devices: