Garage script, not working as planned.

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

Moderator: leecollings

Post Reply
User avatar
jacobsentertainment
Posts: 223
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Garage script, not working as planned.

Post by jacobsentertainment »

Hi guy's

I'm trying to convert all my scripts from blocky to Dzvents. The next script is working but I'm not getting the correct results.
My situation is;
Garage has an main switch, to powerup machines and all sockets. For the workshop I got one light switch and same for the garage one light switch.
There are also two PIR motion detectors and a garage door as a trigger for the lights.
My idea is I leave the two light switches on and when I flick the main powerswitch it all switches on, if one of the light switches is switched of that light goes down and vise-versa. If main switch is off all go off. If there is motion or the door opens and the main is off the lights go on for 3 minutes even if the light switches or in off position.

I came up with the following script and I thought is was working fine but now if I flick on the main the lights won't go on. according to the log they should be on. Maybe I'm doing something simply wrong or I might not see a small mistake, I hope someone here does see it.

Code: Select all

return {
	
	on = {
		devices = { 184, 185, 186, 144, 145, 65, 66, 39,
		},
	},
	
	logging = {
        level = domoticz.LOG_INFO,
        marker = "WP_verlichting"
         },       
    execute = function(domoticz, devices)

    
        local Thuis = domoticz.devices(65)
        local WP_pir = domoticz.devices(144)
        local Gar_pir = domoticz.devices(145)
        local hfd_schakelaar = domoticz.devices(184)--shelly i3
        local WP_lichtschakelaar = domoticz.devices(185)--shelly i3
        local Gar_lichtschakelaar = domoticz.devices(186)--shelly i3
        local Hoofdrelais = domoticz.devices(33)--shelly2.5
        local WP_verlichting = domoticz.devices(31)--shelly2.5
        local Gar_verlichting = domoticz.devices(32)--shelly2.5
        local Garagedeur = domoticz.devices(39)
        
    if  Thuis.state == 'On' and hfd_schakelaar.state == 'On' then 
            Hoofdrelais.switchOn()
            domoticz.log('Hoofdschakelaar staat aan!')
        else
            Hoofdrelais.switchOff()
            domoticz.log('Hoofdschakelaar uit!')
    end
    
    if Thuis.state == 'On' and Bedtime.state == 'On' and hfd_schakelaar.state == 'On' and WP_lichtschakelaar.state == 'On' then
            WP_verlichting.switchOn()
            domoticz.log('werkplaatslicht aan!')
        else
            WP_verlichting.switchOff()
            domoticz.log('werkplaatslicht uit.')
    end
        
    if Thuis.state == 'On' and Bedtime.state == 'On' and hfd_schakelaar.state == 'On' and Gar_lichtschakelaar.state == 'On' then
            Gar_verlichting.switchOn()
            domoticz.log('garagelicht aan!')
        else
            Gar_verlichting.switchOff()
            domoticz.log('garagelicht uit.')
    end
    
    if WP_pir.state == 'On' or Gar_pir.state == 'On' or Garagedeur.state == 'On' and hfd_schakelaar.state == 'Off' then
            WP_pir.switchOff().afterSec(180)
            Gar_pir.switchOff().afterSec(180)
            WP_verlichting.switchOn()
            Gar_verlichting.switchOn()
            domoticz.log('Beweging in de schuur, licht aan.!')
        else
            WP_verlichting.switchOff()
            Gar_verlichting.switchOff()
    end
end
}
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Garage script, not working as planned.

Post by Number8 »

hi
The first thing I would do is tu put parenthesis here and same for the other ones

Code: Select all

 if (Thuis.state == 'On' and Bedtime.state == 'On' and hfd_schakelaar.state == 'On') and Gar_lichtschakelaar.state == 'On'
Debian buster on NUC and three RPi with buster.
User avatar
jacobsentertainment
Posts: 223
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: Garage script, not working as planned.

Post by jacobsentertainment »

Number8 wrote: Tuesday 05 October 2021 18:41 hi
The first thing I would do is tu put parenthesis here and same for the other ones

Code: Select all

 if (Thuis.state == 'On' and Bedtime.state == 'On' and hfd_schakelaar.state == 'On') and Gar_lichtschakelaar.state == 'On'
I'm not sure what it does, but tried it and no change in behaviour :cry:
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Garage script, not working as planned.

Post by EddyG »

Parentheses have no use if all are 'and'
Parentheses have use if there are 'or' and 'and'

Code: Select all

if (WP_pir.state == 'On' or Gar_pir.state == 'On' or Garagedeur.state == 'On') and hfd_schakelaar.state == 'Off' then
or sometimes for more readability.

Code: Select all

if WP_pir.state == 'On' or Gar_pir.state == 'On' or Garagedeur.state == 'On' then 
	if hfd_schakelaar.state == 'Off' then
		.....
	end
end
or

Code: Select all

if hfd_schakelaar.state == 'Off' then
	if WP_pir.state == 'On' or Gar_pir.state == 'On' or Garagedeur.state == 'On' then 
		....
	end
end
User avatar
jacobsentertainment
Posts: 223
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: Garage script, not working as planned.

Post by jacobsentertainment »

Still working on the script, start from scratch and try to learn from my failures.
Question! how can I cluster a couple of triggers? I tried this but won't work.

Code: Select all

domoticz.devices(163, 191, 154).state == 'On'
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Garage script, not working as planned.

Post by rrozema »

You have to set the state using one of the .updateXXX(), .toggleXXX(), .switchXX(), etc functions. attributes like .state are for reading, not for writing. What function(s) is/are available depends on the type of the item you're working on. You can find the details in dzVents documentation. When working with normal switches you'll most likely use device.switchOn() and device.switchOff() or device.toggleSwitch().
User avatar
user4563
Posts: 114
Joined: Tuesday 19 October 2021 17:24
Target OS: Linux
Domoticz version: 2025.2
Contact:

Re: Garage script, not working as planned.

Post by user4563 »

May I ask why if Blockly is working, why convert everything to dzVents?
ODroid H4+ / Ubuntu server 24.04 LTS
Aeotec Z-Stick Gen5+
ZWave-JS-UI / Mosquitto MQTT
Domoticz for Android
Domoticz Scenes add-on in Kodi
User avatar
jacobsentertainment
Posts: 223
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: Garage script, not working as planned.

Post by jacobsentertainment »

user4563 wrote: Monday 08 November 2021 21:00 May I ask why if Blockly is working, why convert everything to dzVents?
Blockly is ok for simple scripts but lacks some functionality/flexibility if things get more complicated. (my opinion :mrgreen: )
For me (no IT related background) blockly was a nice and easy way of stepping in to organizing my domoticz scheiße. Now I'm slowly getting the hang of Dzvents and I like it! Some things I couldn't combine in blockly is easy in Dzvents to combine and make it work. So from about 30 scripts in blockly is now 50% reduced to Dzvents.
And I like the error feedback if a script has a fault it tells me on what line the issue is, in blockly I sometimes had to go over and over to find the fault or find a working solution. (or I did something terribly wrong :lol: )
User avatar
user4563
Posts: 114
Joined: Tuesday 19 October 2021 17:24
Target OS: Linux
Domoticz version: 2025.2
Contact:

Re: Garage script, not working as planned.

Post by user4563 »

Thanks for the reply, that makes sense. I'm a new user to Domoticz and have been studying dzVents and it's syntax as well. You can really get into some interesting and custom things with it!
ODroid H4+ / Ubuntu server 24.04 LTS
Aeotec Z-Stick Gen5+
ZWave-JS-UI / Mosquitto MQTT
Domoticz for Android
Domoticz Scenes add-on in Kodi
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest