Need assistance for script Mechanical Ventilation  [Solved]

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

Moderator: leecollings

Post Reply
Marcjeok
Posts: 37
Joined: Wednesday 01 November 2017 19:12
Target OS: -
Domoticz version:
Location: Netherlands
Contact:

Need assistance for script Mechanical Ventilation

Post by Marcjeok »

Hi all,

I need some assistance again I'm afraid :oops:

I'm trying to write a dzvents script to control my Mechanical Ventilation (MV). Here for I have two humidity sensors (Philio Technology Corp PH-PAT02-B.eu Multisensor 2in1+). In my current blockly script I can easily compare to the humidity percentage. But with dzvents I get this when I ask to presents its state to the log:
dzVents: Info: 18.8;95;3

In this example, the 95 is the humidity percentage and that's the one I want to use. Then I want to compare it with my other one en let's say that if the bathroom is more then 5% higher, I want to raise the MV.

So my questions are:
1. How can I strip the the dzvents log to only the middle value (in this case 95)?
2. How can I compare with the +5 value?

Thanks again in advance ;)

Not sure if it's needed, but this is the script I have made so far. It's not complete (not by a long shot) en not tested yet

Code: Select all

--[[
SCRIPT DESCRIPTION:
This script turns controls the mechanical ventilation level depending on noise, moister and presence.

DEVICES USED:
Idx 54 = MV-Q1-ST2
Idx 55 = MV-Q2-ST3
Idx 84 = Aanwezigheid
Idx 128 = Mechanische ventilatie stand 2
Idx 129 = Mechanische ventilatie stand 3
Idx 144 = Mechanische ventilatie - stand 3 toegestaan

Idx 175 = Badkamer - TempHum
Idx 169 = SK - TempHum

INFO CREATING SCRIPT:
dzVents: Info: 18.8;95;3        <-- output domoticz.log(domoticz.devices(175).state) / 18.8;95;3 = 18.8 graden;95 procent
domoticz.log(domoticz.devices(175).humidity.state)  <-- no result in log

if (domoticz.devices(175) > '25%') then
    domoticz.log(domoticz.devices(175).state)   <-- no entry in log

]]--

--SET USER INPUT VARIABLES:
local IDQST2 = 54       --only allowd to use in script controlling MV directly
local IDQST3 = 55       --only allowd to use in script controlling MV directly
local DELAY = 10        --set delay in seconds to switch to another ventilation level (safe minimum = 10)

local IDMV2 = 128
local IDMV3 = 129
local IDSILENCE = 144
local IDPR = 84
local IDBATHH = 175
local IDBEDH = 169
local STARTNOISE = 'at 07:00'
local ENDNOISE = 'at 19:15'

return {
	active = true,
	on = {
		devices = {
		    IDMV2,
		    IDMV3,
		    IDSILENCE,
		    IDPRES,
		    IDBATHH,
		    IDBEDH,
		},
	    timer = {
	        STARTNOISE,
	        ENDNOISE,
        },
	},
	execute = function(domoticz, triggeredItem, info)

        --SET VARIABLES:
        local MVDIRECT2 = domoticz.devices(IDQST2)         --only allowd to use in script controlling MV directly
        local MVDIRECT3 = domoticz.devices(IDQST3)         --only allowd to use in script controlling MV directly
        
        local MVLEVEL2 = domoticz.devices(IDMV2)
        local MVLEVEL3 = domoticz.devices(IDMV3)
        local MVSILENCE = domoticz.devices(IDSILENCE)
        local PRESENCE = domoticz.devices(IDPR)
        local BATHHUMIDITY = domoticz.devices(IDBATHH)
        local BEDHUMIDITY = domoticz.devices(IDBEDH)

        -- EXECUTE SCRIPT
        if (triggeredItem.id == IDSILENCE) and (MVSILENCE == "On") and (MVLEVEL3.state == "On") then
            domoticz.log('MV: Too much noise, lower the mechanical ventilation to level 2')
            MVLEVEL2.switchOn()
        elseif (triggeredItem.id == IDPR) and (PRESENCE == "On") and (MVLEVEL2 == "Off") and (MVLEVEL3 == "Off") then
            domoticz.log('MV: There is presence, bring in the fresh air')
            MVLEVEL2.switchOn()
        elseif (triggeredItem.id == STARTNOISE) and (MVSILENCE == "Off") then
            domoticz.log('MV: Noise is allowed')
            MVSILENCE.switchOn()
        elseif (triggeredItem.id == ENDNOISE) and (MVSILENCE == "On") then
            domoticz.log('MV: Noise is not allowed anymore')
            MVSILENCE.switchOff()
        end

        -- EXECUTE SCRIPT CONTROLLING MV DIRECTLY (DO NOT CHANGE) <-- this part has been tested
        if (triggeredItem.id == IDMV2) and (MVLEVEL2.state == "On") then
            domoticz.log('MV: Set mechanical ventilation to level 2 with a '..DELAY..' seconds delay')
            if (MVLEVEL3.state == "On") then MVLEVEL3.switchOff() end
            MVDIRECT2.switchOff()
            MVDIRECT3.switchOff()
            MVDIRECT2.switchOn().afterSec(DELAY)
        elseif (triggeredItem.id == IDMV3) and (MVLEVEL3.state == "On") then
            domoticz.log('MV: Set mechanical ventilation to level 3 with a '..DELAY..' seconds delay')
            if (MVLEVEL2.state == "On") then MVLEVEL2.switchOff() end
            MVDIRECT2.switchOff()
            MVDIRECT3.switchOff()
            MVDIRECT3.switchOn().afterSec(DELAY)
        elseif (MVLEVEL2.state == "Off") and (MVLEVEL3.state == "Off") then
            if (MVDIRECT2.state == "On") or (MVDIRECT3.state == "On") then
                domoticz.log('MV: Set mechanical ventilation to level 1')
                MVDIRECT2.switchOff()
                MVDIRECT3.switchOff()
            end    
        end

end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need assistance for script Mechanical Ventilation  [Solved]

Post by waaren »

Marcjeok wrote: Thursday 10 October 2019 15:56 1. How can I strip the the dzvents log to only the middle value (in this case 95)?
2. How can I compare with the +5 value?
Can you have a look at this and try ?

Code: Select all

--[[
SCRIPT DESCRIPTION:
This script turns controls the mechanical ventilation level depending on noise, moister and presence.

DEVICES USED:
Idx 54 = MV-Q1-ST2
Idx 55 = MV-Q2-ST3
Idx 84 = Aanwezigheid
Idx 128 = Mechanische ventilatie stand 2
Idx 129 = Mechanische ventilatie stand 3
Idx 144 = Mechanische ventilatie - stand 3 toegestaan

Idx 175 = Badkamer - TempHum
Idx 169 = SK - TempHum

INFO CREATING SCRIPT:
dzVents: Info: 18.8;95;3        <-- output domoticz.log(domoticz.devices(175).state) / 18.8;95;3 = 18.8 graden;95 procent
domoticz.log(domoticz.devices(175).humidity.state)  <-- no result in log

if (domoticz.devices(175) > '25%') then
    domoticz.log(domoticz.devices(175).state)   <-- no entry in log

]]--

--SET USER INPUT VARIABLES:
local IDQST2 = 54       --only allowd to use in script controlling MV directly
local IDQST3 = 55       --only allowd to use in script controlling MV directly
local DELAY = 10        --set delay in seconds to switch to another ventilation level (safe minimum = 10)

local IDMV2 = 128
local IDMV3 = 129
local IDSILENCE = 144
local IDPR = 84
local IDBATHH = 175
local IDBEDH = 169
local STARTNOISE = 'at 07:00'
local ENDNOISE = 'at 19:15'

return {
    active = true,
    on = {
        devices = {
            IDMV2,
            IDMV3,
            IDSILENCE,
            IDPRES,
            IDBATHH,
            IDBEDH,
        },
        timer = {
            STARTNOISE,
            ENDNOISE,
        },
    },
    execute = function(domoticz, triggeredItem, info)

        --SET VARIABLES:
        local MVDIRECT2 = domoticz.devices(IDQST2)         --only allowd to use in script controlling MV directly
        local MVDIRECT3 = domoticz.devices(IDQST3)         --only allowd to use in script controlling MV directly
        
        local MVLEVEL2 = domoticz.devices(IDMV2)
        local MVLEVEL3 = domoticz.devices(IDMV3)
        local MVSILENCE = domoticz.devices(IDSILENCE)
        local PRESENCE = domoticz.devices(IDPR)
        local BATHHUMIDITY = domoticz.devices(IDBATHH).humidity
        local BEDHUMIDITY = domoticz.devices(IDBEDH).humidity

        -- EXECUTE SCRIPT
        if (triggeredItem.id == IDSILENCE) and (MVSILENCE.state == "On") and (MVLEVEL3.state == "On") then
            domoticz.log('MV: Too much noise, lower the mechanical ventilation to level 2')
            MVLEVEL2.switchOn()
        elseif (triggeredItem.id == IDPR) and (PRESENCE.state == "On") and (MVLEVEL2.state == "Off") and (MVLEVEL3.state == "Off") then
            domoticz.log('MV: There is presence, bring in the fresh air')
            MVLEVEL2.switchOn()
        elseif (triggeredItem.id == STARTNOISE) and (MVSILENCE.state == "Off") then
            domoticz.log('MV: Noise is allowed')
            MVSILENCE.switchOn()
        elseif (triggeredItem.id == ENDNOISE) and (MVSILENCE.state == "On") then
            domoticz.log('MV: Noise is not allowed anymore')
            MVSILENCE.switchOff()
        end


        -- Check and compare humidities
        if BATHHUMIDITY > ( BEDHUMIDITY + 5 ) then 
            domoticz.log('MV: Delta humidity > 5 ')
        else
            domoticz.log('MV: Delta humidity > 5 ')
        end
        
        -- EXECUTE SCRIPT CONTROLLING MV DIRECTLY (DO NOT CHANGE) <-- this part has been tested
        if (triggeredItem.id == IDMV2) and (MVLEVEL2.state == "On") then
            domoticz.log('MV: Set mechanical ventilation to level 2 with a '..DELAY..' seconds delay')
            if (MVLEVEL3.state == "On") then MVLEVEL3.switchOff() end
            MVDIRECT2.switchOff()
            MVDIRECT3.switchOff()
            MVDIRECT2.switchOn().afterSec(DELAY)
        elseif (triggeredItem.id == IDMV3) and (MVLEVEL3.state == "On") then
            domoticz.log('MV: Set mechanical ventilation to level 3 with a '..DELAY..' seconds delay')
            if (MVLEVEL2.state == "On") then MVLEVEL2.switchOff() end
            MVDIRECT2.switchOff()
            MVDIRECT3.switchOff()
            MVDIRECT3.switchOn().afterSec(DELAY)
        elseif (MVLEVEL2.state == "Off") and (MVLEVEL3.state == "Off") then
            if (MVDIRECT2.state == "On") or (MVDIRECT3.state == "On") then
                domoticz.log('MV: Set mechanical ventilation to level 1')
                MVDIRECT2.switchOff()
                MVDIRECT3.switchOff()
            end    
        end

end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Marcjeok
Posts: 37
Joined: Wednesday 01 November 2017 19:12
Target OS: -
Domoticz version:
Location: Netherlands
Contact:

Re: Need assistance for script Mechanical Ventilation

Post by Marcjeok »

Thanks again! It seems to work. I will continue working on this script and will come back here if it's finished or when I need more assistance 8-).
Marcjeok
Posts: 37
Joined: Wednesday 01 November 2017 19:12
Target OS: -
Domoticz version:
Location: Netherlands
Contact:

Re: Need assistance for script Mechanical Ventilation

Post by Marcjeok »

My script is still under construction, but it looks already promising 8-)
I promised to share my script, so hereby my script so far. I will probably make some more (small) changes in the future and will share it again when it's final.

Code: Select all

--[[
SCRIPT DESCRIPTION:
This script turns controls the mechanical ventilation level depending on humidity, noise, presence and time.
The MV level will be set to level 1, 2 or 3.

DEVICES USED:
Idx 8 = Weer - Barometer
Idx 54 = MV-Q1-ST2
Idx 55 = MV-Q2-ST3
Idx 84 = Aanwezigheid
Idx 128 = Mechanische ventilatie stand 2
Idx 129 = Mechanische ventilatie stand 3
Idx 144 = Mechanische ventilatie - stand 3 toegestaan
Idx 169 = SK - TempHum
Idx 175 = Badkamer - TempHum
]]--

--SET USER INPUT VARIABLES:
local IDQST2 = 54           --only allowd to use in script controlling MV directly
local IDQST3 = 55           --only allowd to use in script controlling MV directly
local DELAY = 10            --set delay in seconds to switch to another ventilation level (safe minimum = 10)

local IDMV2 = 128
local IDMV3 = 129
local IDSILENCE = 144
local IDPR = 84
local IDBATHH = 175
local IDBEDH = 169
local IDOUTDOOR = 8
local STARTNOISE = 'at 07:00'
local ENDNOISE = 'at 19:15'
local DIFFERENCE = 7        --allowed difference between bathroom and bedroom
local LOGGINGON = "Yes"     -- turn logging on or off (values: On = "Yes", Off = "No")

return {
    active = true,
    on = {
        devices = {
            IDMV2,
            IDMV3,
            IDSILENCE,
            IDPRES,
            IDBATHH,
            IDBEDH,
        },
        timer = {
            STARTNOISE,
            ENDNOISE,
        },
    },
    execute = function(domoticz, triggeredItem, info)

        --SET VARIABLES:
        local MVDIRECT2 = domoticz.devices(IDQST2)         --only allowd to use in script controlling MV directly
        local MVDIRECT3 = domoticz.devices(IDQST3)         --only allowd to use in script controlling MV directly
        
        local MVLEVEL2 = domoticz.devices(IDMV2)
        local MVLEVEL3 = domoticz.devices(IDMV3)
        local MVSILENCE = domoticz.devices(IDSILENCE)
        local PRESENCE = domoticz.devices(IDPR)
        local BATHHUMIDITY = domoticz.devices(IDBATHH).humidity
        local BEDHUMIDITY = domoticz.devices(IDBEDH).humidity
        local OUTDOORHUMIDITY = domoticz.devices(IDOUTDOOR).humidity
        local LOGGING = "\n++++++++++++++++++++\n".."SCRIPT MECHANICAL VENTILATION:".."\n...................."

        -- EXECUTE SCRIPT: SET MV LEVEL (CHECK AND COMPARE HUMIDITIES)
        LOGGING = LOGGING .."\n".."SET LEVEL:"
        LOGGING = LOGGING .."\n".."MV-status: Bathroom: "..BATHHUMIDITY.." vs. Bedroom: "..BEDHUMIDITY.." (Outside: "..OUTDOORHUMIDITY..")"
        if BATHHUMIDITY > (BEDHUMIDITY + DIFFERENCE) then 
            LOGGING = LOGGING .."\n".."MV-program: Humidity in bathroom is too high"
            if (MVSILENCE.state == 'On') and (MVLEVEL3.state == 'Off') then
                LOGGING = LOGGING .."\n".."MV-changelevel: Noise OK, change MV to level 3"
                MVLEVEL3.switchOn()
            elseif (MVSILENCE.state == 'Off') and (MVLEVEL2.state == 'Off') then
                MVLEVEL2.switchOn()
                LOGGING = LOGGING .."\n".."MV-changelevel: No noise, change MV to level 2"
            else
                LOGGING = LOGGING .."\n".."No action needed"
            end    
        else
            LOGGING = LOGGING .."\n".."MV-program: Humidity in bathroom is normal"
            if (PRESENCE.state == 'On') then
                LOGGING = LOGGING .."\n".."MV-subprogram: Presence: Yes "
                if domoticz.time.matchesRule('at 06:15-23:30') then
                    LOGGING = LOGGING .." -- Day time active:"
                    if (MVLEVEL3.state == 'On') then
                        LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 3 to level 2"
                        MVLEVEL2.switchOn()
                    elseif (MVLEVEL2.state == 'Off') and (MVLEVEL3.state == 'Off') then
                        LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 1 to level 2"
                        MVLEVEL2.switchOn()
                    else
                        LOGGING = LOGGING .."\n".."No action needed"
                    end
                else
                    LOGGING = LOGGING .." --Night time active"
                    if (MVLEVEL2.state == 'On') then
                        LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 2 to level 1"
                        MVLEVEL2.switchOff()
                    elseif (MVLEVEL3.state == 'On') then
                        LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 3 to level 1"
                        MVLEVEL3.switchOff()
                    else
                        LOGGING = LOGGING .."\n".."No action needed"
                    end
                end
            elseif (PRESENCE.state == 'Off') then
                LOGGING = LOGGING .."\n".."MV-subprogram: Presence: No"
                if (MVLEVEL2.state == 'On') then
                    LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 2 to level 1"
                    MVLEVEL2.switchOff()
                elseif (MVLEVEL3.state == 'On') then
                    LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 3 to level 1"
                    MVLEVEL3.switchOff()
                else
                    LOGGING = LOGGING .."\n".."No action needed"
                end
            end
        end

        -- EXECUTE SCRIPT: TURN MVSILENCE ON/OFF
        LOGGING = LOGGING .."\n".."\n".."SET MVSILENCE:"
        if domoticz.time.matchesRule(STARTNOISE) and (MVSILENCE.state == 'Off') then
            LOGGING = LOGGING .."\n".."Noise is allowed from now "..STARTNOISE
            MVSILENCE.switchOn()
        elseif domoticz.time.matchesRule(ENDNOISE) and (MVSILENCE.state == 'On') then
            LOGGING = LOGGING .."\n".."Noise is not allowed anymore from now "..ENDNOISE
            MVSILENCE.switchOff()
        else
            LOGGING = LOGGING .."\n".."No action needed"
        end
        
        -- EXECUTE SCRIPT: CONTROLLING MV DIRECTLY (DO NOT CHANGE) <-- this part has been tested
        LOGGING = LOGGING .."\n".."\n".."SET MV DIRECTLY:"
        if (triggeredItem.id == IDMV2) and (MVLEVEL2.state == "On") then
            LOGGING = LOGGING .."\n".."MV-directly: Change to level 2 with a "..DELAY.."seconds delay"
            if (MVLEVEL3.state == "On") then MVLEVEL3.switchOff() end
            MVDIRECT2.switchOff()
            MVDIRECT3.switchOff()
            MVDIRECT2.switchOn().afterSec(DELAY)
        elseif (triggeredItem.id == IDMV3) and (MVLEVEL3.state == "On") then
            LOGGING = LOGGING .."\n".."MV-directly: Change to level 3 with a "..DELAY.."seconds delay"
            if (MVLEVEL2.state == "On") then MVLEVEL2.switchOff() end
            MVDIRECT2.switchOff()
            MVDIRECT3.switchOff()
            MVDIRECT3.switchOn().afterSec(DELAY)
        elseif (MVLEVEL2.state == "Off") and (MVLEVEL3.state == "Off") then
            if (MVDIRECT2.state == "On") or (MVDIRECT3.state == "On") then
                LOGGING = LOGGING .."\n".."MV-directly: Change to level 1"
                MVDIRECT2.switchOff()
                MVDIRECT3.switchOff()
            end
        else
            LOGGING = LOGGING .."\n".."No action needed"
        end
    
        LOGGING = LOGGING .."\n++++++++++++++++++++"
        
        --LOGGING:
        if (LOGGINGON == "Yes") then
            domoticz.log(LOGGING)
        end
end
}
Joep123
Posts: 56
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Need assistance for script Mechanical Ventilation

Post by Joep123 »

What kind of devices are:

Idx 54 = MV-Q1-ST2
Idx 55 = MV-Q2-ST3

?
Marcjeok
Posts: 37
Joined: Wednesday 01 November 2017 19:12
Target OS: -
Domoticz version:
Location: Netherlands
Contact:

Re: Need assistance for script Mechanical Ventilation

Post by Marcjeok »

Joep123 wrote: Saturday 12 October 2019 21:33 What kind of devices are:

Idx 54 = MV-Q1-ST2
Idx 55 = MV-Q2-ST3
It's one device (double light switch):
Qubino (Goap) ZMNHBDx Flush 2 Relays+

This device has been attached to my Duco MV (DucoBox Silent).
Marcjeok
Posts: 37
Joined: Wednesday 01 November 2017 19:12
Target OS: -
Domoticz version:
Location: Netherlands
Contact:

Re: Need assistance for script Mechanical Ventilation

Post by Marcjeok »

As promised, hereby my final script. I've made several small changes and fixed a bug.

Code: Select all

--[[
SCRIPT DESCRIPTION:
This script turns controls the mechanical ventilation level depending on humidity, noise, presence and time.
The MV level will be set to level 1, 2 or 3.

DEVICES USED:
Idx 8 = Weer - Barometer
Idx 54 = MV-Q1-ST2
Idx 55 = MV-Q2-ST3
Idx 84 = Aanwezigheid
Idx 128 = Mechanische ventilatie stand 2
Idx 129 = Mechanische ventilatie stand 3
Idx 144 = Mechanische ventilatie - stand 3 toegestaan
Idx 169 = SK - TempHum
Idx 175 = Badkamer - TempHum
]]--

--SET USER INPUT VARIABLES:
local IDQST2 = 54           --only allowd to use in script controlling MV directly
local IDQST3 = 55           --only allowd to use in script controlling MV directly
local DELAY = 10            --set delay in seconds to switch to another ventilation level (safe minimum = 10)

local IDMV2 = 128
local IDMV3 = 129
local IDSILENCE = 144
local IDPR = 84
local IDBATHH = 175
local IDBEDH = 169
local IDOUTDOOR = 8
local STARTNOISE = 'at 06:55'
local ENDNOISE = 'at 19:15'
local DIFFERENCE = 7        --allowed difference between bathroom and bedroom
local LOGGINGON = "Yes"     -- turn logging on or off (values: On = "Yes", Off = "No")

return {
    active = true,
    on = {
        devices = {
            IDMV2,
            IDMV3,
            IDSILENCE,
            IDPR,
            IDBATHH,
            IDBEDH,
        },
        timer = {
            STARTNOISE,
            ENDNOISE,
        },
    },
    execute = function(domoticz, triggeredItem, info)

        --SET VARIABLES:
        local MVDIRECT2 = domoticz.devices(IDQST2)         --only allowd to use in script controlling MV directly
        local MVDIRECT3 = domoticz.devices(IDQST3)         --only allowd to use in script controlling MV directly
        
        local MVLEVEL2 = domoticz.devices(IDMV2)
        local MVLEVEL3 = domoticz.devices(IDMV3)
        local MVSILENCE = domoticz.devices(IDSILENCE)
        local PRESENCE = domoticz.devices(IDPR)
        local BATHHUMIDITY = domoticz.devices(IDBATHH).humidity
        local BEDHUMIDITY = domoticz.devices(IDBEDH).humidity
        local OUTDOORHUMIDITY = domoticz.devices(IDOUTDOOR).humidity
        local LOGGING = "\n++++++++++++++++++++\n".."SCRIPT MECHANICAL VENTILATION:".."\n...................."

        -- EXECUTE SCRIPT: SET MV LEVEL (CHECK AND COMPARE HUMIDITIES)
        LOGGING = LOGGING .."\n".."SET LEVEL:"
        LOGGING = LOGGING .."\n".."MV-status: Bathroom: "..BATHHUMIDITY.." vs. Bedroom: "..BEDHUMIDITY.." (Outside: "..OUTDOORHUMIDITY..")"
        LOGGING = LOGGING .."\n".."Allowed difference: "..DIFFERENCE
        if BATHHUMIDITY > (BEDHUMIDITY + DIFFERENCE) then 
            LOGGING = LOGGING .."\n".."MV-program: Humidity bathroom too high"
            if (MVSILENCE.state == 'On') and (MVLEVEL3.state == 'Off') then
                LOGGING = LOGGING .."\n".."MV-changelevel: Noise OK, change MV to level 3"
                MVLEVEL3.switchOn()
            elseif (MVSILENCE.state == 'Off') and (MVLEVEL2.state == 'Off') then
                MVLEVEL2.switchOn()
                LOGGING = LOGGING .."\n".."MV-changelevel: No noise allowed, change MV to level 2"
            else
                LOGGING = LOGGING .."\n".."No action needed ".." (MV-lvl 2 = "..MVLEVEL2.state..", MV-lvl 3 = "..MVLEVEL3.state..")"
            end    
        else
            LOGGING = LOGGING .."\n".."MV-program: Humidity bathroom normal"
            if (PRESENCE.state == 'On') then
                LOGGING = LOGGING .."\n".."MV-subprogram: Presence: Yes "
                if domoticz.time.matchesRule('at 06:15-23:30') then
                    LOGGING = LOGGING .." -- Day time active:"
                    if (MVLEVEL3.state == 'On') then
                        LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 3 to level 2"
                        MVLEVEL2.switchOn()
                    elseif (MVLEVEL2.state == 'Off') and (MVLEVEL3.state == 'Off') then
                        LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 1 to level 2"
                        MVLEVEL2.switchOn()
                    else
                        LOGGING = LOGGING .."\n".."No action needed".." (MV-lvl 2 = "..MVLEVEL2.state..", MV-lvl 3 = "..MVLEVEL3.state..")"
                    end
                else
                    LOGGING = LOGGING .." --Night time active"
                    if (MVLEVEL2.state == 'On') then
                        LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 2 to level 1"
                        MVLEVEL2.switchOff()
                    elseif (MVLEVEL3.state == 'On') then
                        LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 3 to level 1"
                        MVLEVEL3.switchOff()
                    else
                        LOGGING = LOGGING .."\n".."No action needed".." (MV-lvl 2 = "..MVLEVEL2.state..", MV-lvl 3 = "..MVLEVEL3.state..")"
                    end
                end
            elseif (PRESENCE.state == 'Off') then
                LOGGING = LOGGING .."\n".."MV-subprogram: Presence: No"
                if (MVLEVEL2.state == 'On') then
                    LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 2 to level 1"
                    MVLEVEL2.switchOff()
                elseif (MVLEVEL3.state == 'On') then
                    LOGGING = LOGGING .."\n".."MV-changelevel: Change MV from level 3 to level 1"
                    MVLEVEL3.switchOff()
                else
                    LOGGING = LOGGING .."\n".."No action needed".." (MV-lvl 2 = "..MVLEVEL2.state..", MV-lvl 3 = "..MVLEVEL3.state..")"
                end
            end
        end

        -- EXECUTE SCRIPT: TURN MVSILENCE ON/OFF
        LOGGING = LOGGING .."\n".."\n".."SET MVSILENCE:"
        if domoticz.time.matchesRule(STARTNOISE) and (MVSILENCE.state == 'Off') then
            LOGGING = LOGGING .."\n".."Noise is allowed from now "..STARTNOISE
            MVSILENCE.switchOn()
        elseif domoticz.time.matchesRule(ENDNOISE) and (MVSILENCE.state == 'On') then
            LOGGING = LOGGING .."\n".."No Noise allowed anymore "..ENDNOISE
            MVSILENCE.switchOff()
        else
            LOGGING = LOGGING .."\n".."No action needed".." (noise allowed = "..MVSILENCE.state..")"
        end
        
        -- EXECUTE SCRIPT: CONTROLLING MV DIRECTLY (DO NOT CHANGE) <-- this part has been tested
        LOGGING = LOGGING .."\n".."\n".."SET MV DIRECTLY:"
        if (triggeredItem.id == IDMV2) and (MVLEVEL2.state == "On") then
            LOGGING = LOGGING .."\n".."MV-directly: Change to level 2 with a "..DELAY.." seconds delay"
            if (MVLEVEL3.state == "On") then MVLEVEL3.switchOff() end
            MVDIRECT2.switchOff()
            MVDIRECT3.switchOff()
            MVDIRECT2.switchOn().afterSec(DELAY)
        elseif (triggeredItem.id == IDMV3) and (MVLEVEL3.state == "On") then
            LOGGING = LOGGING .."\n".."MV-directly: Change to level 3 with a "..DELAY.." seconds delay"
            if (MVLEVEL2.state == "On") then MVLEVEL2.switchOff() end
            MVDIRECT2.switchOff()
            MVDIRECT3.switchOff()
            MVDIRECT3.switchOn().afterSec(DELAY)
        elseif (MVLEVEL2.state == "Off") and (MVLEVEL3.state == "Off") then
            LOGGING = LOGGING .."\n".."MV-directly: Change to level 1"
            if (MVDIRECT2.state == "On") or (MVDIRECT3.state == "On") then
                MVDIRECT2.switchOff()
                MVDIRECT3.switchOff()
            end
        else
            LOGGING = LOGGING .."\n".."No action needed"
        end
    
        LOGGING = LOGGING .."\n++++++++++++++++++++"
        
        --LOGGING:
        if (LOGGINGON == "Yes") then
            domoticz.log(LOGGING)
        end
end
}
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Need assistance for script Mechanical Ventilation

Post by freijn »

Without looking at your script.... Are you aware there is a Bathroom script already ?

I am running it for over a year now and love it. It handles all situations and changes pretty well.

Frank
Marcjeok
Posts: 37
Joined: Wednesday 01 November 2017 19:12
Target OS: -
Domoticz version:
Location: Netherlands
Contact:

Re: Need assistance for script Mechanical Ventilation

Post by Marcjeok »

freijn wrote: Thursday 17 October 2019 8:41 Without looking at your script.... Are you aware there is a Bathroom script already ?

I am running it for over a year now and love it. It handles all situations and changes pretty well.

Frank
I've seen multiple bathroom scripts, but the scripts I've seen didn't completely fulfil my personal needs. That's why I made my own. Because I needed some help with making this script (I'm a noob at scripting :oops:), I think it's useful for others if they can see the question and a working end result. At least I like to see working end results, so I can borrow commands that works. So for everybody who likes that as much as I do, I share my final script. It's not intended to be an example or that sort of things, because other people can do that a lot better then me, because they are really good in scripting (heads off to them :D).
Last edited by Marcjeok on Thursday 17 October 2019 15:27, edited 1 time in total.
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Need assistance for script Mechanical Ventilation

Post by freijn »

Ok Marc, understood.

What I do love in my script is the ability to adapt when the next shower is going to happen in the "cooldown" period of the previous shower.

i.e. there is some time between the showers and huminity has not come to the starting level. The next shower starts and huminity goes up again.
The script takes the first starting value as a target and not the value at the start of the second shower. ( Me like :-) )
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest