dzVents 3.0 released
Posted: Thursday 13 February 2020 20:45
Hi folks,
I am proud to announce dzVents 3.0 has been merged in Domoticz v4.11687. Thanks to the hard work of MrHobbes74, waaren and yours truly we have some very interesting new features:
System events
Many times asked for and now possible is a way to run scripts as soon as Domoticz was started. You can now use the new system on-trigger:
Of course there are other system events and for now we implemented the following (but it is not unlikely there will be more in the future):
Custom events
It is now possible to emit your own custom events using the new domoticz.emitEvent() function. dzVents scripts can then subscribe to these custom events using the new on-trigger customEvent.
A script emiting an event:
Then other scripts can subscribe to this event:
Note that it is not necessary to provide data with you custom event. It is optional:
And there's a bonus: you can emit a custom event using the json api:
or MQTT:
This is very useful if for instance you have some external systems like sensors that want to send data to Domoticz and have a script process this data without having to create virtual devices or user variables. Previously that was the only way to trigger scripts in Domoticz. Now you can simply trigger an event with some data and a script can process the data and perhaps update the necessary devices based on this (processed) data. Much easier!
Oh, one more thing: both system and custom events can be combined with time rules:
So, exciting new features. Happy scripting peeps and let's make our houses even smarter!
Cheers,
Danny
I am proud to announce dzVents 3.0 has been merged in Domoticz v4.11687. Thanks to the hard work of MrHobbes74, waaren and yours truly we have some very interesting new features:
System events
Many times asked for and now possible is a way to run scripts as soon as Domoticz was started. You can now use the new system on-trigger:
Code: Select all
return {
on = {
system = { 'start' }
},
execute = function(domoticz, item)
domoticz.log('Domoticz has started')
domoticz.log(item.trigger) -- will print 'start'
end
}
- start - fired when Domoticz has started.
- stop - fired when Domoticz is shutting down. As you probably can imagine you have only a limited amount of time to have Domoticz do stuff when your script has been completed. Some commands will probably not be executed. Just give it a try.
- dailyBackupFinished - the trigger item (2nd parameter of the execute function) holds the location of the newly created backup. You can use this perhaps to copy the file to some other location.
- hourlyBackupFinished
- monthlyBackupFinished
- manualBackupFinished - fired when you start a backup using the Domoticz GUI.
Code: Select all
return {
on = {
system = { 'dailyBackupFinished' }
},
execute = function(domoticz, item)
domoticz.log('Backup finished. It took ' .. item.duration .. ' and the location is ' .. item.location)
end
}
Custom events
It is now possible to emit your own custom events using the new domoticz.emitEvent() function. dzVents scripts can then subscribe to these custom events using the new on-trigger customEvent.
A script emiting an event:
Code: Select all
return {
on = {
devices = {
'myTempSensor'
}
},
execute = function(domoticz, mySensor)
if (mySensor.temperature > 50) then
domoticz.emitEvent('fire', { 'temp' = mySensor.temperature })
end
end
}
Code: Select all
return {
on = {
customEvent = { 'fire' }
},
execute = function(domoticz, trigger)
domoticz.log('Fire! Run!!')
domoticz.log(triggeredItem.data.temp)
end
}
Code: Select all
domoticz.emitEvent('myEvent') -- no data
domoticz.emitEvent('another event', 'some data')
domoticz.emitEvent('hugeEvent', { a = 10, b = 20, some = 'text', sub = { x = 10, y = 20 } })
Code: Select all
https://path.to.domoticz/json.htm?type=command¶m=customevent&event=MyEvent&data=myData
Code: Select all
{"command" : "customevent", "event" : "MyEvent" , "data" : "myData" }
Oh, one more thing: both system and custom events can be combined with time rules:
Code: Select all
return {
on = {
system = {
['start'] = { 'between sunset and sunrise on mon,tue,fr', 'on sun' }
},
customEvent = {
['fire'] = { 'at daytime' } -- don't disturb me when I'm sleeping please!
}
},
execute = function(dz)
...
end
}
Cheers,
Danny