Request: Lua script can read settings

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.
Post Reply
jagroeneveld
Posts: 6
Joined: Tuesday 29 May 2018 9:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

Request: Lua script can read settings

Post by jagroeneveld » 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.

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

User avatar
waaren
Posts: 1220
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Request: Lua script can read settings

Post by waaren » Tuesday 26 June 2018 20:49

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.
....
Not sure if you do not want password less access from local system either. That would be required for this dzVents / Lua script.
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

}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest