DewGew / DZGA-Flask

Domoticz Google Assisting using Flask
GNU General Public License v3.0
8 stars 4 forks source link

Add Timer trait #98

Closed DewGew closed 4 months ago

DewGew commented 4 months ago

Needs to add a dzVents script in Domoticz to act like a timer. Example:

return {
    on = {
            customEvents = { 'TIMER' },
    },
    logging = {
            level = domoticz.LOG_INFO,
            marker = "Timer"
        },
    execute = function(dzga, item)
        if (item.isJSON) then
                local device = dzga.devices(item.json.idx)

            if (device.active and item.json.cancel) then
                dzga.log('Stop timer for ' .. device.name)
                device.cancelQueuedCommands()
            else
                dzga.log('No timer is running for' .. device.name)
            end
            if  item.json.on == true then
                device.cancelQueuedCommands()
                device.switchOn()
                dzga.log('Switch ' .. device.name .. ' On for: ' .. item.json.time .. ' sec')
                device.switchOff().afterSec(item.json.time)
            end
        end
    end
}

Use like this:

User: Turn on living room light for 5 minutes.
Google Assistant: Turning on living room light for 5 minutes?
User: Stop timer for living room light.
Google Assistant: Updating living room timer? (Turn off light/switch manually)