wildr
1
I am sending gps data via json webhook like this:
JSON_DATA='{
"latitude": 43.287576,
"longitude": -0.360591
}'
curl \
-k -v \
-H "Content-Type: application/json" \
--data "$JSON_DATA" \
https://home.lan:8123/api/webhook/gps
I get error
Error while executing automation automation.update_gps: invalid latitude for dictionary value @ data['latitude']
the coordinates are correct; they come from the gps
why ?
here is my automation ( I tried with and without |float
converrsion )
alias: Update Zone
triggers:
- webhook_id: gps
trigger: webhook
allowed_methods:
- POST
- PUT
local_only: true
actions:
- data_template:
latitude: |
"{{ trigger.json.latitude |float }}"
longitude: |
"{{ trigger.json.longitude |float}}"
action: homeassistant.set_location
Take a look at the automation trace. It should show you the trigger data, then you can verify you are using it correctly.
I don’t think you need those | either. Just move it onto one line.
1 Like
wildr
3
I identified the issue:
looks like HA is interpreting the number with quotes
tried with and without |float
but it did not solve the issue
I triple checked that my data is being sent as Number
so I do not understand why HA would put quotes event with float conversion
Error: invalid latitude for dictionary value @ data['latitude']
Result:
params:
domain: homeassistant
service: set_location
service_data:
latitude: '"45.28757373333333"'
longitude: '"-0.5605946166666667"'
target: {}
running_script: false
wildr
4
I works !
here is the final solution:
alias: Update Zone
trigger:
- platform: webhook
webhook_id: gps
allowed_methods:
- POST
- PUT
local_only: true
action:
- service: homeassistant.set_location
data:
latitude: "{{ trigger.json.latitude | float }}"
longitude: "{{ trigger.json.longitude | float }}"
mode: single