Now I use this
- Spoiler: show
I guess I am looking for a way of avoiding all the if then end
Moderator: leecollings
Code: Select all
local ubi = domoticz.devices('Ubica').rawData[1]
if ubi == '10' then zmw = tostring('08360')
elseif ubi == '20' then zmw = tostring('08085')
elseif ubi == '30' then zmw = tostring('07510')
elseif ubi == '40' then zmw = tostring('07130')
elseif ubi == '50' then zmw = tostring('07037')
elseif ubi == '60' then zmw = tostring('06431')
elseif ubi == '70' then zmw = tostring('06431')
elseif ubi == '80' then zmw = tostring('07385') end
Code: Select all
local ubi = tonumber(domoticz.devices('Ubica').rawData[1])
local zmw = ubi==10 and '08360' or ubi==20 and '08085' or ubi==30 and '07510' or ubi==40 and '07130' or ubi==50 and '07037' or ubi==60 and '06431' or ubi==70 and '06431' or ubi==80 and '07385' or '?????'
Here is a variant of achieving the same result. 2 lines of code and an additional line for logging.elmortero wrote: Thursday 24 August 2017 13:43 I would like some advice for the best practice in LUA/dzVents for selector switch when there are a lot of levels.
Code: Select all
local t = {[10]='08360', [20]='08085', [30]='07510', [40]='07130', [50]='07037', [60]='06431', [70]='06431', [80]='07385'}
local zmw = t[tonumber(domoticz.devices('Ubica').rawData[1])]
domoticz.log('The new value of zmw is: '..(zmw and zmw or 'nil'), domoticz.LOG_FORCE)
Users browsing this forum: No registered users and 1 guest