in the comfiguration page Setup > Settings a lot of parameters can be set by the user.
now i'm having a lua script and i am looking for a way to read a particular setting's value into a script variable to use it in a calculation.
i've been digging thru lots of wiki pages, but have not found where i was looking for.
question: can someone help me by showing where to find a sample or where this is documented?
access settings variables from lua
Moderators: leecollings, remb0
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: access settings variables from lua
You cannot do it directly in Lua or dzVents but you can use domoticz.openURL in dzVents or curl in Lua and call the api. You need admin rights to do that ( either by including a username/password in the url of a auser with admin rights or by allowing local network in settings to access domoticz without password)
Some of the settings are base64 encoded
You can find the api call on this Wiki page
in dzVents it could look like the samplescript below
__________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
___________________________________________________________________________________________________________________________
Code: Select all
--[[
script to get and decode settings
]]--
local scriptVar = 'getSettings'
return
{
on =
{
timer =
{
'every minute' , --- change to your liking
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
marker = scriptVar,
},
execute = function(dz, item)
local settingsEncoded =
{
ClickatellTo = true,
HTTPPostContentType = true,
HTTPURL = true,
EmailUsername = true,
EmailPassword = true,
ClickatellAPI = true,
HTTPPostContentType = true,
IFTTTAPI = true,
MyDomoticzPassword = true,
}
local function showSettings(t)
for key, value in pairs(t) do
if settingsEncoded[key] then
value = dz.utils.fromBase64(value)
end
dz.log(key .. ': ' .. dz.utils._.str(value) )
end
end
if item.isTimer or item.isDevice then
settingsURL = dz.settings['Domoticz url'] .. '/json.htm?type=settings'
dz.openURL(
{
url = settingsURL,
callback = scriptVar
})
elseif item.isJSON then
showSettings(item.json)
else
dz.log('There was a problem handling' .. item.trigger, dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
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