Page 1 of 1

emitEvent does not trigger event

Posted: Wednesday 11 August 2021 14:16
by stephanvdplas
I run the following script to automaticcaly turn down my coffeemaker after 30 minutes, and notify me of that:

Code: Select all

return {
	on = {
		devices = {'Test Switch'},
		customEvents = {'Koffieapparaat*'}
	},
logging = {
	level = domoticz.LOG_DEBUG,
	marker = "SvdP-koffie"
	},

execute = function(domoticz, item)
	domoticz.log('item.state = ' .. item.state, domoticz.LOG_DEBUG)
	if (item.isDevice) then
		if (item.state == 'On') then
		domoticz.emitEvent('koffieapparaat12').afterSec(12)
		domoticz.emitEvent('koffieapparaat28').afterSec(28)
		domoticz.emitEvent('koffieapparaat30').afterSec(30)
	end
	elseif (item.trigger == 'Koffieapparaat12') then
		local message = 'Het koffieapparaat is klaar voor gebruik'
		message = string.gsub(message, "%s+", "+")
		domoticz.openURL({ url = 'https://api.callmebot.com/whatsapp.php?source=domz&apikey=XXXXXX&phone=XXXXXXXXXXX&text=' .. message, method = 'GET'})
	elseif (item.trigger == 'Koffieapparaat28') then
		local message = 'Het koffieapparaat wordt automatisch uitgezet over 2 minuten'
		message = string.gsub(message, "%s+", "+")
		domoticz.openURL({ url = 'https://api.callmebot.com/whatsapp.php?source=domz&apikey=XXXXXX&phone=XXXXXXXXXXX&text=' .. message, method = 'GET'})
	elseif (item.trigger == 'Koffieapparaat30') then
		item.switchOff().checkFirst()
		domoticz.log('Koffieapparaat gaat automatisch uit na een half uur.')
	end
end
}
Does anyone know what can be the problem?

Re: emitEvent does not trigger event

Posted: Wednesday 11 August 2021 14:38
by StephaneM60
Hi,

You have a mismatch between the event name and the event you send :

'Koffieapparaat*' is the event name

'koffieapparaat12' is the event you sent

So either go with "K" or "k" everywhere

Re: emitEvent does not trigger event

Posted: Wednesday 11 August 2021 14:54
by stephanvdplas
ow Thanks! that was the deal...

Code: Select all

return {
	on = {
		devices = {'Koffieapparaat'},
		customEvents = {'Koffieapparaat*'}
        },
	logging = {
       level = domoticz.LOG_DEBUG,
       marker = "SvdP-koffie"
    },

	execute = function(domoticz, item)
        if (domoticz.devices('Koffieapparaat').state == 'On') then
    	    if (item.isDevice) then
	            domoticz.emitEvent('Koffieapparaat12' , domoticz.time.rawTime).afterMin(12)
	            domoticz.emitEvent('Koffieapparaat28' , domoticz.time.rawTime).afterMin(28)
	            domoticz.emitEvent('Koffieapparaat30' , domoticz.time.rawTime).afterMin(30)
            elseif (item.trigger == 'Koffieapparaat12') then
        	    local message = 'Het koffieapparaat is klaar voor gebruik'
    	        message = string.gsub(message, "%s+", "+")
    	        domoticz.openURL({ url = 'https://api.callmebot.com/whatsapp.php?source=domz&apikey=149244&phone=31652563021&text=' .. message, method = 'GET'})
            elseif (item.trigger == 'Koffieapparaat28') then
        	    local message = 'Het koffieapparaat wordt automatisch uitgezet over 2 minuten'
    	        message = string.gsub(message, "%s+", "+")
    	        domoticz.openURL({ url = 'https://api.callmebot.com/whatsapp.php?source=domz&apikey=149244&phone=31652563021&text=' .. message, method = 'GET'})
            elseif (item.trigger == 'Koffieapparaat30') then
                domoticz.devices('Koffieapparaat').switchOff().checkFirst()
                domoticz.log('Koffieapparaat gaat automatisch uit na een half uur.', LOG_INFO)
            end
        end
	end
}
This is the full working code. Thanks.