I'd like to be able to read the settings using lua. Especially the location settings are of interest to me.
I know I could use json, but since I protected my Domotic, I have to use a userid/password in the script which I don't like for some reason.
Nice to have:
location = settings['location'] (as a line in a lua script)
from https://www.domoticz.com/wiki/Lua_-_json.lua (with change to use wget instead of curl):
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
--json = (loadfile "D:\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
read = os.execute('wget '..tempfilename..' http://localhost:<port>/json.htm?type=settings')
file = io.open(tempfilename, "r")
settings = file:read('*all')
file.close()
location = json:decode(settings)
lat = jsonLocation.current_observation.display_location.latitude
lon = jsonLocation.current_observation.display_location.longitude
Request: Lua script can read settings
Moderators: leecollings, remb0
-
- Posts: 2
- Joined: Tuesday 29 May 2018 9:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Request: Lua script can read settings
Not sure if you do not want password less access from local system either. That would be required for this dzVents / Lua script.jagroeneveld wrote: ↑Tuesday 26 June 2018 18:40 I'd like to be able to read the settings using lua. Especially the location settings are of interest to me.
I know I could use json, but since I protected my Domotic, I have to use a userid/password in the script which I don't like for some reason.
....
SETUP -> SETTINGS -> LOCAL NETWORKS (NO USERNAME/PASSWORD): 127.0.0.*
I use the approach as in this script in various other dzVents scripts and store the Latitude / Longitude in (Global) persistent data variables so that I only have to call the openURL once.
Code: Select all
--[[ getLocation.lua
]]
return {
on = { devices = { "locationTrigger" }, -- Just a trigger switch to kick off script
httpResponses = { "LocationResponse" }
},
execute = function(dz, trigger)
if trigger.isTimer or trigger.isDevice then
dz.openURL({
url = dz.settings['Domoticz url'] .. "/json.htm?type=settings",
method = "GET",
callback = "LocationResponse" })
else
print("Latitude: " ..trigger.json.Location.Latitude)
print("Longitude: " ..trigger.json.Location.Longitude)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest