Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Locked
NietGiftig
Posts: 121
Joined: Sunday 11 October 2015 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6224
Location: Holland
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by NietGiftig »

The zipfile contains files with an older timestamp

I've done a new git clone, and used that files for a retry

same result
All lua files in the dzvent dir have capital as first letter

Code: Select all

2016-03-23 10:41:07.044 LUA: /usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;./?.lua;/home/pi/domoticz/scripts/lua/?.lua;/home/pi/domoticz/scripts/lua/dzVents/?.lua;/home/pi/domoticz/scripts/lua/scripts/?.lua
2016-03-23 10:41:07.052 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/EventHelpers.lua:3: module 'utils' not found:
no field package.preload['utils']
no file '/usr/local/share/lua/5.2/utils.lua'
no file '/usr/local/share/lua/5.2/utils/init.lua'
no file '/usr/local/lib/lua/5.2/utils.lua'
no file '/usr/local/lib/lua/5.2/utils/init.lua'
no file './utils.lua'
no file '/home/pi/domoticz/scripts/lua/utils.lua'
no file '/home/pi/domoticz/scripts/lua/dzVents/utils.lua'
no file '/home/pi/domoticz/scripts/lua/scripts/utils.lua'
no file '/usr/local/lib/lua/5.2/utils.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './utils.so'
RPI-2 + SSD / ESPEasy Sensors & Switches / Sonoff / RFLink / Action Switches / TP-Link switch / Node-Red / Reacticz
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Crap.. my mistake.. try again?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
NietGiftig
Posts: 121
Joined: Sunday 11 October 2015 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6224
Location: Holland
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by NietGiftig »

He, I thought so
Never mind Holland has no Capital punishment :lol:

Seems to work now
I'll be back :D
RPI-2 + SSD / ESPEasy Sensors & Switches / Sonoff / RFLink / Action Switches / TP-Link switch / Node-Red / Reacticz
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by remb0 »

dannybloe wrote:
remb0 wrote:Lua editor in domoticz is fully compatible with this?
You mean the one that runs in the browser? I don't think so. dzVents has it's own mechanism to figure out which script needs to be called (based on the triggers and active state and timer states). The problem is that the scripts that can be edited inside Domoticz don't live on the file system but in the database. That means that the script dispatchers from dzVents cannot find them and cannot call them. You could pass the domoticz object to these scripts with a bit of effort for easy controlling of the domoticz devices but you would miss some part of the fun.

It would have been nice if the script editor in Domoticz would have stored the scripts on the filesystem as was suggested by a couple of people. That would have made this an awesome combination I guess.
But I Use this editor a lot. and my scripts are still using JSON.lua and other function scripts that are stored on the disk. (and are not editable in domoticz)

not ony handy for adjusting the scripts but they are also included in the backups :)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

remb0 wrote:
But I Use this editor a lot. and my scripts are still using JSON.lua and other function scripts that are stored on the disk. (and are not editable in domoticz)

not ony handy for adjusting the scripts but they are also included in the backups :)
It is not that I don't want it but dzVents takes care of loading and running scripts (not Domoticz!) so it needs to have access to all the other scripts. So you can create one of the dispatcher scripts IN Domoticz and then these dispatchers will bootstrap dzVents but there it ends (I think). dzVents has no way of starting scripts that live inside Domoticz.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by remb0 »

I understand. maybe gizmocuz can play a role in here?
commodore white
Posts: 63
Joined: Sunday 14 July 2013 11:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Ipswich, UK
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by commodore white »

Just a thought and haven't looked at the code. Perhaps I should but I'm just off to bed.

I wondered what might be the practicality of using a CRON type specification for time based event scheduling. It's a bit (a lot) cryptic for some folks but might be handy for others.

Also, a new timer option: atStartup, or somesuch which only gets executed once. Might help with persistence across system restarts.

P
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

commodore white wrote:Just a thought and haven't looked at the code. Perhaps I should but I'm just off to bed.

I wondered what might be the practicality of using a CRON type specification for time based event scheduling. It's a bit (a lot) cryptic for some folks but might be handy for others.

Also, a new timer option: atStartup, or somesuch which only gets executed once. Might help with persistence across system restarts.

P
Yeah, thought about that but too complicated for someone with a simple mind like me. I always have to google a lot before I am able to change a cron setting. But pull requests are welcome (with tests) ;-)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
pj-r
Posts: 140
Joined: Wednesday 17 December 2014 17:30
Target OS: Linux
Domoticz version: V3.8650
Location: Jyväskylä, Finland
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by pj-r »

How about this concept:

Read out the scripts from domoticz (sqlite)database, filter the needed scripts and use "loadstring" lua function to execute it?
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

pj-r wrote:How about this concept:

Read out the scripts from domoticz (sqlite)database, filter the needed scripts and use "loadstring" lua function to execute it?
Well, I guess it can be done without database access but using a json call perhaps. After all, the GUI editor does a similar thing.
It could work but it might require the user to have http libraries for lua installed. And doing json calls to fetch all scripts before dzVents can do its work is very inefficient I think. It will be done quite often. Another way is perhaps to serialize the scripts not only to the database but also to the filesystem. As soon as a script changes in the GUI it will be stored in the db and on the fs. Then you have both ways: in the db for backup and the fs for other tools that work outside the GUI.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

dannybloe wrote:
pj-r wrote:How about this concept:

Read out the scripts from domoticz (sqlite)database, filter the needed scripts and use "loadstring" lua function to execute it?
Well, I guess it can be done without database access but using a json call perhaps. After all, the GUI editor does a similar thing.
It could work but it might require the user to have http libraries for lua installed. And doing json calls to fetch all scripts before dzVents can do its work is very inefficient I think. It will be done quite often. Another way is perhaps to serialize the scripts not only to the database but also to the filesystem. As soon as a script changes in the GUI it will be stored in the db and on the fs. Then you have both ways: in the db for backup and the fs for other tools that work outside the GUI.
I could also make a timer script that extracts the Domoticz scripts and store them on the file system automatically. The only thing is that I don't know when a script was edited in the GUI so you could make a button and use that to trigger dzVents to extract the scripts... could work.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
commodore white
Posts: 63
Joined: Sunday 14 July 2013 11:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Ipswich, UK
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by commodore white »

To make dzVents easier to read/write/document might I suggest you add something like:

Code: Select all

domoticz.timedEvent
and its inverse:

Code: Select all

domoticz.deviceEvent
... such that "domoticz.timedEvent" evaluates to true if the script is running because a scheduled event became due, else false.

Peter
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Good idea.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dakipro
Posts: 49
Joined: Thursday 17 December 2015 22:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Norway
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dakipro »

I just tried to get value of a dimmer with

Code: Select all

kitchenLED = domoticz.devices[68];
print(kitchenLED.level);
but nothing comes back. I can get kitchenLED.state as On. In domoticz I see the device as dimmer with the slider and all. I just downloaded latest version and still same results.
Is this the right way to get the value of the dim light?

I tried to get some info from debug, but didn't find anything very useful (before we had a dump with all devices?)
Is it much time consuming to have some debugging function, f.eks. dumpToLog(domoticz.devices[68]), which could dump all that dzVents know about the device?
Raspberry Pi 2 B - MySensors (dimmers, switches, motion, temperature, lux, humidity sensors)
zWave (220v switches)
various 433 via RFLink
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

dakipro wrote:I just tried to get value of a dimmer with

Code: Select all

kitchenLED = domoticz.devices[68];
print(kitchenLED.level);
but nothing comes back. I can get kitchenLED.state as On. In domoticz I see the device as dimmer with the slider and all. I just downloaded latest version and still same results.
Is this the right way to get the value of the dim light?

I tried to get some info from debug, but didn't find anything very useful (before we had a dump with all devices?)
Is it much time consuming to have some debugging function, f.eks. dumpToLog(domoticz.devices[68]), which could dump all that dzVents know about the device?
Well, the level value is extracted from what Domoticz returns for the value. If you look at otherdevices['...'] or devicechanged[..] then if it returns something like 'Set Level xx%' then dzVents extracts the xx and puts that into the level attribute. So if Domoticz just sends 'On' instead then there's no way to assume it has a dimming level.

So just place a 'print(otherdevices[<name of the device>]' and see what it says. I'm curious too ;-)
You can also look at otherdevices_svalues[..] or if you have dzVents fetch http data, open devices.lua in the scripts folder. That's a full dump of everything Domoticz knows about the device. Only dzVents uses only part of that file. But maybe I should use that for better dimming levels :roll:

There is a dump function btw:

Code: Select all

domoticz.logDevice(kitchenLED)
I didn't document it because somehow Domoticz cannot handle a big log dump. Often it seems to miss log statements so you may have to do it several times to see all the attributes. Kinda weird.
Lemme know what you can find...
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dakipro
Posts: 49
Joined: Thursday 17 December 2015 22:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Norway
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dakipro »

It seems that once you set value from the script, then .level is set fine. But it is not always reliably filled in, so I guess additional if around value is needed
Raspberry Pi 2 B - MySensors (dimmers, switches, motion, temperature, lux, humidity sensors)
zWave (220v switches)
various 433 via RFLink
commodore white
Posts: 63
Joined: Sunday 14 July 2013 11:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Ipswich, UK
Contact:

X10 siren state

Post by commodore white »

The value for X10Siren.bState does not return the correct boolean, its always "false". X10Siren states are "All On" and "All Off".

Peter
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

Re: Some daredevils needed

Post by thorbj »

dannybloe wrote:Today I finished refactoring dzVents. As I said earlier, I wrote around 130 unit tests for the code and I moved most of the dzVents code to a subfolder. I also added some new functionality (from the history.txt):

...

So, my intention is that this will become version 1.0 but before releasing it I ask anyone who dares ;-) to test the master branch (perhaps make a copy of your entire lua folder so you can easily restore it). I have tested it locally here and all seems fine.
I'm testing it now, and for my current setup it seems to work great so far.
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: X10 siren state

Post by dannybloe »

commodore white wrote:The value for X10Siren.bState does not return the correct boolean, its always "false". X10Siren states are "All On" and "All Off".

Peter
I'll add that one too.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
olegdt
Posts: 3
Joined: Thursday 31 March 2016 10:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Kyiv
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by olegdt »

If somebody is interested, I've managed to convert Humidity control script from https://www.domoticz.com/wiki/Humidity_control. Thanks to dannybloe for nice script!

Code: Select all

--[[
 
This script controls the humidity in a typical bathroom setting by detecting
relative rises in humidity in a short period.
Of course it requires a humidity sensor and a binary switch controlling a fan/ventilator.
(there is no provision for variable speed ventilators here!)
 
How it works (assuming the default constants as defined below):
Every 5 minutes a reading is done. Every reading is stored together
with the previous reading and is stored in two user variables (humidityTmin5 and humidityTmin10).
So it has two reading over the past 10 minutes.
It then takes the lowest of the two and compares it with the latest reading and
calculates a delta.
If the delta is 3 or higher (see constants) then the fan will be turned
on, it calculates the target humidity and the 'humidity-decrease program' is started (fanFollowsProgram=1).
From then on, every 5 minutes the current humidity is compared to the
stored target humidity. Basically if that target is reached, the fan is turned off
and the 'program' is ended.
Of course, it is possible that the target is never reached (might start raining outside
or whatever). Then there is a failsafe (FANMAXTIME) after which the ventilator
will be turned off.
 
Also, it will detect if the ventilator is manually switched off during a program
or when it is switched on before the program starts.
 
Along the lines it prints to the log and sends notifications
but of course you can turn that off by removing those lines.
 
--]]


return {
	active = true,                  -- set to true to activate this script
	on = {                      
		['timer'] = 'every minute',  
	},

	execute = function(domoticz) 
	
	-- declare some constants
	-- adjust to your specific situation
	local SAMPLEINTERVAL = 3                 -- time in minutes when a the script logic will happen
	local FANDELTATRIGGER = 5               -- rise in humidity that will trigger the fan
	local FANMAXTIME = 24                   --  maximum amount of sample cycles the fan can be on, 
                                    -- in case we never reach the target humidity
	local TARGETOFFSET = 10                   -- ventilator goes off if target+offset is reached 
                                    -- (maybe it takes too long to reach the true target due to wet towels etc)
	local FANNAME = 'V_Fan'    -- exact device name of the switch turning on/off the ventilator
	local SENSORNAME = 'bathroom'     -- exact device name of the humidity sensor

	local TESTMODE = false	-- when true TESTMODEHUMVAR is used instead of the real sensor
	local TESTMODEHUMVAR = 'testHumidity'   -- fake humidity value, give it a test value in domoticz/uservars
	local PRINTMODE = true					-- when true wil print output to log and send notifications

	if PRINTMODE == true then
		domoticz.log('Fan control', domoticz.LOG_INFO)
	end

	-- get the global variables:
	-- this script runs every minute, humCounter is used to create SAMPLEINTERVAL periods
	local humCounter = domoticz.variables['humCounter'].nValue
	local humidityTmin5 = domoticz.variables['humidityTmin5'].nValue                -- youngest reading
	local humidityTmin10 = domoticz.variables['humidityTmin10'].nValue              -- oldest reading
	local targetFanOffHumidity = domoticz.variables['targetFanOffHumidity'].nValue  -- target humidity
	local fanMaxTimer = domoticz.variables['fanMaxTimer'].nValue
	local fanFollowsProgram = domoticz.variables['fanFollowsProgram'].nValue        -- marker indicating that the 
                                                                        -- decrease program is started

	local target = 0 -- will hold the target humidity when the program starts

	-- get the current humidity value
	if (TESTMODE) then
		current = domoticz.variables[TESTMODEHUMVAR].nValue
	else
		current = domoticz.devices[SENSORNAME].humidity
	end

-- check if the sensor is on or has some weird reading
	if (current == 0 or current == nil) then
		domoticz.log('current is 0 or nil. Skipping this reading', domoticz.LOG_ERROR)
		return 
	end

	if PRINTMODE == true then
        domoticz.log('Current humidity:' .. current, domoticz.LOG_INFO)
		domoticz.log('targetFanOffHumidity:' .. targetFanOffHumidity, domoticz.LOG_INFO)
		domoticz.log('humidityTmin5: ' .. humidityTmin5, domoticz.LOG_INFO)
		domoticz.log('humidityTmin10: ' .. humidityTmin10, domoticz.LOG_INFO)
		domoticz.log('fanMaxTimer: ' .. fanMaxTimer, domoticz.LOG_INFO)
		domoticz.log('humCounter:' .. humCounter, domoticz.LOG_INFO)
		domoticz.log('fanFollowsProgram:' .. fanFollowsProgram, domoticz.LOG_INFO)
	end

-- increase cycle counter
	humCounter = humCounter + 1

	if (humCounter >= SAMPLEINTERVAL) then

			if (humidityTmin5 == 0) then
        -- initialization, assume this is the first time
				humidityTmin5 = current
				humidityTmin10 = current
			end

			humCounter = 0 -- reset the cycle counter

    -- pick the lowest history value to calculate the delta
    -- this also makes sure that two relative small deltas in the past 2*interval minutes are treated as one larger rise
    -- and therefore will still trigger the ventilator
    -- I don't want to use a longer interval instead because I want the ventilator to start as soon as possible
    -- (so rather after 5 minutes instead of after 15 minutes because the mirrors in the bathroom become kinda useless ;-)
			delta = current - math.min(humidityTmin10, humidityTmin5)
		
			if PRINTMODE == true then
				domoticz.log('Delta: ' .. delta, domoticz.LOG_INFO)
			end

    -- pick the lowest history value
			target = math.min(humidityTmin10, humidityTmin5) + TARGETOFFSET

    -- shift the previous measurements
			humidityTmin10 = humidityTmin5
    -- and store the current
			humidityTmin5 = current

		if (domoticz.devices[FANNAME].state=='Off' or (domoticz.devices[FANNAME].state=='On' and fanFollowsProgram==0)) then
        -- either the fan is off or it is on but the decrease program has not started
        -- in that latter case we start the program anyway. This could happen if someone turns on the ventilator
        -- manually because he/she is about to take a shower and doesn't like damp mirrors.
        -- I don't do this because the ventilator removes heat from the bathroom and I want this to happen
        -- as late as possible ;-)

		
		
			if (fanFollowsProgram == 1 and domoticz.devices[FANNAME].state=='Off') then
            -- likely someone turned off the ventilator while the program was running
				fanFollowsProgram = 0
			end

        -- see if we have to turn it on
			if (delta >= FANDELTATRIGGER) then
            -- time to start the fan
				domoticz.devices[FANNAME].setState('On')
				targetFanOffHumidity = target

				if (fanFollowsProgram == 1) then
					domoticz.log('Ventilator was already on but we start the de-humidifying program', domoticz.LOG_INFO)
				end

				fanFollowsProgram = 1

            -- set the safety stop
				fanMaxTimer = FANMAXTIME

				if PRINTMODE == true then
					domoticz.log('Rise in humidity. Turning on the vents. Delta: ' .. delta, domoticz.LOG_INFO)
					domoticz.log('Target humidity for turning the ventilator: ' ..targetFanOffHumidity, domoticz.LOG_INFO)
					domoticz.log('Ventilator is on#The ventilator was activated at humidity level ' .. current .. '#0', domoticz.LOG_INFO)
				end
			end

		else
			if (fanMaxTimer > 0) then
            -- possible that someone started the ventialator manually
				fanMaxTimer = fanMaxTimer - 1
			end


			if (fanFollowsProgram == 1) then -- not manually started

				if (delta >= FANDELTATRIGGER) then
                -- ok, there is another FANDELTATRIGGER rise in humidity
                -- when this happen we reset the fanMaxTimer to a new count down
                -- because we have to ventilate a bit longer due to the extra humidity
					if PRINTMODE == true then
						domoticz.log('Another large increase detected, resetting max timer. Delta: ' .. delta, domoticz.LOG_INFO)
					end
					fanMaxTimer = FANMAXTIME
				end

            -- first see if it can be turned off
				if (current <= targetFanOffHumidity or fanMaxTimer==0) then
					domoticz.devices[FANNAME].setState('Off')

					local msg = ''

					if (fanMaxTimer == 0 and current > targetFanOffHumidity) then
						msg = 'Target not reached but safety time-out is triggered.'
						if PRINTMODE == true then
							domoticz.log(msg, domoticz.LOG_INFO)
						end
					else
						msg = 'Target humidity reached'
						if PRINTMODE == true then
							domoticz.log(msg, domoticz.LOG_INFO)
						end
					end

					if PRINTMODE == true then
						domoticz.log('Turning off the ventilator', domoticz.LOG_INFO)
						msg = msg .. '\nTurning off the ventilator'
					end

					targetFanOffHumidity = 0
					fanMaxTimer = 0
					fanFollowsProgram = 0
                -- reset history in this case.. we start all over
                -- Tmin10 is still in the 'ventilator=On'-zone
					humidityTmin10 = humidityTmin5
					if PRINTMODE == true then
						domoticz.log('Ventilator is off#' .. msg .. '#0', domoticz.LOG_INFO)
					end

				else
                -- we haven't reached the target yet
					if PRINTMODE == true then
						domoticz.log('Humidity delta: ' .. delta, domoticz.LOG_INFO)
					end
				end
			end
    end

	if PRINTMODE == true then
		domoticz.log('New values >>>>>>>>>>>', domoticz.LOG_INFO)
		domoticz.log('humidityTmin5: ' .. humidityTmin5, domoticz.LOG_INFO)
		domoticz.log('humidityTmin10: ' .. humidityTmin10, domoticz.LOG_INFO)
		domoticz.log('fanMaxTimer: ' .. fanMaxTimer, domoticz.LOG_INFO)
		domoticz.log('humCounter:' .. humCounter, domoticz.LOG_INFO)
		domoticz.log('fanFollowsProgram:' .. fanFollowsProgram, domoticz.LOG_INFO)
		domoticz.log('------ target: ' .. targetFanOffHumidity, domoticz.LOG_INFO)
	end

	end

-- save the globals
	domoticz.variables['humCounter'].set(humCounter)
	domoticz.variables['humidityTmin10'].set(humidityTmin10)
	domoticz.variables['humidityTmin5'].set(humidityTmin5)
	domoticz.variables['targetFanOffHumidity'].set(targetFanOffHumidity)
	domoticz.variables['fanMaxTimer'].set(fanMaxTimer)
	domoticz.variables['fanFollowsProgram'].set(fanFollowsProgram)

	end
}
All variables in script declared as local except variable current. Then current is declared as local it's value become 0 in following check:

Code: Select all

-- check if the sensor is on or has some weird reading
	if (current == 0 or current == nil) then
		domoticz.log('current is 0 or nil. Skipping this reading', domoticz.LOG_ERROR)
		return 
	end

Otherwise it's working as it should. Looks very strange for me.
Also I'm not using notifications in the script, so I've changed all print statements to domoticz.log

I wanted to have possibility to override Fan switch from humidity script and for that I have another script:

Code: Select all

--[[

This script controls ventilation logic.

--]]

return {
	active = true,                  -- set to true to activate this script
	on = {
		'Fan',
		'Ventilation_Force',
		'Ventilation_Off',
		'V_Fan',
		'timer'
		},

	execute = function(domoticz, mySwitch) 

	if (domoticz.devices['Fan'].state =='Off' and domoticz.devices['Ventilation_Force'].state =='On' and domoticz.devices['Ventilation_Off'].state =='On' and domoticz.devices['V_Fan'].state =='On') then	domoticz.devices['Fan'].switchOn()
		elseif (domoticz.devices['Fan'].state =='On' and domoticz.devices['Ventilation_Force'].state =='On' and domoticz.devices['Ventilation_Off'].state =='On' and domoticz.devices['V_Fan'].state =='Off') then domoticz.devices['Fan'].switchOff()

		elseif (domoticz.devices['Fan'].state =='On' and domoticz.devices['Ventilation_Force'].state =='On' and domoticz.devices['Ventilation_Off'].state =='Off' and domoticz.devices['V_Fan'].state =='On') then domoticz.devices['Fan'].switchOff()

		elseif (domoticz.devices['Fan'].state =='Off' and domoticz.devices['Ventilation_Force'].state =='Off' and domoticz.devices['Ventilation_Off'].state =='On' and domoticz.devices['V_Fan'].state =='Off') then domoticz.devices['Fan'].switchOn()

		elseif (domoticz.devices['Fan'].state =='On' and domoticz.devices['Ventilation_Force'].state =='Off' and domoticz.devices['Ventilation_Off'].state =='On' and domoticz.devices['V_Fan'].state =='On') then domoticz.devices['Fan'].switchOn()

	end
	if(domoticz.devices['V_Fan'].lastUpdate.minutesAgo>50) and domoticz.devices['V_Fan'].state =='Off' then
         domoticz.devices['V_Fan'].switchOn().for_min(10)
      end
end
}
In this script Fan is switch controlling fan, V_fan - virtual switch from humidity script, Ventilation_Force and Ventilation_Off - switches to force ventilation and to disable it completely.
Also in this script fan is switched on for 10 min every 50 min after last 'On' state to refresh air.
Locked

Who is online

Users browsing this forum: Bing [Bot] and 1 guest