Page 1 of 1

Trigger dzVents script with MQTT command (customEvents)

Posted: Tuesday 17 January 2023 11:18
by riko
I'm testing a trigger of a dzVents script by a MQTT command send by NodeRED.

Domoticz is set-up to receive MQTT commands through with the domoticz/in prefix (this works to trigger devices already). I've created a test flow in NodeRED, which results in the following output on MQTT:
Schermafbeelding 2023-01-17 110205.png
Schermafbeelding 2023-01-17 110205.png (9.41 KiB) Viewed 774 times
The dzVents script has the following triggers defined (I'm intended to schange the MyEvent and myData description later on, but this is for the sake of testing):

Code: Select all

return {
        on = { 
			timer = {
				'at ' .. TijdAan, 
				'at ' .. TijdUit, 
				"at sunrise", 
				"at sunset" 
				},
			customEvents = {
				"command":"customevent", "event":"MyEvent", "data":"myData"
				}	
			},
        
        logging = { level = domoticz.LOG_ERROR , marker = "Lamp voorkamer"},
        
		execute = function(dz, item)
Domoticz gives the following error, so I suppose it has something to do with the signs around the custom event. I've tried "" and [[ ]], but without any effect:

2023-01-17 11:17:53.823 Error: dzVents: Error: (3.1.8) error loading module 'control_lamp_voorkamer' from file '/home/pi/domoticz/scripts/dzVents/scripts/control_lamp_voorkamer.lua':
2023-01-17 11:17:53.823 ...oticz/scripts/dzVents/scripts/control_lamp_voorkamer.lua:13: '}' expected near ':'

Re: Trigger dzVents script with MQTT command (customEvents)

Posted: Tuesday 17 January 2023 15:49
by hoeby
I think you format a , behind the } on line
And don't put the mqtt message in there, but the event name

Code: Select all

return {
        on = { 
			timer = {
				'at ' .. TijdAan, 
				'at ' .. TijdUit, 
				"at sunrise", 
				"at sunset" 
				},
			customEvents = { 'MyEvent'
				},	
			},
        
        logging = { level = domoticz.LOG_ERROR , marker = "Lamp voorkamer"},
        
		execute = function(dz, item)

Re: Trigger dzVents script with MQTT command (customEvents)

Posted: Tuesday 17 January 2023 15:53
by boum
Well, it's not functioning lua code. Check the documentation: https://www.domoticz.com/wiki/DzVents:_ ... tom_events
Try:

Code: Select all

customEvents = { "MyEvent" }	
And you'll get "myData" in your function in item.data.

Re: Trigger dzVents script with MQTT command (customEvents)

Posted: Tuesday 17 January 2023 19:03
by riko
Great, I misunderstood the documentation. Thank you!