selective trigger DzVents scripts  [Solved]

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

Moderator: leecollings

Post Reply
AntoonvdOetelaar
Posts: 15
Joined: Thursday 24 August 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Holland
Contact:

selective trigger DzVents scripts

Post by AntoonvdOetelaar »

I'm wondering for some time, if it's possible to limit the amount of triggers of a script.
something like:
on = { devices = 'mySwitch' only 'every <xx> minutes' },

So the script gets triggered by mySwitch but only every xx minutes. Normally you have the combined triggering, so on the device and also on the time trigger

I have a script with a function for the trigger that checks if the temperature is above a given value. It looks like the trigger of this script comes into a loop that crashes domoticz.
RPI3B, Z-WAVE AEOTEC GEN5, Zigbee2Mqtt, Xiaomi gateway, GPIO, I2C, 1-wire, DS18B20, P1 meter, Growatt, Buienradar, Harmony hub, Domoticz 2020.2
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: selective trigger DzVents scripts

Post by waaren »

AntoonvdOetelaar wrote: Tuesday 21 January 2020 13:48 I have a script with a function for the trigger that checks if the temperature is above a given value. It looks like the trigger of this script comes into a loop that crashes domoticz.
Can you please include the script in your post to help us understand what might cause the loop?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
AntoonvdOetelaar
Posts: 15
Joined: Thursday 24 August 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Holland
Contact:

Re: selective trigger DzVents scripts

Post by AntoonvdOetelaar »

The sort of script that I think that can be the reason of the crashes is:

Code: Select all


	on = {
       timer = {

            -- 'every 10 minutes', -- test
            
            function(domoticz)
                local TimerTriggerCVKetelVloerPomp  = domoticz.devices('CV ketel vloer pomp')
                local TimerTriggerCVKetelPower      = domoticz.devices('CV ketel power')
                local TimerTriggerCvWarmWaterTemp   = domoticz.devices('CV warm temp')
                local TimerTriggerCvKoudWaterTemp   = domoticz.devices('CV koud temp')

                    if     (TimerTriggerCvWarmWaterTemp.temperature > 35 
                        and TimerTriggerCVKetelVloerPomp.state == 'Off' 
                        and TimerTriggerCVKetelVloerPomp.lastUpdate.minutesAgo > 20) or 

                           (TimerTriggerCvWarmWaterTemp.temperature < 25 
                        and TimerTriggerCVKetelVloerPomp.state == 'On' 
                        and TimerTriggerCVKetelVloerPomp.lastUpdate.minutesAgo > 30) or 

                        --   (TimerTriggerCVKetelPower.lastUpdate.minutesAgo > 28 
                        --and TimerTriggerCVKetelPower.lastUpdate.minutesAgo < 52 
                        --and TimerTriggerCvWarmWaterTemp.temperature < 25) or
                    
                        TimerTriggerCvKoudWaterTemp.temperature < 7 
                    then 
                    return true
                end    
            end    
 
		},
		devices = {
			'CV ketel power',       
            'CV ketel vloer pomp'   
		}                           		
	},
	
	
I did have a couple of these active at the moments of the crashes. Since I have updated to (at that time) the latest beta V4.11605, I did turn off all events with function triggers and now domoticz is running for 7 days without a reboot.
Maybe the update did fix problems, maybe the disabled script, not really sure. Will test further. For some time I was blaming OZW1.6, not sure what has changed.

Edit:

Code: Select all

return {
	on = {
	    devices = {
			['Badkamer'] = { 'at nighttime' },
			[293] = { 'at nighttime' }	-- PIR trap beneden

		}
	},
Maybe something like this but then: ['Badkamer'] = { 'every 5 minutes' },
RPI3B, Z-WAVE AEOTEC GEN5, Zigbee2Mqtt, Xiaomi gateway, GPIO, I2C, 1-wire, DS18B20, P1 meter, Growatt, Buienradar, Harmony hub, Domoticz 2020.2
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: selective trigger DzVents scripts  [Solved]

Post by waaren »

AntoonvdOetelaar wrote: Wednesday 22 January 2020 19:37 The sort of script that I think that can be the reason of the crashes is:
This script will not be loaded by dzVents so not execute by domoticz. For one thing because it does not have an execute section.
Will test further.
Please keep us informed
Maybe something like this but then: ['Badkamer'] = { 'every 5 minutes' },
This will work but probably not the way you intend. Check this test-script

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'init script',                                      -- to get the script started  
            ['retrigger script'] = { 'every 5 minutes' },     
        },
    },
    
    logging = 
    {
        level = domoticz.LOG_ERROR,
        marker = "trigger combination test"
    },

    execute = function(dz, item)
        local retrigger = dz.devices('retrigger script') 
        dz.log(item.name .. ' triggered this script ', dz.LOG_FORCE )
        
        local next5minuteStart = 300 - ( os.time() % 300 ) -- os.time() % 300 is the amount of seconds of this moment after the last hh:00:00, hh:05:00 ... hh:55:00 point 
        
        retrigger.cancelQueuedCommands()
        retrigger.switchOn().afterSec(5)
        retrigger.switchOn().afterSec(next5minuteStart)

    end
}


The above will only trigger on 'retrigger script' device when the minutes of current time are 0, 5, 10 etc
Spoiler: show

Code: Select all

2020-01-22 21:58:23.469 Status: dzVents: !Info: trigger combination test: init script triggered this script

2020-01-22 22:00:00.551 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:05.614 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:10.698 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:15.773 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:20.811 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:25.859 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:30.934 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:35.982 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:41.066 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:46.140 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:51.186 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:00:56.271 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script

2020-01-22 22:05:00.329 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:05.411 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:10.493 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:15.578 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:20.653 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:25.692 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:30.733 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:35.822 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:40.902 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:45.976 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:51.014 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
2020-01-22 22:05:56.054 Status: dzVents: !Info: trigger combination test: retrigger script triggered this script
A solution for what I think you want would be something like this

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'scriptTrigger',
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = "trigger combination test"
    },

    data = 
    {
        lastTimeTriggered = { initial = 0 },
    },

    execute = function(dz, item)
        local secondsAgo = dz.time.dDate - dz.data.lastTimeTriggered 
        if dz.time.dDate - dz.data.lastTimeTriggered < 100 then 
            dz.log('Too soon after last execution. (Only ' .. secondsAgo .. ' seconds ago).', dz.LOG_DEBUG )
            return 
        end
        dz.data.lastTimeTriggered = dz.time.dDate

        -- rest of script
        dz.log('I will execute the rest of the script now. Previous execution was ' .. secondsAgo .. ' seconds ago.', dz.LOG_DEBUG)

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
AntoonvdOetelaar
Posts: 15
Joined: Thursday 24 August 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Holland
Contact:

Re: selective trigger DzVents scripts

Post by AntoonvdOetelaar »

Update:
Although not all scripts are functional at this moment, the crashing has completely stopped, since I updated to beta v4.11605. I also did an apt update en apt upgrade. Now it has run in total 12 days without any problems. Since yesterday also buienradar plug in and zigbee2mqtt is running.

@Waaren, thank you for trying to help me. Greatly appreciated.
RPI3B, Z-WAVE AEOTEC GEN5, Zigbee2Mqtt, Xiaomi gateway, GPIO, I2C, 1-wire, DS18B20, P1 meter, Growatt, Buienradar, Harmony hub, Domoticz 2020.2
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest