Script acting different after update

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

Moderator: leecollings

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Script acting different after update

Post by snellejellep »

Hi all,

after updating to domoticz 2021.1 from 2020.1 something seems to be changed.
i have the script listed below, it does the following:
i have a gate, which has a dry contact relay for activating it, and a reed switch for detecting when the gate is open or closed, for when it is used with the built in code pad or remote.
now, i wanted to combine that input and output into one switch which could tell the state of the gate and open/close it according to the current state, so when i was comming home i could see if it was already open or closed and activate when necessary with the same switch.
but this script broke with the last update of domoticz.

it seems that te .silent() function no longer works.
the behaviour i am seeing is that when the gate is activated and it goes far enough that it changes the state of te reed switch, it activates again which initiates the stop function and i end up with a gate that is half open/half closed.
there is also a function built in to the script which automatically closes the gate at 22.00 and between 22.00 and 04.00 it closes again after 5 minutes and on sunday it also closes after 5 minutes.

i hope someone can help me to fix the script and restore the functionality.

the script that is currently broken but worked before:

Code: Select all

return {
    on ={
        devices ={
            'Hek',
            'Status hek'
        },
        timer={
            'every 5 minutes'
        }
    },

    execute = function(dz, device)
        
        local hek          = dz.devices("Hek")
        local status       = dz.devices("Status hek")
        local activate     = dz.devices("Activeer hek")
        local zondag       = dz.devices("Zondag")
        
        if hek.state == "Off" and status.lastUpdate.secondsAgo > 5 then
            activate.switchOn()
        elseif hek.state == "On" and status.lastUpdate.secondsAgo > 5 then
            activate.switchOn()
        elseif status.state == "Off" and hek.state == "Off" and hek.lastUpdate.secondsAgo > 5 then
            hek.switchOn().silent()
        elseif status.state == "On" and hek.state == "On" and hek.lastUpdate.secondsAgo > 5 then
            hek.switchOff().silent()
        end
        
        if (dz.time.matchesRule("at 22:00-04:00") or zondag.state == "On") and hek.state == "On" and hek.lastUpdate.minutesAgo > 5 then
            hek.switchOff()
        end
    end
}
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script acting different after update

Post by waaren »

snellejellep wrote: Tuesday 27 April 2021 22:46 It seems that te .silent() function no longer works.
Nothing changed in the last years with regards to the silent() option. There was an issue with the previous stable with lastUpdate and that was fixed in V2020.2 build 12002. (see github issue 4112 )
Maybe that fix is now causing an unexpected behavior of your script.

It is not completely clear to me what you expect and what you see. Can you add some debug loglines and share the log with some remarks on what you see and what you expect?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Script acting different after update

Post by snellejellep »

well, i did some further investigation regarding to the behaviour of my script
i got no errors with adding a debug log rule
but something else was interesting, if i add a lastUpdate to the if statement, and the trigger is the item that is checked for the lastUpdate, it ignores the lastUpdate or simply won't go on.
i can make no sense of the behaviour what so ever.
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script acting different after update

Post by waaren »

snellejellep wrote: Wednesday 28 April 2021 10:57 I can make no sense of the behaviour what so ever.
Can you use this one, -share the log and tell us what you expected differently compared to what happens?

Code: Select all

return {
    on ={
        devices ={
            'Hek',
            'Status hek'
        },
        timer={
            'every 5 minutes'
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Hek',
    },

    execute = function(dz, device)

        local hek          = dz.devices("Hek")
        local status       = dz.devices("Status hek")
        local activate     = dz.devices("Activeer hek")
        local zondag       = dz.devices("Zondag")

        dz.log('Hek status: ' .. hek.status,dz.LOG_DEBUG)
        dz.log('Status hek status: ' .. status.status,dz.LOG_DEBUG)
        dz.log('Hek lastupdate: ' .. hek.lastUpdate.secondsAgo, dz.LOG_DEBUG)
        dz.log('Status hek lastupdate: ' .. status.lastUpdate.secondsAgo,dz.LOG_DEBUG)

        if hek.state == "Off" and status.lastUpdate.secondsAgo > 5 then
            dz.log('-1-', dz.LOG_DEBUG)
            activate.switchOn()
        elseif hek.state == "On" and status.lastUpdate.secondsAgo > 5 then
            dz.log('-2-', dz.LOG_DEBUG)
            activate.switchOn() -- so only dependinh on lastUpdate ?
        elseif status.state == "Off" and hek.state == "Off" and hek.lastUpdate.secondsAgo > 5 then
            dz.log('-3-', dz.LOG_DEBUG)
            hek.switchOn().silent()
        elseif status.state == "On" and hek.state == "On" and hek.lastUpdate.secondsAgo > 5 then
            dz.log('-4-', dz.LOG_DEBUG)
            hek.switchOff().silent()
        end

        if (dz.time.matchesRule("at 22:00-04:00") or zondag.state == "On") and hek.state == "On" and hek.lastUpdate.minutesAgo > 5 then
            dz.log('-5-', dz.LOG_DEBUG)
            hek.switchOff()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest