Updating incremental counter with TIME value / json
Moderator: leecollings
Updating incremental counter with TIME value / json
Is there a way, to store a value - an user variable - into a dummy counter, that measures time?
I tried a lot of different settings, but without any luck
I would like to create a simple run time counter, since I have to replace a special device every 8000 running hours.
So I made a simple blockly, that should write a new value of 1 minute to an incremental dummy counter.
But whatever I try, the counter does not show any activity.
I also tried different json commands, in order to increase the counter, but without any luck too...
e.g. http://<ip>:<port>/json.htm?type=command¶m=udevice&idx=88&nvalue=59
The result is always "ok", but no sign/values change within the counter (still got the question-marks).
If I set the counter to "counter" the value increases. But this gives me only the result in minutes, and hours would be sufficient
The device 89 is a dummy hardware counter, with the type "time" (instead of count, energy, gas, water etc).
What would be the correct way, to increase the the counter every minute?
I tried a lot of different settings, but without any luck
I would like to create a simple run time counter, since I have to replace a special device every 8000 running hours.
So I made a simple blockly, that should write a new value of 1 minute to an incremental dummy counter.
But whatever I try, the counter does not show any activity.
I also tried different json commands, in order to increase the counter, but without any luck too...
e.g. http://<ip>:<port>/json.htm?type=command¶m=udevice&idx=88&nvalue=59
The result is always "ok", but no sign/values change within the counter (still got the question-marks).
If I set the counter to "counter" the value increases. But this gives me only the result in minutes, and hours would be sufficient
The device 89 is a dummy hardware counter, with the type "time" (instead of count, energy, gas, water etc).
What would be the correct way, to increase the the counter every minute?
Re: Updating incremental counter with TIME value / json
Have been searching too long today, and cant find answers.....
Maybe another idea to implement the runtime counter:
Running a python script from within blocky.
Script starts from within Blockly and stops if device started, stopped of day change (after 24:00hrs).
The variables should be then
TimeDeviceStart
TimeDeviceStop
Script should contain command line variables and would be like (e.g.)
RunTimeCalc.py <deviceIdx> <TimeDeviceStart> <TimeDeviceStop>
(no need to create a script for every counter needed)
The scripts might receive the data with a json command
http://localhost:<port>/json.htm?type=command¶m=getuservariable&idx=<deviceIdx>
After calculation TimeDeviceStop-TimeDeviceStrat I would like to write the result into the Domoticz incremental counter (the hours / the rest are left-over minutes and must be restored to the runtime variable).
This can be done with a json http call too. E.g.
requests.get("localhost:<port>/json.htm?type=command¶m=udevice&idx=%s&svalue=%d" % (server, port, deviceIdx, value))
But I have really no idea how to start with this script since I'm not familiar with Python (or other recent scripting languages) and the Wiki's didnt bring the right examples - to understand the script anywat .
I googled a simple calculation in Python that does the job if the CMD is used (and tested it).....
def getime(prom):
"""Prompt for input, return minutes since midnight"""
s = raw_input('Enter time-%s (hh:mm): ' % prom)
sh, sm = s.split(':')
return int(sm) + 60 * int(sh)
time1 = getime('1')
time2 = getime('2')
diff = time2 - time1
print "Difference: %d hours and %d minutes" % (diff//60, diff%60)
How do I get the values from Blockly in Python script with parameters from the command line and how to export the results afterwards into the timer?
Is there anyone able to help or give e good directions (for a new-be)?
Maybe another idea to implement the runtime counter:
Running a python script from within blocky.
Script starts from within Blockly and stops if device started, stopped of day change (after 24:00hrs).
The variables should be then
TimeDeviceStart
TimeDeviceStop
Script should contain command line variables and would be like (e.g.)
RunTimeCalc.py <deviceIdx> <TimeDeviceStart> <TimeDeviceStop>
(no need to create a script for every counter needed)
The scripts might receive the data with a json command
http://localhost:<port>/json.htm?type=command¶m=getuservariable&idx=<deviceIdx>
After calculation TimeDeviceStop-TimeDeviceStrat I would like to write the result into the Domoticz incremental counter (the hours / the rest are left-over minutes and must be restored to the runtime variable).
This can be done with a json http call too. E.g.
requests.get("localhost:<port>/json.htm?type=command¶m=udevice&idx=%s&svalue=%d" % (server, port, deviceIdx, value))
But I have really no idea how to start with this script since I'm not familiar with Python (or other recent scripting languages) and the Wiki's didnt bring the right examples - to understand the script anywat .
I googled a simple calculation in Python that does the job if the CMD is used (and tested it).....
def getime(prom):
"""Prompt for input, return minutes since midnight"""
s = raw_input('Enter time-%s (hh:mm): ' % prom)
sh, sm = s.split(':')
return int(sm) + 60 * int(sh)
time1 = getime('1')
time2 = getime('2')
diff = time2 - time1
print "Difference: %d hours and %d minutes" % (diff//60, diff%60)
How do I get the values from Blockly in Python script with parameters from the command line and how to export the results afterwards into the timer?
Is there anyone able to help or give e good directions (for a new-be)?
-
- Posts: 536
- Joined: Friday 23 December 2016 16:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: Netherlands Purmerend
- Contact:
Re: Updating incremental counter with TIME value / json
What about this :
Have a python script started by cron every min
have the python script checking if the device runs if yes the + the number minutes
have python increment the device counter
You could update a text device with a calculated hours from min to hours and even calculate hours to go
main message : use a single script and do not jump from blocky into python and so..
Have a python script started by cron every min
have the python script checking if the device runs if yes the + the number minutes
have python increment the device counter
You could update a text device with a calculated hours from min to hours and even calculate hours to go
main message : use a single script and do not jump from blocky into python and so..
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Updating incremental counter with TIME value / json
I am sure there are more ways to get what you want but one method is to use the information already available in the domoticz database.FrankVZ wrote: ↑Monday 04 June 2018 1:26 Is there a way, to store a value - an user variable - into a dummy counter, that measures time?
I tried a lot of different settings, but without any luck
I would like to create a simple run time counter, since I have to replace a special device every 8000 running hours.
So I made a simple blockly, that should write a new value of 1 minute to an incremental dummy counter.
But whatever I try, the counter does not show any activity.
I also tried different json commands, in order to increase the counter, but without any luck too...
e.g. http://<ip>:<port>/json.htm?type=command¶m=udevice&idx=88&nvalue=59
The result is always "ok", but no sign/values change within the counter (still got the question-marks).
What would be the correct way, to increase the the counter every minute?
Implemented in dzVents it could be something like this:
- Spoiler: show
I now trigger the script once a day but can be done less frequent as long it's is more frequent than the setting in [SETTINGS] [SETUP] [LOG_HISTORY]
It keeps track which entries are already processed by means of the index of the log-entries.
It now writes the amount of hours into a text device but can do a similar action for all type of devices.
[EDIT] now also handles multiple consecutive "Off" / "On" states
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Updating incremental counter with TIME value / json
Or with a more realtime approach but still not having to execute every minute..
Code: Select all
--[[ getUptime.lua for [ dzVents >= 2.4 ]
]]--
return {
on = { devices = { nnn }}, -- name enclosed in quotes or IDX number without quotes
logging = { level = domoticz.LOG_DEBUG,
marker = "getUptime" },
data = { lastState = { initial = "Off" },
secondsOn = { initial = 0 },
lastSwitchTime = { initial = "0" }},
execute = function(dz,trigger)
local myTextDevice = dz.devices("hourCounter") -- name enclosed in quotes or number without
-- ( or remove if you don't want textDevice )
local function updateSensor()
if myTextDevice then
local myText = "\nRuntime in hours for device " .. trigger.name .. " ==>> ".. dz.utils.round( tonumber(dz.data.secondsOn) / 3600 )
if myTextDevice.text ~= myText then
myTextDevice.updateText( myText )
end
end
end
if trigger.state ~= dz.data.lastState then
if trigger.state == "Off" then
local Time = require('Time')
t1 = Time(dz.time.rawDate .." " .. dz.time.rawTime)
t2 = Time(dz.data.lastSwitchTime)
deltaTime = t1.compare(t2).secs
dz.data.secondsOn = dz.data.secondsOn + deltaTime
updateSensor()
end
dz.data.lastState = trigger.state
dz.data.lastSwitchTime = dz.time.rawDate .. " " .. dz.time.rawTime
end
dz.log("State ==>> " .. trigger.state .. "; Date Time ==>> " .. dz.time.rawDate .." " ..
dz.time.rawTime .. "; secondsOn ===>> " .. dz.data.secondsOn ,dz.LOG_DEBUG)
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
Re: Updating incremental counter with TIME value / json
Thanks Waaren for your effort!
I was hoping to test it today, but I noticed that dzVents and lua scripts didnt work (running the latest beta from jadahl). A problem with the default location of the dzVents folder and the actual location at my Synology. (oh man, this proces has a steep learning curve )
Anyway, took me a day, but now dzVents works so I'll try your suggestion! (re-installing older stable version, copy files, reinstall (not update) beta, all in CLI /SSH (since WinSCP is not useible for this)... a lot learned and I hope I'll remember.
I do agree that using the existing logs is much better, instead of creating them ourselves. But I read somewhere that these logs are not accessible, so I skipped this in my suggestion.... but now they are..... Great!
I'll keep it updated. As you may notice, I dont give up, but wow - this is consuming time to learn. So no answer today. But if it works - the "feel good" moment of the week
I was hoping to test it today, but I noticed that dzVents and lua scripts didnt work (running the latest beta from jadahl). A problem with the default location of the dzVents folder and the actual location at my Synology. (oh man, this proces has a steep learning curve )
Anyway, took me a day, but now dzVents works so I'll try your suggestion! (re-installing older stable version, copy files, reinstall (not update) beta, all in CLI /SSH (since WinSCP is not useible for this)... a lot learned and I hope I'll remember.
I do agree that using the existing logs is much better, instead of creating them ourselves. But I read somewhere that these logs are not accessible, so I skipped this in my suggestion.... but now they are..... Great!
I'll keep it updated. As you may notice, I dont give up, but wow - this is consuming time to learn. So no answer today. But if it works - the "feel good" moment of the week
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Updating incremental counter with TIME value / json
Understand. It also took me quite some time to find answers on the different settings and directories on Synology NAS.
That and the fact that I could not compile myself on that platform were the main reasons why I moved to Raspberry with berryboot (Debian Stretch). This has also challenges but far less.
I still have a domoticz instance running on my Synology for test purposes and do use WinSCP to work on that system. What problem do you face with it ?
That and the fact that I could not compile myself on that platform were the main reasons why I moved to Raspberry with berryboot (Debian Stretch). This has also challenges but far less.
I still have a domoticz instance running on my Synology for test purposes and do use WinSCP to work on that system. What problem do you face with it ?
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
Re: Updating incremental counter with TIME value / json
Well, my main problem with the syno is to run winSCP and login with root, in order to drag-and-drop files on the syno. Doing this by CLI (Putty) is quite difficult - mistakes are easily made.
But that has been done now, amd dzVents runs within Domoticz. Unfortunatly python not, because the option Python is not shown within the events editor. So I have to run python scripts with the task scheduler from DSM6.1
That has an advantage too: I noticed that your second script causes domoticz to crash at midnight (form that moment I get notifications from Syno that the python script is causing errors - domoticz is off line.
So I gave it another try: running the first script you did show above. With a minor mod.
That has a strange effect too: I'm sure using the correct Idx - but whatever I try: using my Idx 8 as trigger, there happens a lot, but no counting. Instead my Idx 52 gets activated, while idx 8 and 52 are not connnected in any way! (8=my light in the study, 52 is a circulationpump from my pond in the garden)..... So there must be ghosts in town.....
Absolutely no clue what happens.
So I want the runtime counters. Best would be to use the counters that are build-in.
To update these counters I know the json command works, but a command from within dzVents should work too.
But what is wrong in the script? I try 3 different ways (the updateSensor() function), and none of them show an update within the counter so doesnt work.
I think I dont understand the wiki enough (the correct syntax) so there might be things wrong...
But that has been done now, amd dzVents runs within Domoticz. Unfortunatly python not, because the option Python is not shown within the events editor. So I have to run python scripts with the task scheduler from DSM6.1
That has an advantage too: I noticed that your second script causes domoticz to crash at midnight (form that moment I get notifications from Syno that the python script is causing errors - domoticz is off line.
So I gave it another try: running the first script you did show above. With a minor mod.
That has a strange effect too: I'm sure using the correct Idx - but whatever I try: using my Idx 8 as trigger, there happens a lot, but no counting. Instead my Idx 52 gets activated, while idx 8 and 52 are not connnected in any way! (8=my light in the study, 52 is a circulationpump from my pond in the garden)..... So there must be ghosts in town.....
Absolutely no clue what happens.
So I want the runtime counters. Best would be to use the counters that are build-in.
To update these counters I know the json command works, but a command from within dzVents should work too.
But what is wrong in the script? I try 3 different ways (the updateSensor() function), and none of them show an update within the counter so doesnt work.
I think I dont understand the wiki enough (the correct syntax) so there might be things wrong...
- Spoiler: show
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Updating incremental counter with TIME value / json
I have the line sudo su - in advanced shell shell area of the winSCP session config. No problems to drag and drop files on my Synology
Do you use a version from Jadahl with Python included ?
Do you have any logs on this as the seconds script is triggered by a device event and is not based on time. ?
Here also; very much interrested in domoticz logging. Could you please try to switch debug logging on and revert with the logs ?FrankVZ wrote: ↑Thursday 07 June 2018 23:40 So I gave it another try: running the first script you did show above. With a minor mod.
That has a strange effect too: I'm sure using the correct Idx - but whatever I try: using my Idx 8 as trigger, there happens a lot, but no counting. Instead my Idx 52 gets activated, while idx 8 and 52 are not connnected in any way! (8=my light in the study, 52 is a circulationpump from my pond in the garden)..... So there must be ghosts in town.....
Absolutely no clue what happens.
the updateSensor() function as coded now is only working for text devices. For a counter device you will need another function / command.FrankVZ wrote: ↑Thursday 07 June 2018 23:40 So I want the runtime counters. Best would be to use the counters that are build-in.
To update these counters I know the json command works, but a command from within dzVents should work too.
But what is wrong in the script? I try 3 different ways (the updateSensor() function), and none of them show an update within the counter so doesnt work.
I think I dont understand the wiki enough (the correct syntax) so there might be things wrong...
Something like updateCounter(value)
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
Re: Updating incremental counter with TIME value / json
I dont know why, but for some reason it is advised for the synology to use the sudo -i instead (for the newer DSM versions).
See https://www.synology-forum.nl/algemeen/ ... nscp-putty
I tried that method, but still worried that you are able to login with a root account, without using the password. Might be a more sensitive for vulnerabilities...
For temporary situations looks good and can I drag and drop with WinSCP too. Afterwarts, I put the settings back to their original state.
Without the Python option, because I use Python for other packages on the synology too. Installing Jadahls version with Python sounds like conflicts because of different Python versions?
After Domoticz goes offline at 0:00hrs (crash?), all the content of the logs is erased. The first entry of the log is just from the moment I restarted the service within DSM.
Checked for other logs, but nothing seen....
I'll check tonight what happens if I first download the domoticz.log file with WinSCP, before restarting the service. Maybe there is some info left....
It might have to do with the calculation of 0:00 - 23:59, what gives a negative number that is supposed to be an integer?
I try tomorrow. see if I can reproduce this...
I think I tried that in the previous posting Must be a syntax thing and I give it another try.
Re: Updating incremental counter with TIME value / json
Hi,
About the crashes: still every day at midnight.
I have another Syno DS (ds218+), and installed Domoticz too, but the latest stable version. Then restored the database of the running machine (ds214+) with the beta software (be aware of backward compatability issues?). But the DS218 does not crash....
Rebooting the service after the crash shows an empty log, and only contains the data from the reboot.
See the log:
About the crashes: still every day at midnight.
I have another Syno DS (ds218+), and installed Domoticz too, but the latest stable version. Then restored the database of the running machine (ds214+) with the beta software (be aware of backward compatability issues?). But the DS218 does not crash....
Rebooting the service after the crash shows an empty log, and only contains the data from the reboot.
See the log:
- Spoiler: show
Re: Updating incremental counter with TIME value / json
For the supplied script does almost do what is has to do
Since I dont understand the script yet (and took a looooot of time, now 2 days busy to find answeres) maybe you can help me out.
I would like to improve the script, being more "realtime" (and not only measuring the time between off and on.
So I thought to insert a timer that only runs if the device is triggered On and adds measured time to the regular counter.
But the I run into several problems:
The timer runs always, even the device is Off (or is it possible to disable the timertrigger somehow?).
I tried e.g.
So I get errors with .lastState, lastSwitchState, trigger.state, dz.lastState or lastUpdate values (doesnt even show them in the db.log
But this makes me wondering too:
Where are the extensions like "laststate" and "lastswitchstate" coming from? Like the "lastSwitch time" is not handled like a local variable, otherwise it shouldnt be "nill" value?
I cant find the in the domoticz wiki. I even looked (with an DB sqlite editor) into the database, and could not find anything like it within the database structure, except for the field "LastUpdate" (starts with a capital instead of the used variable - dont know if that makes any difference).
Lighting.log shows within the Domoticz.db a "nValue" too and I noticed (in the database) that nvalue >0 = On ; nValue 0 = Off. Coincidence, or is that always the case? If so: using that variable should solve most issues I encounter (easier to get and use within dzvents I think)
The script so far (and sorry for the noob questions.....);
Since I dont understand the script yet (and took a looooot of time, now 2 days busy to find answeres) maybe you can help me out.
I would like to improve the script, being more "realtime" (and not only measuring the time between off and on.
So I thought to insert a timer that only runs if the device is triggered On and adds measured time to the regular counter.
But the I run into several problems:
The timer runs always, even the device is Off (or is it possible to disable the timertrigger somehow?).
I tried e.g.
- Spoiler: show
So I get errors with .lastState, lastSwitchState, trigger.state, dz.lastState or lastUpdate values (doesnt even show them in the db.log
But this makes me wondering too:
Where are the extensions like "laststate" and "lastswitchstate" coming from? Like the "lastSwitch time" is not handled like a local variable, otherwise it shouldnt be "nill" value?
I cant find the in the domoticz wiki. I even looked (with an DB sqlite editor) into the database, and could not find anything like it within the database structure, except for the field "LastUpdate" (starts with a capital instead of the used variable - dont know if that makes any difference).
Lighting.log shows within the Domoticz.db a "nValue" too and I noticed (in the database) that nvalue >0 = On ; nValue 0 = Off. Coincidence, or is that always the case? If so: using that variable should solve most issues I encounter (easier to get and use within dzvents I think)
The script so far (and sorry for the noob questions.....);
- Spoiler: show
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Updating incremental counter with TIME value / json
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
Re: Updating incremental counter with TIME value / json
Hi, again a few days further, with a lot of trial and error
The system still crashes at exactly midnight (with I think is a dzVents issue, since the log alway stops there).
Today I moved the domoticz to another server (DS218+) that run the same version (and almost the same database) but never crashed.
Now I have to wait and see what happenes,
Thanks by the way for the effort you did put in my questions Waaren - great work. Most of the details I think I'm going to understand by now so it really did help a lot
But there are still a lot of question marks in between my ears, that are related to the syntax (how exactly has a line to be written, what functions/extensions etc are available for this situation (within your script there are also extensions used that I couldnt find in the wiki, how local is a local variable, etc . There are some hints within the wiki and the wiki might be a handy library for the more experienced user, but for a noob like me.....
Thanks anyway for the link, but I've read the wiki a 100 times by now (and also about lua scripting guides, and other forums, etc etc...).
For now I have the script working fine with logging data to a counter, so for me that part is solved
There is still one thing left that bothers me: within the script the run time is logged every 6 minutes. That makes 10 data entries within the database, and they are within the .db too.
But for some reason I only get graphs with an interval time of 1 hour instead of 6 minutes (I tried 10 minutes too). If this graphical resolution could be improved somehow.... that would be great.
The system still crashes at exactly midnight (with I think is a dzVents issue, since the log alway stops there).
Today I moved the domoticz to another server (DS218+) that run the same version (and almost the same database) but never crashed.
Now I have to wait and see what happenes,
Thanks by the way for the effort you did put in my questions Waaren - great work. Most of the details I think I'm going to understand by now so it really did help a lot
But there are still a lot of question marks in between my ears, that are related to the syntax (how exactly has a line to be written, what functions/extensions etc are available for this situation (within your script there are also extensions used that I couldnt find in the wiki, how local is a local variable, etc . There are some hints within the wiki and the wiki might be a handy library for the more experienced user, but for a noob like me.....
Thanks anyway for the link, but I've read the wiki a 100 times by now (and also about lua scripting guides, and other forums, etc etc...).
For now I have the script working fine with logging data to a counter, so for me that part is solved
There is still one thing left that bothers me: within the script the run time is logged every 6 minutes. That makes 10 data entries within the database, and they are within the .db too.
But for some reason I only get graphs with an interval time of 1 hour instead of 6 minutes (I tried 10 minutes too). If this graphical resolution could be improved somehow.... that would be great.
-
- Posts: 7
- Joined: Thursday 15 August 2019 22:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Updating incremental counter with TIME value / json
I'm a beginner in scripts. I tried to use the script to calculate the uptime of my heater, but without success. I gave IDX switch, I created Text Device "hourCounter", but after running the script I receive a message: " 1: return: Illegal number: { "
Could I ask you to explain how to use the script? Thank you in advance.
Could I ask you to explain how to use the script? Thank you in advance.
waaren wrote: ↑Tuesday 05 June 2018 10:00 Or with a more realtime approach but still not having to execute every minute..
Code: Select all
--[[ getUptime.lua for [ dzVents >= 2.4 ] ]]-- return { on = { devices = { nnn }}, -- name enclosed in quotes or IDX number without quotes logging = { level = domoticz.LOG_DEBUG, marker = "getUptime" }, data = { lastState = { initial = "Off" }, secondsOn = { initial = 0 }, lastSwitchTime = { initial = "0" }}, execute = function(dz,trigger) local myTextDevice = dz.devices("hourCounter") -- name enclosed in quotes or number without -- ( or remove if you don't want textDevice ) local function updateSensor() if myTextDevice then local myText = "\nRuntime in hours for device " .. trigger.name .. " ==>> ".. dz.utils.round( tonumber(dz.data.secondsOn) / 3600 ) if myTextDevice.text ~= myText then myTextDevice.updateText( myText ) end end end if trigger.state ~= dz.data.lastState then if trigger.state == "Off" then local Time = require('Time') t1 = Time(dz.time.rawDate .." " .. dz.time.rawTime) t2 = Time(dz.data.lastSwitchTime) deltaTime = t1.compare(t2).secs dz.data.secondsOn = dz.data.secondsOn + deltaTime updateSensor() end dz.data.lastState = trigger.state dz.data.lastSwitchTime = dz.time.rawDate .. " " .. dz.time.rawTime end dz.log("State ==>> " .. trigger.state .. "; Date Time ==>> " .. dz.time.rawDate .." " .. dz.time.rawTime .. "; secondsOn ===>> " .. dz.data.secondsOn ,dz.LOG_DEBUG) end }
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Updating incremental counter with TIME value / json
Did you save the script as a dzVents type in the internal editor ?
When not yet familiar with dzVents please start with reading Get started Before implementing. Special attention please for
"In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
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: 7
- Joined: Thursday 15 August 2019 22:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Updating incremental counter with TIME value / json
The problem was the lack of address 127.0.0.1. Now everything works, thanks for your help and information!
I would like to pass the results of the script to counter incremental (to have daily, monthly sums etc). Is that possible? I tried to edit the script, but unfortunately for now it is beyond my capabilities. I would appreciate your help.
I would like to pass the results of the script to counter incremental (to have daily, monthly sums etc). Is that possible? I tried to edit the script, but unfortunately for now it is beyond my capabilities. I would appreciate your help.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Updating incremental counter with TIME value / json
Yes but can you please explain what you want to send to the counter incremental. Is that the total On time overall or should it reset to zero daily or something else ?
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: 7
- Joined: Thursday 15 August 2019 22:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Updating incremental counter with TIME value / json
I would like to have statistics On time daily, monthly, annual. It should reset to zero daily.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Updating incremental counter with TIME value / json
OK need some time to test if the counter incremental is best suited for this or that using a 'normal'counter is preferable. Might take a couple of days before I have these results.
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 0 guests