I now have:
Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false"
Moderator: leecollings
Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false"
2018-02-20 18:00:15.317 dzVents: The iPhone check script is running
2018-02-20 18:00:22.652 dzVents: The iPhone check script is running
2018-02-20 18:00:29.354 dzVents: The iPhone check script is running
2018-02-20 18:00:32.940 dzVents: The iPhone check script is running
2018-02-20 18:00:36.976 dzVents: The iPhone check script is running
2018-02-20 18:00:44.629 dzVents: The iPhone check script is running
2018-02-20 18:00:52.070 dzVents: The iPhone check script is running
2018-02-20 18:00:55.461 dzVents: The iPhone check script is running
2018-02-20 18:00:59.058 dzVents: The iPhone check script is running
2018-02-20 18:25:00.169 dzVents: The iPhone check script is running
2018-02-20 18:25:04.156 dzVents: The iPhone check script is running
2018-02-20 18:25:07.449 dzVents: The iPhone check script is running
2018-02-20 18:25:14.613 dzVents: The iPhone check script is running
2018-02-20 18:25:22.316 dzVents: The iPhone check script is running
2018-02-20 18:25:25.731 dzVents: The iPhone check script is running
2018-02-20 18:25:32.835 dzVents: The iPhone check script is running
2018-02-20 18:25:36.534 dzVents: The iPhone check script is running
2018-02-20 18:25:43.779 dzVents: The iPhone check script is running
2018-02-20 18:25:47.470 dzVents: The iPhone check script is running
2018-02-20 18:25:51.075 dzVents: The iPhone check script is running
2018-02-20 18:25:54.718 dzVents: The iPhone check script is running
I have remade this script but I don't have finish. I will post here when I do.dens1975 wrote: ↑Tuesday 20 February 2018 16:55 Thanks landaisbenj but do you have an example how to add a condition?
I now have:Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false"
Here you have a script for all. Device time and variable. So ever a change appear in that 3 stuff you do the script. Make this script has time.numanx wrote: ↑Tuesday 20 February 2018 18:04 I've added print('The iPhone check script is running') right after the if statement.
Right now the interval set to 25 and here is the log output:
2018-02-20 18:00:15.317 dzVents: The iPhone check script is running
2018-02-20 18:00:22.652 dzVents: The iPhone check script is running
2018-02-20 18:00:29.354 dzVents: The iPhone check script is running
2018-02-20 18:00:32.940 dzVents: The iPhone check script is running
2018-02-20 18:00:36.976 dzVents: The iPhone check script is running
2018-02-20 18:00:44.629 dzVents: The iPhone check script is running
2018-02-20 18:00:52.070 dzVents: The iPhone check script is running
2018-02-20 18:00:55.461 dzVents: The iPhone check script is running
2018-02-20 18:00:59.058 dzVents: The iPhone check script is running
2018-02-20 18:25:00.169 dzVents: The iPhone check script is running
2018-02-20 18:25:04.156 dzVents: The iPhone check script is running
2018-02-20 18:25:07.449 dzVents: The iPhone check script is running
2018-02-20 18:25:14.613 dzVents: The iPhone check script is running
2018-02-20 18:25:22.316 dzVents: The iPhone check script is running
2018-02-20 18:25:25.731 dzVents: The iPhone check script is running
2018-02-20 18:25:32.835 dzVents: The iPhone check script is running
2018-02-20 18:25:36.534 dzVents: The iPhone check script is running
2018-02-20 18:25:43.779 dzVents: The iPhone check script is running
2018-02-20 18:25:47.470 dzVents: The iPhone check script is running
2018-02-20 18:25:51.075 dzVents: The iPhone check script is running
2018-02-20 18:25:54.718 dzVents: The iPhone check script is running
landaisbenj wrote: ↑Tuesday 20 February 2018 18:41I have remade this script but I don't have finish. I will post here when I do.dens1975 wrote: ↑Tuesday 20 February 2018 16:55 Thanks landaisbenj but do you have an example how to add a condition?
I now have:Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false"
I post gps in uservariable to get last position. On second pass I read this position, compare with present position and if difference is upper than radius, I have movement. I post in position..user just "movement". And if difference is under radius, and if position..user equal movement I do google request and I post it in position..user. It's ok?
Here you have a script for all. Device time and variable. So ever a change appear in that 3 stuff you do the script. Make this script as time.numanx wrote: ↑Tuesday 20 February 2018 18:04 I've added print('The iPhone check script is running') right after the if statement.
Right now the interval set to 25 and here is the log output:
2018-02-20 18:00:15.317 dzVents: The iPhone check script is running
2018-02-20 18:00:22.652 dzVents: The iPhone check script is running
2018-02-20 18:00:29.354 dzVents: The iPhone check script is running
2018-02-20 18:00:32.940 dzVents: The iPhone check script is running
2018-02-20 18:00:36.976 dzVents: The iPhone check script is running
2018-02-20 18:00:44.629 dzVents: The iPhone check script is running
2018-02-20 18:00:52.070 dzVents: The iPhone check script is running
2018-02-20 18:00:55.461 dzVents: The iPhone check script is running
2018-02-20 18:00:59.058 dzVents: The iPhone check script is running
2018-02-20 18:25:00.169 dzVents: The iPhone check script is running
2018-02-20 18:25:04.156 dzVents: The iPhone check script is running
2018-02-20 18:25:07.449 dzVents: The iPhone check script is running
2018-02-20 18:25:14.613 dzVents: The iPhone check script is running
2018-02-20 18:25:22.316 dzVents: The iPhone check script is running
2018-02-20 18:25:25.731 dzVents: The iPhone check script is running
2018-02-20 18:25:32.835 dzVents: The iPhone check script is running
2018-02-20 18:25:36.534 dzVents: The iPhone check script is running
2018-02-20 18:25:43.779 dzVents: The iPhone check script is running
2018-02-20 18:25:47.470 dzVents: The iPhone check script is running
2018-02-20 18:25:51.075 dzVents: The iPhone check script is running
2018-02-20 18:25:54.718 dzVents: The iPhone check script is running
Make this:dens1975 wrote: ↑Tuesday 20 February 2018 16:55 Thanks landaisbenj but do you have an example how to add a condition?
I now have:Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false"
Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false&key=googlekey"
Here you have a script for all. Device time and variable. So ever a change appear in that 3 stuff you do the script. Make this script as time.
Thanks, I Added the API key but that doesn't make a difference.landaisbenj wrote: ↑Tuesday 20 February 2018 18:44Make this:dens1975 wrote: ↑Tuesday 20 February 2018 16:55 Thanks landaisbenj but do you have an example how to add a condition?
I now have:Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false"
I have remade this script but I don't have finish. I will post here when I do.Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false&key=googlekey"
I post gps in uservariable to get last position. On second pass I read this position, compare with present position and if difference is upper than radius, I have movement. I post in position..user just "movement". And if difference is under radius, and if position..user equal movement I do google request and I post it in position..user. It's ok?
I now have:
Code: Select all
command = "curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=" .. latitude .. "," .. longitude .. "&sensor=false&key=xxxxxx"
I don't see any traffic on my api if I look at my Google dashboard, so I think it's not using it.landaisbenj wrote: ↑Wednesday 21 February 2018 10:39 Ok.
I realized i'had the same problem.
In google api it says:
Free until 2 500 request by day and under 50 by seconds.... I don't think we are above.
Maybe it's curl parameter.
My bad it's filter problemlandaisbenj wrote: ↑Wednesday 21 February 2018 12:37 yes me too I Check more if I can this weekend.
I have been finish my script. I post it in same time. With it, i don't have problem with curl error.
Code: Select all
2018-03-18 18:40:01.629 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_checkphones.lua: /home/pi/domoticz/scripts/lua/script_time_checkphones.lua:29: attempt to index field '?' (a nil value)
Code: Select all
command = "curl -s --insecure -H 'Content-Type: application/json' -H 'https://maps.googleapis.com/maps/api/geocode/json?key={API_KEY}&latlng=" .. latitude .. "," .. longitude .."'"
Code: Select all
"curl -s --insecure -H 'Content-Type: application/json' 'https://maps.googleapis.com/maps/api/geocode/json?key={API_KEY}&latlng=" .. latitude .. "," .. longitude .."'"
Code: Select all
Error: EventSystem: Warning!, lua script /usr/local/domoticz/var/scripts/lua/script_time_checkphones.lua has been running for more than 10 seconds
Code: Select all
commandArray = {}
interval = 9
local m = os.date('%M')
if (m % interval == 0) then
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
-- Array of users to be checked
users = {
Iphone 1 = {username = "Email" ; password = "password" ; devicename = "Iphone 1"};
Iphone 2 = {username = "Email" ; password = "password" ; devicename = "Iphone 2"};
}
-- The latitude and longitude of your house (use Google Maps or similar to find this)
homelongitude = X.XXXXXX
homelatitude = XX.XXXXXX
-- Radius (in km) which will be used to determine if a device is at home
radius = 1.0
function address(longitude, latitude)
command = "curl -s --insecure -H 'Content-Type: application/json' 'https://maps.googleapis.com/maps/api/geocode/json?key=APIKEY&latlng=" .. latitude .. "," .. longitude .."'"
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
output = json:decode(result)
return output.results[1].formatted_address
end
for user,credentials in pairs(users) do
stage1command = "curl -s -X POST -D - -o /dev/null -L -u '" .. credentials.username .. ":" .. credentials.password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://fmipmobile.icloud.com/fmipservice/device/" .. credentials.username .."/initClient"
local handle = io.popen(stage1command)
local result = handle:read("*a")
handle:close()
stage2server = "fmipmobile.icloud.com"
stage2command = "curl -s -X POST -L -u '" .. credentials.username .. ":" .. credentials.password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://" .. stage2server .. "/fmipservice/device/" .. credentials.username .."/initClient"
local handle = io.popen(stage2command)
local result = handle:read("*a")
handle:close()
output = json:decode(result)
for key,value in pairs(output.content) do
if value.name == credentials.devicename then
lon = value.location.longitude
lat = value.location.latitude
bat = value.batteryLevel * 100 / 1
battstat = value.batteryStatus
powerstateval = value.batteryStatus
table.insert(commandArray,{['UpdateDevice'] = otherdevices_idx['iPhone Battery ' .. user] .. '|0|' .. bat})
distance = math.sqrt(((lon - homelongitude) * 111.320 * math.cos(math.rad(lat)))^2 + ((lat - homelatitude) * 110.547)^2) -- approximation
position = address(lon,lat)
position_text = string.gsub(position, ', Netherlands', '') .. ' (' .. (math.floor(distance*10+0.5)/10) .. ' km)'
--prev_distance_str = string.match(otherdevices['Position ' .. user], '%(.*%)') or '(1000 km)'
--prev_distance_str = string.match(otherdevices_svalues['Position ' .. user], '%(.*%)') or '(1000 km)'
prev_distance_str = string.match(otherdevices_idx['Position ' .. user], '%(.*%)') or '(1000 km)'
print('iPhone ' .. user .. ' has '.. bat .. ' percent battery.')
print('iPhone ' .. user .. ' is at: ' .. position)
print('iPhone ' .. user .. ' is ' .. battstat)
prev_distance = tonumber(string.sub(prev_distance_str, 2,-5))
if prev_distance == nil then prev_distance = 1000 end
--update text device, but only if postion has changed more than defined in "radius" to reduce log size
if math.abs(prev_distance - distance) > radius then
table.insert(commandArray,{['UpdateDevice'] = otherdevices_idx['Position ' .. user] .. '|0|' .. position_text})
end
if bat < 2 then
if otherdevices['iPhone off ' .. user] == 'Off' then
commandArray['iPhone off ' .. user] = 'On'
end
else
if otherdevices['iPhone off ' .. user] == 'On' then
commandArray['iPhone off ' .. user] = 'Off'
end
end
print('iPhone ' .. user .. ': ' .. math.floor(distance*100+0.5)/100 .. ' km from home')
if distance < radius then
if otherdevices['iPhone ' .. user] == 'Off' then
commandArray['iPhone ' .. user] = 'On'
--table.insert(commandArray, {['SendNotification'] = 'Presence update#' .. user .. ' came home'})
end
else
if otherdevices['iPhone ' .. user] == 'On' then
commandArray['iPhone ' .. user] = 'Off'
--table.insert(commandArray, {['SendNotification'] = 'Presence update#' .. user .. ' left home'})
end
end
end
end
end
end
return commandArray
Code: Select all
2018-08-03 16:27:00.858 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_checkphones.lua: /home/pi/domoticz/scripts/lua/script_time_checkphones.lua:45: attempt to index global 'output' (a nil value)
Code: Select all
stage1command = "curl -s -X POST -D - -o /dev/null -L -u '" .. credentials.username .. ":" .. credentials.password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://fmipmobile.icloud.com/fmipservice/device/" .. credentials.username .."/initClient"
local handle = io.popen(stage1command)
local result = handle:read("*a")
handle:close()
stage2server = "fmipmobile.icloud.com"
stage2command = "curl -s -X POST -L -u '" .. credentials.username .. ":" .. credentials.password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://" .. stage2server .. "/fmipservice/device/" .. credentials.username .."/initClient"
local handle = io.popen(stage2command)
local result = handle:read("*a")
handle:close()
output = json:decode(result)
Code: Select all
stage1command = "curl -s -X POST -D - -o /dev/null -L -u '" .. credentials.username .. ":" .. credentials.password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://fmipmobile.icloud.com/fmipservice/device/" .. credentials.username .."/initClient"
Code: Select all
local handle = io.popen(stage1command)
local result = handle:read("*a")
handle:close()
Users browsing this forum: No registered users and 0 guests