Page 1 of 1

Combine script

Posted: Saturday 10 February 2018 11:50
by poudenes
Hi ALl,

I read dzvent wiki but im to noob to solve it haha. I want combine 2 scripts so i have less different scripts.

Code: Select all

local Version        = '17.12.16'
local iPhoneKay	             = 86
local iPhonePeter	     = 85

return {
    active = true,
    on = {
        devices = {iPhoneKay},
    },
    logging = {marker = 'SENSOR iPhone Kay ' ..Version..'......'},
    execute = function(domoticz, device)

    if
    (domoticz.devices(iPhoneKay).state == 'On')
    then
        domoticz.notify('Sensor Kay aangezet','dzVents Sensor Kay is aangezet', domoticz.PRIORITY_NORMAL)
        domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)
        domoticz.log('--------------------==<[ IPHONE KAY AANGEZET] >==--------------------', domoticz.LOG_FORCE)
        domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)

    elseif
    (domoticz.devices(iPhoneKay).state == 'Off')
    then
        domoticz.notify('Sensor Kay uitgezet','dzVents Sensor Kay is uitgezet', domoticz.PRIORITY_NORMAL) 
        domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)
        domoticz.log('--------------------==<[ IPHONE KAY UITGEZET ]>==--------------------', domoticz.LOG_FORCE)
        domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)

    elseif
    (domoticz.devices(iPhonePeter).state == 'On')
    then
        domoticz.notify('Sensor Peter aangezet','dzVents Sensor Peter is aangezet', domoticz.PRIORITY_NORMAL)
        domoticz.log('-----------------------------------------------------------------------', domoticz.LOG_FORCE)
        domoticz.log('--------------------==<[ IPHONE PETER AANGEZET ]>==--------------------', domoticz.LOG_FORCE)
        domoticz.log('-----------------------------------------------------------------------', domoticz.LOG_FORCE)

    elseif
    (domoticz.devices(iPhonePeter).state == 'Off')
    then
        domoticz.notify('Sensor Peter uitgezet','dzVents Sensor Peter is uitgezet', domoticz.PRIORITY_NORMAL) 
        domoticz.log('-----------------------------------------------------------------------', domoticz.LOG_FORCE)
        domoticz.log('--------------------==<[ IPHONE PETER UITGEZET ]>==--------------------', domoticz.LOG_FORCE)
        domoticz.log('-----------------------------------------------------------------------', domoticz.LOG_FORCE)
        end
    end
}
When i combine those and turn off iPhone Peter. It will always do action of the first IF statement. Because it looks also to the first one. If the device is on then execute that part. It will never goto the other else if statement.

Re: Combine script

Posted: Saturday 10 February 2018 13:21
by dannybloe
Assuming both devices are called 'iPhoneKay' and 'iPhonePeter' I'd do this:

Code: Select all

return {
	on = {
		devices = {'iPhone*'},
	},
	execute = function(domoticz, iPhone)
		local state = ''
		
		if (iPhone.active) then
			state = 'aangezet'
		else
			state = 'uitgezet'
		end
	
		domoticz.notify('Sensor ' .. iPhone.name .. 'is ' .. state ,'dzVents Sensor ' .. iPhone.name ..' is ' .. state, domoticz.PRIORITY_NORMAL)
		domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)
		domoticz.log('--------------------==<[ ' .. iPhone.name .. ' is ' .. state ..' >==--------------------', domoticz.LOG_FORCE)
		domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)
	end
}

Re: Combine script

Posted: Saturday 10 February 2018 14:47
by poudenes
Thanks Danny,

Work great !! thanks... i see the logic how it works... see if i can use it for more scripts :D
dannybloe wrote: Saturday 10 February 2018 13:21 Assuming both devices are called 'iPhoneKay' and 'iPhonePeter' I'd do this:

Code: Select all

return {
	on = {
		devices = {'iPhone*'},
	},
	execute = function(domoticz, iPhone)
		local state = ''
		
		if (iPhone.active) then
			state = 'aangezet'
		else
			state = 'uitgezet'
		end
	
		domoticz.notify('Sensor ' .. iPhone.name .. 'is ' .. state ,'dzVents Sensor ' .. iPhone.name ..' is ' .. state, domoticz.PRIORITY_NORMAL)
		domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)
		domoticz.log('--------------------==<[ ' .. iPhone.name .. ' is ' .. state ..' >==--------------------', domoticz.LOG_FORCE)
		domoticz.log('---------------------------------------------------------------------', domoticz.LOG_FORCE)
	end
}