Page 1 of 1

Issue with lastUpdate.minutesAgo

Posted: Tuesday 08 August 2017 15:25
by leby
Running win10 and V3.8256

I try to turn of a fan after a fixed number of minutes. I can't get it to work.

First I tried with

Code: Select all

return {
    active = true,
    on = {
        timer = {'Every minute'}
    },
    execute = function(domoticz)
        if (domoticz.devices('1st floor Bathroom Fan').lastUpdate.minutesAgo > 3) 
        and domoticz.devices('1st floor Bathroom Fan') == 'On' 
        then domoticz.devices('1st floor Bathroom Fan').switchOff()
        end
        
    end
}
But no turning of...

I then changed to id (I thought have not used id before)

Code: Select all

return {
    active = true,
    on = {
        timer = {'Every minute'}
    },
    execute = function(domoticz)
        if (domoticz.devices('365').lastUpdate.minutesAgo > 3) 
        and domoticz.devices('365') == 'On' 
        then domoticz.devices('365').switchOff()
        end
        
    end
}
and got this

Code: Select all

2017-08-08 15:13:00.365 Error: dzVents: Error: There is no device with that name or id: 365
Is this ID?
Skärmklipp.JPG
Skärmklipp.JPG (23.31 KiB) Viewed 1432 times
And can a friendly sole tell me where I go wrong?

Re: Issue with lastUpdate.minutesAgo

Posted: Tuesday 08 August 2017 15:30
by Milifax
Try this:

domoticz.devices('1st floor Bathroom Fan').state == 'On'

Code: Select all

return {
    active = true,
    on = {
        timer = {'Every minute'}
    },
    execute = function(domoticz)
    
        if ( domoticz.devices('1st floor Bathroom Fan').lastUpdate.minutesAgo > 3 and domoticz.devices('1st floor Bathroom Fan').state == 'On' ) then 
        	domoticz.devices('1st floor Bathroom Fan').switchOff()
        end
        
    end
}
or declare a local:

Code: Select all

return {
    active = true,
    on = {
        timer = {'Every minute'}
    },
    execute = function(domoticz)
    
    	local 1stFloorBathroomFan = domoticz.devices(365)
    
        if ( 1stFloorBathroomFan.lastUpdate.minutesAgo > 3 and 1stFloorBathroomFan.state == 'On' ) then 
        	1stFloorBathroomFan.switchOff()
        end
        
    end
}

Re: Issue with lastUpdate.minutesAgo

Posted: Tuesday 08 August 2017 18:03
by leby
The first seems to work, thx

the second generates this

Code: Select all

2017-08-08 17:55:07.961 Error: dzVents: Error: error loading module 'Auto turn off fan' from file 'C:\Program Files (x86)\Domoticz\scripts\dzVents\generated_scripts/Auto turn off fan.lua':
...\scripts\dzVents\generated_scripts/Auto turn off fan.lua:8: expected near '1'
So when the issue is up, how do I declare a local?

Re: Issue with lastUpdate.minutesAgo

Posted: Tuesday 08 August 2017 18:14
by Milifax
leby wrote:The first seems to work, thx

the second generates this

Code: Select all

2017-08-08 17:55:07.961 Error: dzVents: Error: error loading module 'Auto turn off fan' from file 'C:\Program Files (x86)\Domoticz\scripts\dzVents\generated_scripts/Auto turn off fan.lua':
...\scripts\dzVents\generated_scripts/Auto turn off fan.lua:8: expected near '1'
So when the issue is up, how do I declare a local?
Guess it doesn't like the 1stFloor...

This should do better then:

Code: Select all

return {
    active = true,
    on = {
        timer = {'Every minute'}
    },
    execute = function(domoticz)
   
       local FirstFloorBathroomFan = domoticz.devices(365)
   
        if ( FirstFloorBathroomFan.lastUpdate.minutesAgo > 3 and FirstFloorBathroomFan.state == 'On' ) then
           FirstFloorBathroomFan.switchOff()
        end
       
    end
}

Re: Issue with lastUpdate.minutesAgo

Posted: Tuesday 08 August 2017 18:23
by dannybloe
Indeed. A variable cannot start with a number.

Re: Issue with lastUpdate.minutesAgo

Posted: Tuesday 08 August 2017 18:53
by leby
many thx!!