DsVents global var lastupdate
Moderator: leecollings
-
- Posts: 19
- Joined: Thursday 03 March 2016 18:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
DsVents global var lastupdate
Is it possible to get the lastupdate time of a global var
Form what i can tell reading the wiki it could be possible but i can’t get it working
Form what i can tell reading the wiki it could be possible but i can’t get it working
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: DsVents global var lastupdate
Yes, it is possible if you mean a global var within dzVents
Look at the A special kind of persistent variables: history = true (Historical variables API) section in
https://www.domoticz.com/wiki/DzVents:_ ... _variables
relevant scriptlines:
Look at the A special kind of persistent variables: history = true (Historical variables API) section in
https://www.domoticz.com/wiki/DzVents:_ ... _variables
relevant scriptlines:
Code: Select all
data = {
myGlobalVar = { history = true, maxItems = 1 }
},
local myPersistentVar = domoticz.data.myGlobalVar
myPersistentVar.add("test data")
print ( 'Oldest time stamp in history: ' .. myPersistentVar.getOldest().time.getISO())
print ( 'Last added value in history: ' .. myPersistentVar.getLatest().data)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 19
- Joined: Thursday 03 March 2016 18:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: DsVents global var lastupdate
Thx and what About script level vars
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: DsVents global var lastupdate
Please elaborate on what your exact requirement is. A sample script might help me understand what you try to achieve
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 19
- Joined: Thursday 03 March 2016 18:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: DsVents global var lastupdate
Its for a lux meter.
If the lux level is below or above a set level for a set time turn on or off the lights
Made this in plain lua and want to port this to dzvents
There the var is only updated once and only if the current lux is above or under the set level.
If the var is not changed for a set time the lights a turned off or on
Hope this makes sence
If the lux level is below or above a set level for a set time turn on or off the lights
Made this in plain lua and want to port this to dzvents
There the var is only updated once and only if the current lux is above or under the set level.
If the var is not changed for a set time the lights a turned off or on
Hope this makes sence

- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: DsVents global var lastupdate
Could you try this and come back with your result ?Deluka wrote: ↑Friday 09 March 2018 19:11 Its for a lux meter.
If the lux level is below or above a set level for a set time turn on or off the lights
Made this in plain lua and want to port this to dzvents
There the var is only updated once and only if the current lux is above or under the set level.
If the var is not changed for a set time the lights a turned off or on
Hope this makes sence![]()
Code: Select all
--[[
luxStateTest
]]--
return {
on = { timer = { "every minute" } },
data = { luxLevel = { history = true, maxItems = 1, initial = "Empty" } },
execute = function(domoticz, _)
local currentLux = domoticz.devices("Name of your lux device").lux or 'fail'
local luxSwitchLevel = 100 -- change to lux value where you want to switch on
local timeFence = 30 -- change to how many minutes you want to wait with switching the device on / off
local luxDependendLight = domoticz.devices("Name of your light")
local luxState = domoticz.data.luxLevel
local luxRecord = luxState.getLatest()
local luxData = luxRecord.data
local luxTime = luxRecord.time
if currentLux ~= 'fail' then
if currentLux >= luxSwitchLevel then
if luxData ~= "High" then
luxState.add("High")
elseif luxTime.minutesAgo > timeFence then
luxDependendLight.switchOff().checkFirst()
end
elseif currentLux < luxSwitchLevel then
if luxData ~= "Low" then
luxState.add("Low")
elseif luxTime.minutesAgo > timeFence then
luxDependendLight.switchOn().checkFirst()
end
end
else
print ( 'Skipped adding lux to my (Wrong lux reading) ' )
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 19
- Joined: Thursday 03 March 2016 18:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: DsVents global var lastupdate
Thx for your help but getting a error
attempt to index local 'luxRecord' (a nil value)
attempt to index local 'luxRecord' (a nil value)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: DsVents global var lastupdate
Probably because it is not defined yet at the first time the script is executed.
You could try to change the luxReord line into
Code: Select all
local luxRecord.data = luxState.getLatest().data or 'fail'
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 19
- Joined: Thursday 03 March 2016 18:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: DsVents global var lastupdate
still getting a error
When I alter this line in
into
The scripts works perfect
Thanks for your help with my first baby steps in DZvents
Code: Select all
2018-03-10 18:41:28.354 dzVents: Error (2.4.1): error loading module 'lux' from file '/home/pi/domoticz/scripts/dzVents/scripts/lux.lua':
/home/pi/domoticz/scripts/dzVents/scripts/lux.lua:16: unexpected symbol near '.'
Code: Select all
local luxRecord.date = luxState.getLatest() or 'fail'
Code: Select all
local luxRecord = luxState.getLatest() or 'fail'
Thanks for your help with my first baby steps in DZvents

- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: DsVents global var lastupdate


Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest