At the moment I use these coordinates to get and register e.g. local wheaterforcast, stookalert, earthquakes, airplanes.
It made me think that it could be nice to be able to use your remote/mobile coordinates under certain circumstances? You can use your imagination. So, I gave it a try.
Of course you are depending on some method to bring your remote coordinates over to Domoticz. But then you can work with it as you like.
In fact it is a two step process.
1. Bring your coordinates from your phone to domoticz and place it in a uservariable (only when you are not at home).
2. A script that is triggered by change of the uservariable, picks it up and continues to work with it. (You can think of restricitions to be build in.)
Needed:
- For the example I have created a custom text device, that gets a link to google
- I created a string uservariable to store the remote latitude and longitude in one string.
- The script, as it is, makes use of persistent data in a variable 'prevLatLong' in global_data. His holds the previous position to compare if the location has changed. This prevents unneeded updates.
I use the Macrodroid app on my smartphone. You may have or want other options for this, but this is what I use to explain and show it.
It's a bit of a puzzle, but I'm getting better at it. A lot is possible. See the explanation below the picture. Explanation of these steps in Macrodroid:
- Macrodroid is triggered by a timer every 15 minutes only when its boolean varable that I am not at home is set (by geofence).
- It cleans all the local variables used in the macro.
- It forces to update the current location.
- It stores the coordinates in a local string variable 'location'.
- it waits until the variable is changed.
- When location is retreived, it goes into a loop.
- Update Domoticz uservariable with the location string.
- Obtains the 'httpResonse', Parse the JSON to 'json' and gets the status in variable 'dzStatus'.
- When dzStatus = OK, we get oout of the loop, If not we wait 5 seconds and try again.
Code: Select all
https://yourip:yourport/json.htm?type=command¶m=updateuservariable&vname=<YOURVARIABLENAME>&vtype=2&vvalue=<YOURLATLONGSTRING>
Step 2:
In Domoticz now we see the uservariable that is set.
The scripts is triggered by the update of this variable and puts the coordinates in a hyperlink that is shown in the custom text device.
Prevents update when location is not changed.
v-myLocation
Code: Select all
-- 11-06-2024 Script by Jan Peppink; hppts://ict.peppink.nl
-- Result: Work with your remote coordinates. (Set link to google maps that point to your current location.)
-- Makes use of variable prevLatLong in global_data.
-- Triggers on changed uservariable.
--- Your settings ----------------------------------------------------------------
-- First set the used device index numbers and variables you might want to change.
local locationVar = 'youruservariable' --Name of your location variable, that holds "lat, long"
local loc_idx = 9999 --idx of text device
local testing = 1 --Use Fake coordinates for demo. 0 = for production mode :-)
--------------------------------------------------------------------------------
return {
on = {
variables = {
locationVar,
},
},
logging = {
-- Level can be domoticz.LOG_INFO, domoicz.LOG_MODULE_EXEC_INFO, domoticz.LOG_DEBUG, domoticz.LOG_ERROR or domoticz.LOG_FORCE
level = domoticz.LOG_INFO,
--level = domoticz.LOG_DEBUG,
marker = "MobileLocation--"
},
execute = function( dz, triggeredItem )
-- Set Local environment=================
--local _u = dz.utils -- Holds subset of handy utilities.
--local _h = dz.helpers -- Holds the global functions.
local _d = dz.globalData -- Holds the global data.
local latlong = ''
if testing == 1 then
latlong = '52.373224302364264,4.891381706567313' --get test location.
else
latlong = triggeredItem.value -- Get the LastLatLong from uservariable.
end
-- Use color variable for hyperlink font color
htmlColor = 'Blue'
-- Local Functions go here =============
-- Now start to do something ============
if _d.prevLatLong ~= latlong then
--Location changed, so update
local locationText = '<a href="https://maps.google.com/?q=' .. latlong .. '" target="_blank"><span style="color: ' .. htmlColor .. '">Toon mijn locatie</span></a>'
dz.log( 'Location is set to ' .. triggeredItem.value, dz.LOG_DEBUG )
dz.devices( loc_idx ).updateText( locationText )
--Update and store this as the previous location
_d.prevLatLong = latlong
end
end
}
-- That's All --------------------------------------------------
The Testlocation