Trigger dzVents script with MQTT command (customEvents)

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

Moderator: leecollings

Post Reply
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Trigger dzVents script with MQTT command (customEvents)

Post 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 657 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 ':'
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Trigger dzVents script with MQTT command (customEvents)

Post 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)
Last edited by hoeby on Tuesday 17 January 2023 15:56, edited 1 time in total.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
boum
Posts: 130
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Trigger dzVents script with MQTT command (customEvents)

Post 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.
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Trigger dzVents script with MQTT command (customEvents)

Post by riko »

Great, I misunderstood the documentation. Thank you!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest