Page 1 of 1
Calculate Hours a device has run
Posted: Wednesday 10 February 2016 21:05
by punter9
Hi all I have an air filter in the house that runs based on a few things (geofence, time, etc) so it is not a steady amount each day. It runs when it makes sense. The pre filter and main filter need to be replaced after a set amount of hours. Is there a way to calculate the hours this thing has run via events, blockly, etc and get it to shoot me an email when it is time to replace the filter?
Re: Calculate Hours a device has run
Posted: Wednesday 10 February 2016 21:51
by Siewert308SW
punter9 wrote:Hi all I have an air filter in the house that runs based on a few things (geofence, time, etc) so it is not a steady amount each day. It runs when it makes sense. The pre filter and main filter need to be replaced after a set amount of hours. Is there a way to calculate the hours this thing has run via events, blockly, etc and get it to shoot me an email when it is time to replace the filter?
There are several ways.
But here's a simple quick lua script which has it roots from one of Thinkpad his scripts.
It's a simple counter which counts the minutes a switch has been on.
When it exeeds the runtime user settings it will show you a message in the maintenance message in the log.
Feel free to adapt it with for example a e-mail,pushover or any other script to let you know when maintenance is needed.
Don't know if it's working, haven't tested it...
With this script i didn't wrote a part for ressting the counter when a maintenance has been done so you need to manually set the counter back to zero.
Code: Select all
-- script_time_airfilter.lua
-- This script will count the minutes the Airfilter has run.
-- When the runtime hits the maximum run minutes it will show "Maintenance needed message" in the domoticz log
local airfilter_switch = 'Air Filter' -- Airfilter switch
local airfilter_uservar = 'AirfilterRunCounter' -- Uservariable
local airfilter_runtime = 3360 -- Minutes to replace filter (3360minutes = 20weeks 24/7)
commandArray = {}
run_airfilter_uservar = tonumber(uservariables[airfilter_uservar])
remaining = airfilter_runtime - run_airfilter_uservar
if (otherdevices[airfilter_switch] == 'On') then
run_airfilter_uservar = run_airfilter_uservar + 1
print('<font color="blue">Airfilter has already run for ' ..tonumber(run_airfilter_uservar).. ' minutes, maintenance needed in about ' ..tonumber(remaining).. ' minutes!</font>')
commandArray['Variable:' .. airfilter_uservar] = tostring(run_airfilter_uservar)
end
if run_airfilter_uservar > tonumber(airfilter_runtime) then
print('<font color="red">Airfilter has already run for ' ..tonumber(run_airfilter_uservar).. ' minutes, maintenance needed!</font>')
end
return commandArray
Re: Calculate Hours a device has run
Posted: Monday 22 February 2016 21:15
by punter9
oh wow thank you! I have no knowledge of lua, is there another way you can think of to do this? If no, how steep is the curve for learning lua?
Re: Calculate Hours a device has run
Posted: Monday 22 February 2016 21:48
by niceandeasy
The easiest other way is just to look at your airfilter's switch log history and guess.
LUA is the way to go.
Download & install Notepad++ or use another suitable text editor. (do not torture yourself with microsoft's notepad)
Start with reading up on LUA at the Domoticz wiki. Also read the events part.
Open the three demo-scripts in your domoticz\scripts\lua folder. Read and understand these. Look at the script Siewert posted. Use Google to get explanations on commands.
This script should run okay if you create the uservariable first. First value should be 0.
Re: Calculate Hours a device has run
Posted: Monday 22 February 2016 23:33
by Westcott
Are device on/off times stored in the database?
How else does the log graph get created?
Re: Calculate Hours a device has run
Posted: Tuesday 23 February 2016 9:57
by manwe
What the script does is to check every minute if the device is on.
If this condition is true and the device is on, it increases a user variable by 1.
The second part checks if the user variable is higher than amount of minutes before replacing the filter
I think you could archive the same in a blockly script.
But it someone knows how to get Informations like this from the log I would also be interested

Re: Calculate Hours a device has run
Posted: Tuesday 23 February 2016 20:02
by niceandeasy
Westcott wrote:Are device on/off times stored in the database?
How else does the log graph get created?
It's in the database. The default history is 30 days and that value is configurable in the settings. Domoticz might get sluggish when you would increase this value a lot. That depends on your hardware, the amount of devices and how often you switch them.
As far as I know, Domoticz does not offer this history info by API, so it will require a lot of creativity to get this log info and transfer it into a runtime value. It will be easier to use LUA to log run time in a user variable.
manwe wrote:I think you could archive the same in a blockly script.
How would you increase a user variable in a blockly script?
Re: Calculate Hours a device has run
Posted: Wednesday 24 February 2016 8:37
by jannl
Why not use the lastupdated value? You just need to make sure the filter is not switched on when already on.
Re: Calculate Hours a device has run
Posted: Friday 26 February 2016 15:00
by manwe
niceandeasy wrote:
manwe wrote:I think you could archive the same in a blockly script.
How would you increase a user variable in a blockly script?
You're right. I've never used calculations in blockly before but I didn't expect that you can't increase a number in blockly.
Is that really not possible to do basic calculations?
Before I started with domoticz I've tried some blockly tutorials and there they had lot's of exercises to do some calculations with blockly.
They were Lots of Math Blocks with all kind of calculations.
BUT that was not in Domoticz
