- id: GPS_update
alias: Set GPS coordinates
trigger:
- platform: webhook
webhook_id: update_gps
allowed_methods:
- POST
- PUT
local_only: false
action:
- service: python_script.set_state
data_template:
entity_id: device_tracker.{{trigger.data.device}}
latitude: '{{trigger.data.latitude}}'
longitude: '{{trigger.data.longitude}}'
gps_accuracy: '{{trigger.data.accuracy}}'
battery_level: '{{trigger.data.battery}}'
speed: '{{trigger.data.speed}}'
altitude: '{{trigger.data.altitude}}'
If a python script somehow sets the coordinates without calling the proper services, I would not be surprised if the proximity integration does not work. I would not think you’d need python code to get the webhook data in a device tracker. It could be done using normal automations.
#==================================================================================================
# python_scripts/set_state.py
# modified from - https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975/37
#==================================================================================================
#--------------------------------------------------------------------------------------------------
# Set the state or other attributes for the entity specified in the Automation Action
#--------------------------------------------------------------------------------------------------
inputEntity = data.get('entity_id')
if inputEntity is None:
logger.warning("===== entity_id is required if you want to set something.")
else:
inputStateObject = hass.states.get(inputEntity)
if inputStateObject is None and not data.get('allow_create'):
logger.warning("===== unknown entity_id: %s", inputEntity)
else:
if not inputStateObject is None:
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()
else:
inputAttributesObject = {}
for item in data:
newAttribute = data.get(item)
logger.debug("===== item = {0}; value = {1}".format(item,newAttribute))
if item == 'entity_id':
continue # already handled
elif item == 'allow_create':
continue # already handled
elif item == 'state':
inputState = newAttribute
else:
inputAttributesObject[item] = newAttribute
hass.states.set(inputEntity, inputState, inputAttributesObject)
Well no, all the variables come from the webhook via Tasker. They’re accurate, and I show up correctly on the map.
They can be correct, perfect even. but that is not what I meant. For instance setting correct values in developer tools is not the same as setting the value of entities the way it was intended. Different things might happen.
So it is not the correctness of the values, but the way they are set that might not be picked up by the proximity integration. So if it does not work, that is where you should look. To be sure, you could try an entity created by the companion app instead to see if that does work.
But it is easy though, just replace the pythin script with the device_tracker.see action call. You’ll miss the altitude, but the rest is there. That action is the official way, why use python to go around it? The python will break sooner or later.