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