Switch on Ventilation Toilet.  [Solved]

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

Moderator: leecollings

Post Reply
Markiey99
Posts: 8
Joined: Thursday 27 February 2020 20:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Switch on Ventilation Toilet.

Post by Markiey99 »

Hello guys,

I have the following problem, I am unable to turn on the fan in the toilet when the lamp in the toilet is on for more than 2 minutes.

I now use a blockly where I can only set the fan to turn on after x number of seconds, but if the lamp is on for less than the set number of seconds, the fan will still turn on.

Now I have seen that with a LUA script you can control it better with the 'last seen' status of the lamp. But unfortunately I can't get this done .. :(

example script which I am currently using but does not work. :

Code: Select all

t1 = os.time ()
s = otherdevices_lastupdate ['WC']
- returns a date time like 2013-07-11 17:23:12

year = string.sub (s, 1, 4)
month = string.sub (s, 6, 7)
day = string.sub (s, 9, 10)
hour = string.sub (s, 12, 13)
minutes = string.sub (s, 15, 16)
seconds = string.sub (s, 18, 19)

commandArray = {}

t2 = os.time {year = year, month = month, day = day, hour = hour, min = minutes, sec = seconds}
difference = (os.difftime (t1, t2))
if (otherdevices ['WC'] == 'On' and difference> 120 and difference <130) then
   commandArray ['ventilation'] = 'On'
end
 
return commandArray
Kind regards,
Mark
User avatar
Treve
Posts: 107
Joined: Thursday 05 November 2015 10:37
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.11474
Location: Rotterdam, NL
Contact:

Re: Switch on Ventilation Toilet.

Post by Treve »

if I understand correctly, should the fan turn on if the lamp is on for more than 2 minutes and turn off when the lamp goes out again?
- RFXtrx433E,
- AEON Labs ZW090 Z-Stick Gen5 EU
- Hue v2.1
- Raspberry Pi 3 Model B, Raspbian Stretch Full on USB-Stick.
- Domoticz 4.11474
Devices: KaKu, Z-Wave, Hue.

for testing:
Raspberry 4, 2GB, SSD
Domoticz 2022.1
Ikea Hub, Fyrtur curtain
Markiey99
Posts: 8
Joined: Thursday 27 February 2020 20:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch on Ventilation Toilet.

Post by Markiey99 »

Thanks for your reply :)

If the light is on longer than 2min, the fan should turn on. And if the light is shorter than 2min on the fan does not turn on. When the light goes out, the fan should remain on when it is turned on.
User avatar
Treve
Posts: 107
Joined: Thursday 05 November 2015 10:37
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.11474
Location: Rotterdam, NL
Contact:

Re: Switch on Ventilation Toilet.

Post by Treve »

Markiey99 wrote: Tuesday 06 October 2020 16:02 Thanks for your reply :)

If the light is on longer than 2min, the fan should turn on. And if the light is shorter than 2min on the fan does not turn on.
This is easely done by a Blockly

When the light goes out, the fan should remain on when it is turned on.
When or what switch the Fan off?
- RFXtrx433E,
- AEON Labs ZW090 Z-Stick Gen5 EU
- Hue v2.1
- Raspberry Pi 3 Model B, Raspbian Stretch Full on USB-Stick.
- Domoticz 4.11474
Devices: KaKu, Z-Wave, Hue.

for testing:
Raspberry 4, 2GB, SSD
Domoticz 2022.1
Ikea Hub, Fyrtur curtain
Markiey99
Posts: 8
Joined: Thursday 27 February 2020 20:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch on Ventilation Toilet.

Post by Markiey99 »

With blockly it is not possible, I have already tried everything in that. Blockly can't handle the option if the light is on shorter than 2min

The fan goes automaticly off.
User avatar
Treve
Posts: 107
Joined: Thursday 05 November 2015 10:37
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.11474
Location: Rotterdam, NL
Contact:

Re: Switch on Ventilation Toilet.

Post by Treve »

B1.jpg
B1.jpg (25.84 KiB) Viewed 1515 times
Set the delay of 2 minutes
B2.jpg
B2.jpg (24.94 KiB) Viewed 1515 times
The second set (Ventilator = off) stops the timer of the Fan

This is working at my Domoticz 2020.2

Evert
- RFXtrx433E,
- AEON Labs ZW090 Z-Stick Gen5 EU
- Hue v2.1
- Raspberry Pi 3 Model B, Raspbian Stretch Full on USB-Stick.
- Domoticz 4.11474
Devices: KaKu, Z-Wave, Hue.

for testing:
Raspberry 4, 2GB, SSD
Domoticz 2022.1
Ikea Hub, Fyrtur curtain
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch on Ventilation Toilet.  [Solved]

Post by waaren »

Markiey99 wrote: Tuesday 06 October 2020 17:02 With blockly it is not possible, I have already tried everything in that. Blockly can't handle the option if the light is on shorter than 2min
This dzVents script should do it

______________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is 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."
______________________________________________________________________________________________________________________________

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'WC', -- WC light
        }
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all OK
        marker = 'Fan control',
    },

    execute = function(dz, item)
        local fan = dz.devices('ventilation')
        
        if item.active then
            fan.switchOn().afterSec(120)
        else
            fan.cancelQueuedCommands()
            -- fan.switchOff().afterSec(5) -- uncomment if fan auto off takes too long
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch on Ventilation Toilet.

Post by waaren »

Treve wrote: Tuesday 06 October 2020 17:30 This is working at my Domoticz 2020.2
Nice find!

Reason why I prefer to do this with a dzVents script is that this kind of Blockly script is executed on every device update on the system. On my production system that is on average > 100 times/minute
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
Treve
Posts: 107
Joined: Thursday 05 November 2015 10:37
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.11474
Location: Rotterdam, NL
Contact:

Re: Switch on Ventilation Toilet.

Post by Treve »

I think dzvents is a better solution but I’m not a programmer and try to find solutions at the blockly front. Most of the times I find a solution whether or not supported with variables.
- RFXtrx433E,
- AEON Labs ZW090 Z-Stick Gen5 EU
- Hue v2.1
- Raspberry Pi 3 Model B, Raspbian Stretch Full on USB-Stick.
- Domoticz 4.11474
Devices: KaKu, Z-Wave, Hue.

for testing:
Raspberry 4, 2GB, SSD
Domoticz 2022.1
Ikea Hub, Fyrtur curtain
Markiey99
Posts: 8
Joined: Thursday 27 February 2020 20:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch on Ventilation Toilet.

Post by Markiey99 »

waaren wrote: Tuesday 06 October 2020 17:42
Markiey99 wrote: Tuesday 06 October 2020 17:02 With blockly it is not possible, I have already tried everything in that. Blockly can't handle the option if the light is on shorter than 2min
This dzVents script should do it

______________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is 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."
______________________________________________________________________________________________________________________________

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'WC', -- WC light
        }
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all OK
        marker = 'Fan control',
    },

    execute = function(dz, item)
        local fan = dz.devices('ventilation')
        
        if item.active then
            fan.switchOn().afterSec(120)
        else
            fan.cancelQueuedCommands()
            -- fan.switchOff().afterSec(5) -- uncomment if fan auto off takes too long
        end
    end
}


Thank you! All working great now!
Markiey99
Posts: 8
Joined: Thursday 27 February 2020 20:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch on Ventilation Toilet.

Post by Markiey99 »

Treve wrote: Tuesday 06 October 2020 17:57 I think dzvents is a better solution but I’m not a programmer and try to find solutions at the blockly front. Most of the times I find a solution whether or not supported with variables.
Thank you too, I've been trying to do exactly the same thing with blockly because I can't program either. But with the quick help on this forum it is still possible to use a programmed script :)
User avatar
Treve
Posts: 107
Joined: Thursday 05 November 2015 10:37
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.11474
Location: Rotterdam, NL
Contact:

Re: Switch on Ventilation Toilet.

Post by Treve »

Markiey99 wrote: Thank you! All working great now!
Witch solution did you choose?
- RFXtrx433E,
- AEON Labs ZW090 Z-Stick Gen5 EU
- Hue v2.1
- Raspberry Pi 3 Model B, Raspbian Stretch Full on USB-Stick.
- Domoticz 4.11474
Devices: KaKu, Z-Wave, Hue.

for testing:
Raspberry 4, 2GB, SSD
Domoticz 2022.1
Ikea Hub, Fyrtur curtain
User avatar
Treve
Posts: 107
Joined: Thursday 05 November 2015 10:37
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.11474
Location: Rotterdam, NL
Contact:

Switch on Ventilation Toilet.

Post by Treve »

Markiey99 wrote:
Treve wrote: Tuesday 06 October 2020 17:57 I think dzvents is a better solution but I’m not a programmer and try to find solutions at the blockly front. Most of the times I find a solution whether or not supported with variables.
Thank you too, I've been trying to do exactly the same thing with blockly because I can't program either. But with the quick help on this forum it is still possible to use a programmed script :)
I can implement the most scripts, if you can read, you can make use of knowledge of programmers.
I struggle now how to login as Root to save the backup’s, I tried a lot without succes. I must read a lot more on the Forum I think.
- RFXtrx433E,
- AEON Labs ZW090 Z-Stick Gen5 EU
- Hue v2.1
- Raspberry Pi 3 Model B, Raspbian Stretch Full on USB-Stick.
- Domoticz 4.11474
Devices: KaKu, Z-Wave, Hue.

for testing:
Raspberry 4, 2GB, SSD
Domoticz 2022.1
Ikea Hub, Fyrtur curtain
Markiey99
Posts: 8
Joined: Thursday 27 February 2020 20:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch on Ventilation Toilet.

Post by Markiey99 »

Treve wrote: Wednesday 07 October 2020 15:32
Markiey99 wrote: Thank you! All working great now!
Witch solution did you choose?
dzVentz
Markiey99
Posts: 8
Joined: Thursday 27 February 2020 20:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Switch on Ventilation Toilet.

Post by Markiey99 »

Treve wrote: Wednesday 07 October 2020 15:42
Markiey99 wrote:
Treve wrote: Tuesday 06 October 2020 17:57 I think dzvents is a better solution but I’m not a programmer and try to find solutions at the blockly front. Most of the times I find a solution whether or not supported with variables.
Thank you too, I've been trying to do exactly the same thing with blockly because I can't program either. But with the quick help on this forum it is still possible to use a programmed script :)
I can implement the most scripts, if you can read, you can make use of knowledge of programmers.
I struggle now how to login as Root to save the backup’s, I tried a lot without succes. I must read a lot more on the Forum I think.
Automaticly backups to the cloud are also on my to do list. :)
User avatar
Treve
Posts: 107
Joined: Thursday 05 November 2015 10:37
Target OS: Raspberry Pi / ODroid
Domoticz version: v4.11474
Location: Rotterdam, NL
Contact:

Re: Switch on Ventilation Toilet.

Post by Treve »

Finally I found a editor (VIM) which allow me to edit a root file (sshd_config) as pi user.
Now I’m able to login as root user.
- RFXtrx433E,
- AEON Labs ZW090 Z-Stick Gen5 EU
- Hue v2.1
- Raspberry Pi 3 Model B, Raspbian Stretch Full on USB-Stick.
- Domoticz 4.11474
Devices: KaKu, Z-Wave, Hue.

for testing:
Raspberry 4, 2GB, SSD
Domoticz 2022.1
Ikea Hub, Fyrtur curtain
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest