Calculate Hours a device has run
Moderator: leecollings
-
- Posts: 18
- Joined: Thursday 13 August 2015 4:36
- Target OS: Windows
- Domoticz version:
- Contact:
Calculate Hours a device has run
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?
- Siewert308SW
- Posts: 290
- Joined: Monday 29 December 2014 15:47
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Re: Calculate Hours a device has run
There are several ways.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?
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
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
-
- Posts: 18
- Joined: Thursday 13 August 2015 4:36
- Target OS: Windows
- Domoticz version:
- Contact:
Re: Calculate Hours a device has run
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?
-
- Posts: 102
- Joined: Thursday 28 January 2016 22:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: NL
- Contact:
Re: Calculate Hours a device has run
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.
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.
- Westcott
- Posts: 423
- Joined: Tuesday 09 December 2014 17:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: UK - Glos
- Contact:
Re: Calculate Hours a device has run
Are device on/off times stored in the database?
How else does the log graph get created?
How else does the log graph get created?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
-
- Posts: 12
- Joined: Thursday 04 February 2016 14:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Switzerland
- Contact:
Re: Calculate Hours a device has run
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
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

-
- Posts: 102
- Joined: Thursday 28 January 2016 22:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: NL
- Contact:
Re: Calculate Hours a device has run
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.Westcott wrote:Are device on/off times stored in the database?
How else does the log graph get created?
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.
How would you increase a user variable in a blockly script?manwe wrote:I think you could archive the same in a blockly script.
-
- Posts: 673
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: Calculate Hours a device has run
Why not use the lastupdated value? You just need to make sure the filter is not switched on when already on.
-
- Posts: 12
- Joined: Thursday 04 February 2016 14:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Switzerland
- Contact:
Re: Calculate Hours a device has run
niceandeasy wrote:How would you increase a user variable in a blockly script?manwe wrote:I think you could archive the same 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

Who is online
Users browsing this forum: No registered users and 1 guest