Using the results of a simple GPS Rest call?

There was an error in my value template. I had "{{ value_jason.0.log }}" instead of "{{ value_json.0.log }}". I have corrected this above.

yeah, but its not the value template, if i just use ā€œokā€ there, and use attributes, i get sale error

dont think the null is causing it , i have seen others with null too before in json
i would test it , but how can i remove those null values before parsing it?

No the value template canā€™t be used.

Not sure about the replacement. Iā€™m just saying that is the only thing I can think of.
Except trying it in Node red, since you will be able to parse and manipulate the values before it entering HA there.

dont have nodered either :slight_smile:

i tried another one, without any null values, gives me same error??

  - platform: rest
    name: GPS365_Status_2
    resource: http://365gps.com/n365_utime.php?imei=123456789&sec=60&hw=apk
    headers:
      Content-Type: application/json    
    scan_interval: 300 
    value_template: "OK"
    json_attributes:
       - result

2021-12-06 12:17:53 WARNING (MainThread) [homeassistant.components.rest.sensor] REST result could not be parsed as JSON

you can test the command too if you want :

curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_utime.php?imei=123456&sec=60&hw=apk"

just pasted a fake IMEI number, but gives results

As expected, there is a bad character in the string.
But Node red can parse it when you remove that character.

What is the bad character? Can it be removed with the sensor? Donā€™t have nosered

Donā€™t know what it is but itā€™s the first character.

Itā€™s one horrible click to install.

it seems thereā€™s a bug in your device. If you donā€™t want to use node red, you can use the rest integration.

rest:
  - resource: http://server/n365_ilist.php?hw=iOS&imei=IMEI&pw=PASSWORD
    scan_interval: 300
    sensor:
   - name: Google
     value_template: "{{ (value[1:] | from_json)[0].google }}"
   - name: Logs
     value_template: "{{ (value[1:] | from_json)[0].log[3:] | as_datetime }}"
     device_class: timestamp
   - name: Gps
     value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[5:7] | join(', ') }}"

this creates 3 sensors. 2 with gps cords, 1 timestamp.

1 Like

Thank you ! This works.

FYI the timestamp one will have a warning in 2021.12 that will get fixed sometime in the future and you can safely ignore it

nice!!

@john2014 , now we have the coordinates, how can we build a device tracker from it? to show on map?

btw, i also now have extra commands, like remote on/off / reboot / shutdown / fnd on/off / enabe trackign / playback history / ā€¦

gonna make some shell commands from it, so i can use them in HA
if interested ā€¦

we are thinking the same thing :). Already looking at this post How to create a custom device tracker (from GPS coordinates)? - Configuration - Home Assistant Community (home-assistant.io) but not that familair on this. Will need to read about this a bit more.

ok, gonna read about it , stuff for tomorrow
anyway, if you already have it pls paste

below are the commands i took from the android app, for me the most imortant onesā€¦

gps365_get_status: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_ilist.php?hw=apk&imei=111111111123456&pw=123456"
gps365_remote_shutdown: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_req.php?imei=111111111123456&req=49&hw=apk"
gps365_remote_reboot: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_req.php?imei=111111111123456&req=48&hw=apk"
gps365_remote_off: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_sav.php?imei=111111111123456&msg=01010000000001000000000000"
gps365_remote_on: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_sav.php?imei=111111111123456&msg=01000000000001000000000000"
gps365_interval_600: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_utime.php?imei=111111111123456&sec=600&hw=apk"
gps365_interval_60: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_utime.php?imei=111111111123456&sec=60&hw=apk"
gps365_sleep: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_utime.php?imei=111111111123456&sec=65535&hw=apk"
gps365_get_location: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_loc.php?imei=111111111123456&t=1&hw=apk"
gps365_find_on: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_find.php?status=1&imei=111111111123456&hw=apk"
gps365_find_off: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_find.php?status=0&imei=111111111123456&hw=apk"
gps365_playback: curl -X GET -H "Content-type: application/json" -H "Accept: application/json" "http://365gps.com/n365_route.php?imei=111111111123456&sd=2021-11-21+23%3A00%3A00&ed=2021-11-22+22%3A59%3A00"

Use the device_tracker.see in an automation to make a device tracker.

- alias: My GPS automation
  mode: parallel
  trigger:
  - platform: state
    entity_id:
    - sensor.google
    - sensor.gps
  variables:
    coords: >
      {{ trigger.to_state.state.split(',') | list if trigger is not none and trigger.to_state is defined else none }}
  condition:
  - condition: template
    value_template: "{{ coords | length == 2 }}"
  action:
  - service: device_tracker.see
    data:
      dev_id: "{{ trigger.to_state.entity_id.replace('.','_') }}"
      gps: "{{ coords }}"

I think I got it.

I changed the solution of petro a bit to have seperate sensors for lon and lat

    resource: http://server/n365_ilist.php?hw=iOS&imei=IMEI&pw=PASSWORD   
    scan_interval: 300
    sensor:
    - name: Google
      value_template: "{{ (value[1:] | from_json)[0].google }}"
    - name: Logs
      value_template: "{{ (value[1:] | from_json)[0].log[3:] | as_datetime }}"
      device_class: timestamp
    - name: GpsLON
      value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[5] }}"
    - name: GpsLAT
      value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[6] }}"

Then create an automation

trigger:
  - platform: state
    entity_id: sensor.gpslat, sensor.gpslon
action:
  - service: device_tracker.see
    data_template:
      dev_id: cargps
      gps:
        - '{{ states(''sensor.gpslat'') }}'
        - '{{ states(''sensor.gpslon'') }}'

This will create an entity cargps
image

Which you should be able to use on the map card

Thnx @petro as always!! Thnx @john2014 for sharing!!

One correction it should be

    - name: GpsLAT
      value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[5] }}"
    - name: GpsLON
      value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[6] }}"

I had mixed up the LON and LAT

I am seeing my car now on a map on my dashboard.

Maybe also usefull to include battery in the device tracker?