Variable 'at' time

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

Moderator: leecollings

Post Reply
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Variable 'at' time

Post by EddyG »

It would be nice to have something like:

Code: Select all

        ['timer'] = { 'at ' .. domoticz.devices("selectorSwitch").levelName }
Or is there a simple way to emulate this?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Variable 'at' time

Post by waaren »

EddyG wrote: Monday 21 December 2020 7:27 Or is there a simple way to emulate this?
It can be emulated with below example

selector levelNames 'Off', '08:03', '12:23', etc..
If you cannot name the levelNames like this using Add, use a dummy name first and rename afterwards.

Code: Select all

local scriptVar =  'selector controlled'
local selector = 'selectorSwitch'

return

{
    on =
    {
        timer =
        {
            'at 00:01',
        },
        devices =
        {
            selector,
        },
        customEvents =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)
        local selector = dz.devices(selector)
        if item.isTimer or item.isDevice then
            local setTime = selector.levelName
            dz.log('Emit event at '.. setTime, dz.LOG_DEBUG)
            dz.emitEvent(scriptVar, selector.levelName).at(setTime)
        elseif item.isCustomEvent and item.data == selector.levelName then
            selector.switchSelector(0).silent() -- EDIT changed to  the more appropriate switchSelector ( was dimTo() )
            dz.log('-- rest of script', dz.LOG_DEBUG)  -- rest of script behind this line


        else
            dz.log('No action needed now', dz.LOG_DEBUG)
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Variable 'at' time

Post by EddyG »

Tnx, but I got this error when I actuate the selector. (zzz.lua is my script.)

Code: Select all

2020-12-21 11:57:18.831 Error: dzVents: Error: (3.0.19) selector controlled: An error occurred when calling event handler zzz
2020-12-21 11:57:18.831 Error: dzVents: Error: (3.0.19) selector controlled: /home/pi/domoticz/dzVents/runtime/Utils.lua:151: attempt to perform arithmetic on a nil value (local 'hours')
Edit: Sorry forgot to save the selector names.
Second edit: The 'Off' value is not accepted, changed that too.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Variable 'at' time

Post by EddyG »

Is there also a cancelemitEvent, or is there just 1 emitEvent active?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Variable 'at' time

Post by waaren »

EddyG wrote: Monday 21 December 2020 22:45 Is there also a cancelemitEvent, or is there just 1 emitEvent active?
There is no cancel EmitEvent possible and there can be multiple emitEvents active.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Variable 'at' time

Post by EddyG »

Tnx, it works brilliant. :D
Would not it be nice to have a cancelEmitEvent function too? ;)
Are they kept in memory or saved in the database? If so where?

P.S. the dimTo should be switchSelector, I think.
Funny indeed that initially levelnames cannot contain the ':' , but afterwards by editing the levelnames it is possible.
Last edited by EddyG on Wednesday 23 December 2020 10:47, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Variable 'at' time

Post by waaren »

EddyG wrote: Wednesday 23 December 2020 10:07 Would not it be nice to have a cancelEmitEvent function too? ;)
Are they kept in memory or saved in the database? If so where?

P.S. the dimTo should be switchSelector, I think.
I don't know if implementing cancelEmitEvent() is possible / easy (@MrHobbes74 ?) but the script(s) dealing with the customEvents at hand could check the conditions leading to a situation that the customEvent should no longer perform any follow up action.

You are right about dimTo vs switchSelector. They do the same in domoticz but it's better to use switchSelector here.

btw. emitEvent It is only in memory.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Variable 'at' time

Post by EddyG »

I use it as a minimum time that automated lights go on.
My problem is that when a emitevent cannot be canceled, a click on 07:00 and subsequent click on 07:30 the lights still go on at 07:00 and again at 07:30
I would like to cancel the 07:00 once I click on an other time in the selectorswitch.
Is there an enum of all outstanding emitevents?
Is there a workaround?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Variable 'at' time

Post by waaren »

EddyG wrote: Wednesday 23 December 2020 11:47 My problem is that when a emitevent cannot be canceled, a click on 07:00 and subsequent click on 07:30 the lights still go on at 07:00 and again at 07:30
that should not happen as the script checks if the time of the selectorLevel == item.data of the customEvent

Code: Select all

elseif item.isCustomEvent and item.data == selector.levelName then 
Is there an enum of all outstanding emitevents?
No
You could create something yourself by keeping track of the emitEvents in globalData but I cannot see a use case for this that could not be solved easier by checking the conditions with the the same- or similar code as I posted in this topic.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Variable 'at' time

Post by EddyG »

Oke. Tnx, totally clear now.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest