Timer trigger depending on device state. [SOLVED]

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

Moderator: leecollings

Post Reply
darkdude
Posts: 7
Joined: Thursday 20 June 2019 7:41
Target OS: Linux
Domoticz version: Release
Location: Poland
Contact:

Timer trigger depending on device state. [SOLVED]

Post by darkdude »

I need to make an event where if a certain device is on for at least 15 consecutive minutes another device will be triggered. I couldn't find a way to do it with just devices. I made a timer which runs every minute and if device 1 is still on, +1 is added to a counter. If it's off the counter resets.

Code: Select all

return {

active = true,

	on = { 
	      timer = {'every 1 minutes'}
	    },
	   
	data = {
	    counter = { initial = 0 }
	    },
       

	execute = function(domoticz, _)

   if (domoticz.devices("POMPA ZBIORNIKA").state == "On" and domoticz.devices("HISTEREZA_NAPELNIANIA").state == "On" and domoticz.data.counter <15) then
       
       domoticz.data.counter = domoticz.data.counter + 1
        domoticz.log (domoticz.data.counter)
       
   elseif (domoticz.devices("POMPA ZBIORNIKA").state ~= "On" or domoticz.devices("HISTEREZA_NAPELNIANIA").state ~= "On") then 
       
        domoticz.data.counter = 0 
         
          domoticz.log (domoticz.data.counter)
        
    elseif  (domoticz.data.counter == 15) then 
        
        domoticz.devices("HISTEREZA_NAPELNIANIA").switchOff().checkFirst()
          domoticz.log (domoticz.data.counter)
       
	    end
	end
}

This one works (the probing resolution is really bad, but it's enough in this case). However this whole event may occur only a few times a year. If possible I don't want a script to run every minute for a whole year just for this.

Is it possible to activate this script only if a switch.state == "On" (not on a change of state)?

Cheers!
Last edited by darkdude on Sunday 14 July 2019 8:42, 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: Timer trigger depending on device state.

Post by waaren »

darkdude wrote: Sunday 14 July 2019 7:27 I need to make an event where if a certain device is on for at least 15 consecutive minutes another device will be triggered. I couldn't find a way to do it with just devices. I made a timer which runs every minute and if device 1 is still on, +1 is added to a counter. If it's off the counter resets.

Is it possible to activate this script only if a switch.state == "On" (not on a change of state)?
Try this.

Code: Select all

return {
    active = function(domoticz)
         return domoticz.devices('your switch').active
    end,
    
    on = { 
          timer = {'every 1 minutes'}
        },
       
    data = {
        counter = { initial = 0 }
        },
       

    execute = function(domoticz, _)

   if (domoticz.devices("POMPA ZBIORNIKA").state == "On" and domoticz.devices("HISTEREZA_NAPELNIANIA").state == "On" and domoticz.data.counter <15) then
       
       domoticz.data.counter = domoticz.data.counter + 1
        domoticz.log (domoticz.data.counter)
       
   elseif (domoticz.devices("POMPA ZBIORNIKA").state ~= "On" or domoticz.devices("HISTEREZA_NAPELNIANIA").state ~= "On") then 
       
        domoticz.data.counter = 0 
         
          domoticz.log (domoticz.data.counter)
        
    elseif  (domoticz.data.counter == 15) then 
        
        domoticz.devices("HISTEREZA_NAPELNIANIA").switchOff().checkFirst()
          domoticz.log (domoticz.data.counter)
       
        end
    end
}
            
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
darkdude
Posts: 7
Joined: Thursday 20 June 2019 7:41
Target OS: Linux
Domoticz version: Release
Location: Poland
Contact:

Re: Timer trigger depending on device state. [SOLVED]

Post by darkdude »

Yep, that does it.

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest