NoClaim wrote:... I also like the last provided option.... combination of blocky and lua scripts.....but need the script for it (I don't have any scripting experience....

)
There are a few examples in the wiki. You can start reading them and try to find out what is being done. That's how I do it. But it takes time and effort to understand it, but it feels great when you make yourself a working script. Let me give you some info. Remember, these are my interpretations of things and maybe I make some mistakes or things can be done easier, but then again: if it works, I'm where I wanna be.
First a script:
Code: Select all
s = otherdevices_lastupdate['PushOnButton']
t = os.time()
commandArray = {}
print (s)
print (t)
return commandArray
Change the PushOnButton with the name of one of your own switches. Save this script as script_time_timetest.lua and put in in the LUA dir of Domoticz. Then take a look at the logging. In my case I see this:
2016-03-17 22:51:00.302 LUA: 2016-03-09 15:43:19
2016-03-17 22:51:00.302 LUA: 1458251460
Now I can see when my PushOnButton is last updated. But when I look at the OS time I see something very different. The system can't compare those two values or do maths with it. So I need to reconstruct the lastupdate.
In the script, between s and t, I put the following:
Code: Select all
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
ts = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
What does it do? I tell the system to get the characters 1 through 4 of the string 's' (that is the output of the lastupdate request) to be the value of 'year', characters 6 and 7 to be the value of 'month', etc. Then I rebuild this (in a way the system could use it to compare or do math with the os time) as the value of 'ts', to tell it that 'ts' is an os.time constructed with the values year, month, etc.
In the script, between print(s) and print (t), put the following line in between:
Then again, take a look at the log. In my case it shows this:
2016-03-17 23:03:00.051 LUA: 2016-03-09 15:43:19
2016-03-17 23:03:00.051 LUA: 1457534599
2016-03-17 23:03:00.051 LUA: 1458252180
I see the lastupdate in a way I can understand, the next line shows me after rebuilding it and the last line is the actual time. With those last two line, you can do maths with it. In the script, under thel line t = os.time(), put the following:
.. and below the line print(t), put this:
Code: Select all
print ('Difference in seconds is:')
print (diff)
Again, I take a look at the log:
2016-03-17 23:08:00.254 LUA: 2016-03-09 15:43:19
2016-03-17 23:08:00.254 LUA: 1457534599
2016-03-17 23:08:00.254 LUA: 1458252480
2016-03-17 23:08:00.254 LUA: Difference in seconds is:
2016-03-17 23:08:00.254 LUA: 717881
Oh my god, it's a lot of info. I like to try these things out and put it here for you to examine it. Maybe it gets you interested in trying to learn LUA. Try to understand what is happening and how it could be of any use to you.
