Using the results of a simple GPS Rest call?

Those headers were not needed before, strange…
In that rest command, there is an option to add headers too, but closed laptop, stuff for next time to try

Don’t think the [] are giving issues , there were there before

yeah, they really changed a lot unfortunately.

Yeah, but you already did a nice job :+)

ok, after applying headers, it indeed works again!

rest:
  - resource_template: http://www.365gps.net/api_ilist.php?imei=XXXXX&pw=XXXXX&exp=1&tm=Android&mtype=2&ak=10{{ '%0x' % ( as_timestamp( strptime( now().strftime('%Y-%m-%d %H:%M:%S'), "%Y-%m-%d %H:%M:%S")) - ( as_timestamp(strptime("2023-01-27 00:53:36", "%Y-%m-%d %H:%M:%S")))) | int }}70&hw=apk&ver=2.21&app=n365&lang=eng
    headers:
      User-Agent: App
      Accept-Encoding: gzip
      Connection: Keep-Alive
    scan_interval: 180
    sensor:
    - name: GPS365_Google
      value_template: "{{ (value[1:] | from_json)[0].google }}"
    - name: Gps365_LAT
      value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[5] }}"
    - name: Gps365_LON
      value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[6] }}"      
    - name: GPS365_Battery
      value_template: "{{ (value[1:] | from_json)[0].bat }}"
    - name: GPS365_Update
      value_template: "{{ (value[1:] | from_json)[0].sec }}"
    - name: GPS365_On_off
      value_template: >
        {% if (value[1:] | from_json)[0].log.split(' ')[0] == 'OUT' %}
          off
        {% else %}
          on
        {% endif %}
1 Like

nice!, I think i will go back to you solution then, as its a bit cleaner then using the Python scrypt.

1 Like

We will need to see what’s going to happen in next month… The prefix “10” is just maybe “1” and the 0 is a leading zero of the hex values what’s next

Also the unknown last 2 digits…

if the first 2 digits are also part of the counter, then we would need to change the start date to Saturday, 16 July 2022, 19:33:20 according to this calculation. I just took one of the calls of the APP and that gave 10ae4da as a result, which is 17491162 seconds. If I subtract it from the date/time of the call, i would get to that new date. But lets see what happens :slight_smile:

Date Calculator: Add to or Subtract From a Date – Results (timeanddate.com)

Indeed, and maybe the last digits are miliseconds

Maybe its indeed better to already change the date and include the leading 10

hmm, that date in july does not seem correct, so we indeed need to see what will happen. If the july date was correct, the result should have the same result (besides the 10)

ah the time was not correct this does seem to work.

So 16 July 2022, 21:33:20

Yeah, and maybe the last digits is some kind of offset, a mismatch between the GET and the datenow…

Because if you lower it, it fails, the higher the value, it succeeds

Hey guy’s, i can’t get it working, i’m close.

http://47.75.106.117/api_ilist.php?imei=xxxxxxx&pw=xxxxxxx&exp=1&tm=Android&mtype=2&ak={{ ‘%0x’ % ( as_timestamp( strptime( now().strftime(’%Y-%m-%d %H:%M:%S’), “%Y-%m-%d %H:%M:%S”)) - ( as_timestamp(strptime(“2022-07-16 21:33:20”, “%Y-%m-%d %H:%M:%S”)))) | int }}70&hw=apk&ver=4.18&app=n365&lang=eng

Your posts always work only now i am stuck :slight_smile:

It still works here, put that complete url in the template editor, then quick copy paste the output in a browser, what do see then?

http://www.365gps.net/api_ilist.php?imei=xxxxxxxx&pw=xxxxxxx&exp=1&tm=Android&mtype=2&ak={{ ‘%0x’ % ( as_timestamp( strptime( now().strftime(’%Y-%m-%d %H:%M:%S’), “%Y-%m-%d %H:%M:%S”)) - ( as_timestamp(strptime(“2022-07-16 21:33:20”, “%Y-%m-%d %H:%M:%S”)))) | int }}70&hw=apk&ver=4.18&app=n365&lang=eng

with this code and the template editor i get the output i want.

[{“login”:“noki66”,“imei”:“xxxxxxxx”,“name”:“Sem”,“carno”:“4”,“gps”:“2023-02-08 12:13:48,6,1,0,39,51.906983,4.317183,112”,“log”:“IN 2023-02-08 17:42:45”,“google”:“51.906983,4.317183”,“baidu”:“51.910487,4.340957”,“speed”:null,“bat”:“96”,“icon”:“1”,“marker”:“0”,“device”:“303N”,“ver”:“90;0000;0”,“sec”:“10”,“level”:“42”,“expdate”:null,“loc”:“XX”,“onoff”:“0”,“gexpdate”:null,“iccid”:“89882280666054440718”,“ggkey”:null,“startdate”:“2023-01-05”,“pic”:“2”}]

this yaml code

rest:

  • resource_template: xxxxxxxxxx (the correct api link)
    headers:
    User-Agent: App
    Accept-Encoding: gzip
    Connection: Keep-Alive
    scan_interval: 180
    sensor:
    • name: GPS365_Google
      value_template: “{{ (value[1:] | from_json)[0].google }}”
    • name: Gps365_LAT
      value_template: “{{ (value[1:] | from_json)[0].gps.split(’,’)[5] }}”
    • name: Gps365_LON
      value_template: “{{ (value[1:] | from_json)[0].gps.split(’,’)[6] }}”
    • name: GPS365_Battery
      value_template: “{{ (value[1:] | from_json)[0].bat }}”
    • name: GPS365_Update
      value_template: “{{ (value[1:] | from_json)[0].sec }}”
    • name: GPS365_On_off
      value_template: >
      {% if (value[1:] | from_json)[0].log.split(’ ')[0] == ‘OUT’ %}
      off
      {% else %}
      on
      {% endif %}

and the automation from befor (the working version from 1 week ago)

But i still can’t keep it working

Seems ok, do you have the sensors in HA? Or any error ?

Also format your code , we can’t read it like that :slight_smile:

rest:

  - resource:http://www.365gps.net/api_ilist.php?imei=xxxxxxxxxx&pw=xxxxxxxxxx&exp=1&tm=Android&mtype=2&ak={{ '%0x' % ( as_timestamp( strptime( now().strftime('%Y-%m-%d %H:%M:%S'), "%Y-%m-%d %H:%M:%S")) - ( as_timestamp(strptime("2022-07-16 21:33:20", "%Y-%m-%d %H:%M:%S")))) | int }}70&hw=apk&ver=4.18&app=n365&lang=eng

    headers:
      User-Agent: App
      Accept-Encoding: gzip
      Connection: Keep-Alive
      scan_interval: 00:00:20
    sensor:
    - name: GPS365_Google
      unique_id: GPS365_Google
      value_template: "{{ (value[1:] | from_json)[0].google }}"
    - name: Gps365_LAT
      unique_id: Gps365_LAT
      value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[5] }}"
    - name: Gps365_LON
      unique_id: Gps365_LON
      value_template: "{{ (value[1:] | from_json)[0].gps.split(',')[6] }}"      
    - name: GPS365_Battery
      unique_id: GPS365_Battery
      value_template: "{{ (value[1:] | from_json)[0].bat }}"
    - name: GPS365_Update
      unique_id: GPS365_Update
      value_template: "{{ (value[1:] | from_json)[0].sec }}"
    - name: GPS365_On_off
      unique_id: GPS365_On_off
      value_template: >
        {% if (value[1:] | from_json)[0].log.split(' ')[0] == 'OUT' %}
          off
        {% else %}
          on
        {% endif %}

log is coming :slight_smile:

log :slight_smile: