Page 1 of 1
Persistent (global)data save Time()
Posted: Monday 18 June 2018 12:30
by Freemann
I'm struggeling a bit with the following case;
I want to have the last time a device is switch ON and in most case the last ON time is not equal to the lastUpdate property.
So I decided to save the Time() to an (global)data variable, but that isn't working.
Look like dzVents is not saving the Time() object when doing something like:
domoticz.globalData.BadkamerLastMotionOn = Time()
or
domoticz.data.BadkamerLastMotionOn = Time()
both variables are define in OR global_data.lua OR in the script itself.
Is this a known "bug" and/or has somebody an idea how to save the last ON time to persistent storage?
Re: Persistent (global)data save Time()
Posted: Monday 18 June 2018 12:37
by dannybloe
Don't save the Time object but just the raw value. If you use historical=true with persistence you automatic get a time stamp on your data. So, define your persistent variable with history = true and maxItems = 1 and simply store the state value in there. Then you can easily read the time stamp of the current value. Check the documentation about historical data.
Re: Persistent (global)data save Time()
Posted: Monday 18 June 2018 13:25
by Freemann
So easy... (zo simple)
Hero (HELD)!!
Re: Persistent (global)data save Time()
Posted: Monday 18 June 2018 16:47
by waaren
Freemann wrote: Monday 18 June 2018 12:30
I want to have the last time a device is switch ON and in most case the last ON time is not equal to the lastUpdate property.
So I decided to save the Time() to an (global)data variable.
Look like dzVents is not saving the Time() object when doing something like:
domoticz.globalData.BadkamerLastMotionOn = Time()
or
domoticz.data.BadkamerLastMotionOn = Time()
... has somebody an idea how to save the last ON time to persistent storage?
Just for completeness; dzVents is capable of storing the time object in persistent storage.
see example code and resulting datafile
- Spoiler: show
Code: Select all
-- timeTest.lua
return {
on = { devices = { "timeTriggerDevice"}},
data = { currentTimeTable = { initial = "" },
nextTimeTable = { initial = "" },
nextTimeValue = { initial = "" }},
execute = function(dz, trigger)
dz.data.currentTimeTable = os.date('*t') -- Now as table
dz.data.nextTimeTable = os.date("*t",os.time(dz.data.currentTime)+3600) -- now + 1 hour as table
dz.data.nextTimeValue = os.date("%c",os.time(dz.data.currentTime)) -- now as string
end
}
__data_timeTest.lua
- Spoiler: show
Code: Select all
-- Persistent Data
local multiRefObjects = {
} -- multiRefObjects
local obj1 = {
["nextTimeValue"] = "Mon Jun 18 16:39:49 2018";
["nextTimeTable"] = {
["min"] = 39;
["hour"] = 17;
["sec"] = 49;
["day"] = 18;
["isdst"] = true;
["wday"] = 2;
["yday"] = 169;
["month"] = 6;
["year"] = 2018;
};
["currentTimeTable"] = {
["min"] = 39;
["hour"] = 16;
["sec"] = 49;
["day"] = 18;
["isdst"] = true;
["wday"] = 2;
["yday"] = 169;
["month"] = 6;
["year"] = 2018;
};
}
return obj1
Re: Persistent (global)data save Time()
Posted: Monday 18 June 2018 18:20
by dannybloe
Yes but it is not needed as I explained above. You can however extract the raw time string and store that and feed that back into Time() when you need it again.
Re: Persistent (global)data save Time()
Posted: Sunday 08 July 2018 21:59
by Freemann
So to "reuse" this topic;
Trying to make my variables global available, but not getting there.
how should I use the global define variables for getting/setting in my scripts?
Tried some variations like;
for setting:
Code: Select all
domoticz.globalData.motionVar.add('Foo')
domoticz.globalData.motionVar = 'On'
domoticz.data.motionVar.add('Foo')
domoticz.data.motionVar = 'On'
I'm not getting the __data_global_data.lua to show data...
and should I define the global_data vars in my "local" scripts again?
[SOLVED] and maybe it can help somebody
found it after some "testing/debugging";
/home/user/domoticz/scripts/dzVents/scripts/global_data.lua looks like;
Code: Select all
data = {
LastMotionOn = { history = true, maxItems = 1}
}
normal dzvents script is doing for historical setting;
Code: Select all
domoticz.globalData.LastMotionOn.add('On')
normal dzvents script is doing for historical getting;
Code: Select all
domoticz.globalData.LastMotionOn.get(1).time.secondsAgo