Using the results of a simple GPS Rest call?

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?

If you use your original setup with the automation I posted, it will work for both google and gps

In my case, it’s a cat :slight_smile: so I know where he is :slight_smile:

I tried copy pasting your automation but keep getting

Message malformed: extra keys not allowed @ data[‘condition’][0][‘value_tempate’]

The way I tried it is to create a new empty automation from the UI and then paste. Then I have to change it a bit as the yaml there is different then the one you pasted. Also tried to just copy your automation in automation.yaml, but also that gives errors. I am very unfamiliar with this so not sure what to change.

@petro
the command sometimes gives

`"log": "OUT 2021-12-06 14:17:12",`

or

`"log": "IN 2021-12-06 14:17:12",`

i’m interested in the words IN or OUT in that json, that means if the device is ON or OFF

how can i create the value template so it creates the word on/off ?

    - name: GPS365_Online
      value_template: "{{ (value[1:] | from_json)[0].log.split(' ')[0:1] }}"

that already gives me : ['OUT']

check it against the word out then using ==

like this?

    - name: GPS365_Online
      #value_template: "{{ (value[1:] | from_json)[0].log.split(' ')[0:1] }}"
      value_template: >
        {% (value[1:] | from_json)[0].log.split(' ')[0:1]  == ['OUT'] %}
          off
        {% else %}
          on
        {% endif %}

gives me template syntax error :’

crap, forgot the if word

you’re missing if, and you added brackets around out.

1 Like