emitEvent does not trigger event

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

Moderator: leecollings

Post Reply
stephanvdplas
Posts: 73
Joined: Wednesday 13 February 2019 18:09
Target OS: Windows
Domoticz version: 2023.1
Location: Netherlands
Contact:

emitEvent does not trigger event

Post 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?
- Running LMS, Domoticz and Dashticz on a windows 11 laptop.
- LMS (11 players) / Hue (26 lights, 2 switches) / Z-wave (14 devices) / Toon (unrooted) / Chromecast
StephaneM60
Posts: 12
Joined: Saturday 10 November 2018 12:47
Target OS: Windows
Domoticz version:
Contact:

Re: emitEvent does not trigger event

Post 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
stephanvdplas
Posts: 73
Joined: Wednesday 13 February 2019 18:09
Target OS: Windows
Domoticz version: 2023.1
Location: Netherlands
Contact:

Re: emitEvent does not trigger event

Post 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.
- Running LMS, Domoticz and Dashticz on a windows 11 laptop.
- LMS (11 players) / Hue (26 lights, 2 switches) / Z-wave (14 devices) / Toon (unrooted) / Chromecast
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest