seems something is wrong again, now I get “{“result”:“Error”}”
using fiddler, i managed to get a working URL again, but it is completely different now it seems.
The tm and ak fields seem specific to my phone, and removing them will just give an error
old URL i used:
http://120.76.241.191/n365_ilist.php?hw=iOS&imei=[IMEI]&pw=[PWD]&ver=4.10
new url that seems to work:
http://47.75.106.117/api_ilist.php?imei=[IMEI]&pw=[PWD]&exp=1&tm=[some kind of identifier for phone]&mtype=2&ak=[no idea what this is]&hw=apk&ver=2.21&app=n365&lang=eng
yeah , i noticed too, didnt investigate it yet
thnx for info!
What values are you using for TM and AK ?
they are strings that seem to be specific to my phone, so I am not sure if i can/should share those here. The TM contains the name of the phone and some local indicators and a number. The AK value seems like a hexadecimal code, but no idea what it is.
ok, gonna check with fiddler next time
do you mitm the apk file before tracing or is the app not encrypted?
i checked the app on playstore, i use this one, but seems it isnt updated?
strange then that the urls are different
seems also the commands like remote on OR remote off are still working
these ones for ex:
gps365_remote_off-: "curl -X GET -H 'Content-type: application/json' -H 'Accept: application/json' 'http://365gps.com/n365_sav.php?imei=XXXXX&msg=01010000000001000000000000'"
gps365_remote_on-: "curl -X GET -H 'Content-type: application/json' -H 'Accept: application/json' 'http://365gps.com/n365_sav.php?imei=XXXXXX&msg=01000000000001000000000000'"
I got an update message when starting the app, it then downloaded an APK that I installed. I can send you the updated apk if you want
yeah, allthough i used fiddler, but i just get an empty response when i test with curl now
Seems the AK is always changing? i think its somekind of token now
can you post your curl url again without the AK ?
i think mine is wrong, everytime i start app, i get an update warning, but it doesnt do anything, it doesnt download the apk
Full working solution again:
Add the following to your configuration.yaml
- platform: command_line
name: gpscommandline
json_attributes:
- google
value_template: "{{ value_json['google'] }}"
command: 'python3 365get.py'
scan_interval: 55
Then create an automation along the lines of this, this will create an entity that you can use on the map card:
alias: Auto - Create device tracker for CAR
trigger:
- platform: state
entity_id:
- sensor.gpscommandline
action:
- service: device_tracker.see
data:
dev_id: cargps
gps:
- "{{states('sensor.gpscommandline').split(',')[0]}}"
- "{{states('sensor.gpscommandline').split(',')[1]}}"
Final step is to create a python file in your HA folder. Name it “365get.py”. And it should contain the following code.
Note that if you are not in my timezone (GMT+1 (Amsterdam)), then you might need to change the line
dateTimeObj = datetime.datetime(2023, 1, 27, 0, 53, 36)
For some reason, the call to get the coordinates contains a weird timestamp that contains the number of seconds since that day. But if you are in another timezone, you need to add or subtract an hour (which is the 4th field in there))
I have to see if/when it breaks as the timecode is a bit of a hacky solution atm.
Python code
# Import the datetime module
import datetime
import requests
# Create a datetime object for the given date
dateTimeObj = datetime.datetime(2023, 1, 27, 0, 53, 36)
# Get the current time
currentTime = datetime.datetime.now()
# Calculate the seconds since the given date
secondsSince = (currentTime - dateTimeObj).total_seconds()
# Convert the value to hexadecimal
hexValue = hex(int(secondsSince))[2:]
# Convert the hexadecimal to a string
stringValue = str(hexValue)
# Add "10" to the start and "70" to the end
stringValue = "10" + stringValue + "70"
imei="yourIMEI"
pwd="yourpassword"
fullurlstring = "http://www.365gps.net/api_ilist.php?imei="+ imei+"&pw="+pwd+"&exp=1&tm=Xiaomi-31+M2012K11AG+nl_NL_M2&mtype=2&ak="+stringValue+ "&hw=apk&ver=2.21&app=n365&lang=eng"
# Set proper headers
headers = {"User-Agent":"App","Accept-Encoding":"gzip","Connection":"Keep-Alive"}
r = requests.get(url = fullurlstring,headers=headers)
print(r.text[2:-1])
hey @john2014 , below is the jinja that you can use in your command line/rest sensor, so you dont need the script…, you can add the “10” and “70” to front and back manually
{% set time = "2023-01-27 00:53:36" %}
{{ '%0x' % ( as_timestamp( strptime( now().strftime('%Y-%m-%d %H:%M:%S'), "%Y-%m-%d %H:%M:%S")) - ( as_timestamp(strptime(time, "%Y-%m-%d %H:%M:%S"))) ) | int }}
nice! much better solution this way indeed.
Hmm, i really don’t understand jinja at all. Dont really see how I can use this in my configuration.yaml. Do you have an example?
not tested, but something like this:
rest:
- resource_template: http://www.365gps.net/api_ilist.php?imei=XXXXXX&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
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 %}
didnt check, but was the json result with our new method exact same as before?
hmm, that one is giving log issues, maybe templating not allowed in rest command
this doesnt give errors, allthough the json doesnt populate
- platform: command_line
command: >
curl
-X GET -H 'Content-type: application/json' -H 'Accept: application/json'
"http://www.365gps.net/api_ilist.php?imei=XXXX&pw=XXXX&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"
name: 365GPS_Sensor
scan_interval: 60
value_template: "365Gps Sensor"
json_attributes:
- name
- google
- bat
the jinja template is correct, because if i copy paste the command in template editor, and then copy/paste to browser, i get a json
its possible the command line sensor doesnt give “real” json and needs to be converted to json first
or like below, but not getting data yet, not sure whats wrong
- platform: rest
name: 365Gps Sensor
resource_template: http://www.365gps.net/api_ilist.php?imei=XXXXX&pw=XXXX&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
method: GET
scan_interval: 90
value_template: "365Gps Sensor"
json_attributes:
- name
- google
- bat
The response has a leading square bracket and also a square bracket at the end. But also, if you dont provide the correct headers, the response is empty. So what I did in my python script is add the exact headers as I saw coming from the app. And then also remove the square brackets. Thats probably what is causing your issues.
Ah ok, didn’t notice, ok stuff for next time
Almost there