Page 1 of 1

Compare 2 values and update sensor (lua parser)

Posted: Sunday 05 April 2020 17:38
by Minglarn
Hi folks..
I must say that I really hate LUA .. I'm more familiar with PHP and other stuff than this s**tty LUA ... :D

I've done a API for my 3D printer and it's returning JSON.

If the JSON value is not equal to Domoticz then update Domoticz

I'm trying to get my LUA script to compare 2 values.
Using the HTTP poller plugin

Code: Select all

-- Retrieve the request content
s = request['content'];

local g_enclosure_temp = domoticz_applyJsonPath(s,'g_enclosure_temp')
local g_job_name = domoticz_applyJsonPath(s,'g_job_name')
local g_bed_temp_actual = domoticz_applyJsonPath(s,'g_bed_temp_actual')
local g_tool_temp_actual = domoticz_applyJsonPath(s,'g_tool_temp_actual')


commandArray = {}
if g_job_name ~= commandArray ["3D Print file"] then
domoticz_deviceChanged(3520,'',g_job_name)
end

return commandArray
Please help this poor man... :D

Re: Compare 2 values and update sensor (lua parser)

Posted: Monday 06 April 2020 13:46
by bewo
Hi Minglarn...

the script you've posted is dzVents no straight lua. ->> False. See below.. :)

I've using several scripts with json values, but instead http poller i use code like this one:

Code: Select all

-- Bind the JSON-libary deliverd with domoticz (in script directory)
json = (loadfile "/opt/domoticz/scripts/lua/JSON.lua")()

-- JSON-API-URL
API_URL = 'http://example.com/jsonendpoint'

commandArray = {}

-- Collect the Json
json_collect = assert(io.popen('curl --max-time 5 "'..API_URL..'"'))
json_collect_data = json_collect:read('*all')
json_collect:close()
json_data = json:decode(json_collect_data)
        
-- Then use the json data, for example
Value1 = json_data.value1
Value2 = json_data.table1.value2
Value3 = json_data.table1.tableA.value3


if Value1 ~= uservariables['BlaBlaBla'] then
    print('Hello!')
end    

return commandArray
Trigger ist time based (once a minute).

Re: Compare 2 values and update sensor (lua parser)

Posted: Monday 06 April 2020 14:39
by waaren
bewo wrote: Monday 06 April 2020 13:46 the script you've posted is dzVents no straight lua.
? I don't see a dVents script in this topic ?

Re: Compare 2 values and update sensor (lua parser)

Posted: Monday 06 April 2020 15:01
by bewo
You're right it's not an dzVents script. "domoticz_deviceChanged(3520,'',g_job_name)" .....Look's like dzVents.... So i think i've mixed up... ;)