Select problem  [Solved]

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

Moderator: leecollings

Post Reply
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Select problem

Post by kroonp »

Hello
I am struggling with the following problem. I have an ELRO switch with 4 positions On and Off. With this switch I want to switch on 4 different scenes. I have already tried it in different ways but they don't work or they influence each other. I am probably using the wrong structure. Who can help me on my way.

Peter
-----

Code: Select all

   return {
        on = {
          devices = {

             'Switch1_1',
             'Switch1_2',            
             'Switch1_3',
             'Switch1_4'
          }
        },
    
    	    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is OK
        marker = 'Slkmr_switch',
    },

	execute = function(dz, device, triggerInfo)
	    
	    local Automaat = dz.devices('Automaat')
        local Slapen = dz.devices('Slapen')

        if(Automaat.state=='On') then   
            
            
            if  ( device . name  ==  'Switch1_1'  and  device .name. state=='On')  then
                dz.scenes('sc_bedverlichting_100').switchOn()
            end 
                
        
         if  ( device . name  ==  'Switch1_2'  and  device .name. state=='On')  then
        	    dz.scenes('sc_bedverlichting_50').switchOn()
        	end
        			
         if  ( device . name  ==  'Switch1_3'  and  device .name. state=='On')  then
        	    dz.scenes('sc_bedverlichting_10').switchOn()
        	end
        	
        	
         if  ( device . name  ==  'Switch1_4'  and  device .name. state=='On')  then
        	    dz.scenes('sc_bedverlichting_tv').switchOn()
        	end
        		    
    
            if  ( device . name  ==  'Switch1_1'  and  device .name. state=='Off')  then
        	    dz.scenes('sc_bedverlichting_uit').switchOn()
        	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: Select problem

Post by waaren »

kroonp wrote: Thursday 10 December 2020 22:01 Hello
I am struggling with the following problem. I have an ELRO switch with 4 positions On and Off. With this switch I want to switch on 4 different scenes. I have already tried it in different ways but they don't work or they influence each other. I am probably using the wrong structure. Who can help me on my way.
I don't know if the syntax errors were the only reason but can you try below script?
If not yet OK then please include log of the execution and show what you expected and what actually happened.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Switch1_*',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is OK
        marker = 'Slkmr_switch',
    },

    execute = function(dz, device)

        local Automaat = dz.devices('Automaat')
        local Slapen = dz.devices('Slapen')

        if Automaat.state == 'On' then

            if device.name == 'Switch1_1' and device.state == 'On' then
                dz.scenes('sc_bedverlichting_100').switchOn()
            elseif device.name == 'Switch1_2' and device.state == 'On' then
                dz.scenes('sc_bedverlichting_50').switchOn()
            elseif device.name == 'Switch1_3' and device.state == 'On' then
                dz.scenes('sc_bedverlichting_10').switchOn()
            elseif device.name == 'Switch1_4' and device.state == 'On' then
                dz.scenes('sc_bedverlichting_tv').switchOn()
            elseif device.name == 'Switch1_1' and device.state == 'Off' then
                dz.scenes('sc_bedverlichting_uit').switchOn()
            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
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Select problem  [Solved]

Post by kroonp »

Hello waaren
Thank you very much for the quick answer. Your solution works fine. (As always). I have learned a lot again. Thank you for doing this work to help people move forward.
Have a nice day.
Peter
Post Reply

Who is online

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