Compare 2 values and update sensor (lua parser)

Moderator: leecollings

Post Reply
User avatar
Minglarn
Posts: 214
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Compare 2 values and update sensor (lua parser)

Post 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
Attachments
iframe11.JPG
iframe11.JPG (34.63 KiB) Viewed 611 times
When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

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

Post 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).
Last edited by bewo on Monday 06 April 2020 15:09, edited 1 time in total.
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

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

Post 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... ;)
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest