Issue with lastUpdate.minutesAgo

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

Moderator: leecollings

Post Reply
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Issue with lastUpdate.minutesAgo

Post 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 1443 times
And can a friendly sole tell me where I go wrong?
/lennart
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: Issue with lastUpdate.minutesAgo

Post 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
}
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Issue with lastUpdate.minutesAgo

Post 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?
/lennart
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: Issue with lastUpdate.minutesAgo

Post 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
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Issue with lastUpdate.minutesAgo

Post by dannybloe »

Indeed. A variable cannot start with a number.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Issue with lastUpdate.minutesAgo

Post by leby »

many thx!!
/lennart
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest