Combine script

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Combine script

Post 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.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Combine script

Post 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
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Combine script

Post 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
}
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest