Page 1 of 1

multiple domoticz devices as local ..

Posted: Monday 15 April 2019 18:44
by dizzeenl
I'm facing some problems with adding multiple domoticz devices under a 'local'.
I want to make a single script to handle all my notifications and need (at the moment) 3 seperate groups for this (doors/windows, motion sensors and lights) to display the right message for each group.

Unfortunately only the first listed devices will work with the code below.
i didn't see any other script with this kind a code so i think that's the reason it's not working :lol:
I tried to convert

Code: Select all

-- Send message when sensor triggered
return {
   on = {
    devices = {
        'Voordeur',
        'Keukendeur',
        'Slaapkamerraam',
        'Voordeursensor',
        'Achtertuinsensor',
        'Voordeurlamp',
        'Achtertuinverlichting',
        'TESTdoor',
        'TESTmotion'
        }
   },
   execute = function(domoticz, item)
       local tijd = os.date("%X")
       local MAGNOmodus = domoticz.devices('MAGNOmodus')
       local lights = domoticz.devices('Voordeurlamp','Achtertuinverlichting','Woonkamer Spot')
       local DWsensors = domoticz.devices('Voordeur','Keukendeur','Slaapkamerraam','TESTdoor')
       local MOsensors = domoticz.devices('Voordeursensor','Achtertuinsensor','TESTmotion')
       domoticz.log(item.name.." triggerd")
     
    if MAGNOmodus.state == 'Standaard' then
        if (DWsensors.active) then
         	domoticz.notify(item.name,"Geopend om "..tijd,domoticz.PRIORITY_NORMAL)	
	    end
	    if (lights.active) then
         	domoticz.notify(item.name,"Ingeschakeld om "..tijd,domoticz.PRIORITY_NORMAL)	
        end
    end
    if MAGNOmodus.state == 'Afwezig' then
        if (DWsensors.active) then
         	domoticz.notify(item.name,"Is geopend om "..tijd.."!",domoticz.PRIORITY_EMERGENCY)	
	    end
	    if (MOsensors.active) then
         	domoticz.notify(item.name,"Beweging gedetecteerd om "..tijd.."!",domoticz.PRIORITY_MODERATE)	
        end
     end
	end 
} 
I also tried the .filter function but don't understand how it works jet, any idea how to solve this? :roll:

DEBUG with TESTdoor switched

Code: Select all

---- Start internal script: 04 SEN_NOTIFYv1: Device: "TESTdoor (VIRTUAL)", Index: 779
2019-04-15 18:43:07.184 Status: dzVents: Debug: Processing device-adapter for MAGNOmodus: Switch device adapter
2019-04-15 18:43:07.186 Status: dzVents: Debug: Processing device-adapter for Voordeurlamp: Switch device adapter
2019-04-15 18:43:07.188 Status: dzVents: Debug: Processing device-adapter for Voordeur: Switch device adapter
2019-04-15 18:43:07.189 Status: dzVents: Debug: Processing device-adapter for Voordeursensor: Switch device adapter
2019-04-15 18:43:07.189 Status: dzVents: Info: TESTdoor triggerd
2019-04-15 18:43:07.189 Status: dzVents: Info: ------ Finished 04 SEN_NOTIFYv1
Before i used the difference in device.state == "ON" and device.state == "Open" but because the motion and light devices has the same value i need a different approach.

Re: multiple domoticz devices as local ..

Posted: Tuesday 16 April 2019 0:58
by waaren
dizzeenl wrote: Monday 15 April 2019 18:44 I'm facing some problems with adding multiple domoticz devices under a 'local'.
I want to make a single script to handle all my notifications and need (at the moment) 3 seperate groups for this (doors/windows, motion sensors and lights) to display the right message for each group.
I also tried the .filter function but don't understand how it works jet, any idea how to solve this? :roll:
Version with filter and forEach (too complicated for this purpose?)

Code: Select all

-- Send message when sensor triggered
return {
   on = {
    devices = {
        'Voordeur',
        'Keukendeur',
        'Slaapkamerraam',
        'Voordeursensor',
        'Achtertuinsensor',
        'Voordeurlamp',
        'Achtertuinverlichting',
        'TESTdoor',
        'TESTmotion'
        }
   },
   execute = function(domoticz, item)
       local tijd = domoticz.time.rawTime
       local MAGNOmodus = domoticz.devices('MAGNOmodus')
       
       local lights = domoticz.devices().filter({'Voordeurlamp','Achtertuinverlichting','Woonkamer Spot' })
       local DWsensors = domoticz.devices().filter({'Voordeur','Keukendeur','Slaapkamerraam','TESTdoor'})
       local MOsensors = domoticz.devices().filter({'Voordeursensor','Achtertuinsensor','TESTmotion'})
       
       domoticz.log(item.name.." triggerd")
     
       if MAGNOmodus.state == 'Standaard' then
            DWsensors.forEach(function(device)
                if device.active then
                    domoticz.notify(device.name,"Geopend om "..tijd,domoticz.PRIORITY_NORMAL)	
                end    
            end)
            
            lights.forEach(function(device)
                if device.active then
                    domoticz.notify(device.name,"Ingeschakeld om "..tijd,domoticz.PRIORITY_NORMAL)	
                end
            end)
        end
        if MAGNOmodus.state == 'Afwezig' then
            DWsensors.forEach(function(device)
                if device.active then
                    domoticz.notify(device.name,"Is geopend om "..tijd.."!",domoticz.PRIORITY_EMERGENCY)	
                end
            end)
            
            MOsensors.forEach(function(device)
               if device.active then
                   domoticz.notify(item.name,"Beweging gedetecteerd om "..tijd.."!",domoticz.PRIORITY_MODERATE)	
               end
            end)
        end
	end 
}
Version with switchType

Code: Select all

-- Send message when sensor triggered
return  {
        on =    {
            devices =   {
                        'Voordeur',
                        'Keukendeur',
                        'Slaapkamerraam',
                        'Voordeursensor',
                        'Achtertuinsensor',
                        'Voordeurlamp',
                        'Achtertuinverlichting',
                        'TESTdoor',
                        'TESTmotion'
                        }
                },
    
    execute = function(domoticz, item)
        local tijd = domoticz.time.rawTime
        local MAGNOmodus = domoticz.devices('MAGNOmodus')
         
        domoticz.log(item.name.." triggerd")
     
        if MAGNOmodus.state == 'Standaard' then
            if item.switchType == 'Door Contact' and item.active then
                domoticz.notify(item.name,"Geopend om "..tijd,domoticz.PRIORITY_NORMAL)
            elseif  item.switchType ~= 'Motion Sensor' and item.switchType ~= 'Door Contact' and item.active then
                domoticz.notify(item.name,"Ingeschakeld om "..tijd,domoticz.PRIORITY_NORMAL)
            end
        elseif MAGNOmodus.state == 'Afwezig' then
            if item.switchType == 'Door Contact' and item.active then
                domoticz.notify(item.name,"Is geopend om "..tijd.."!",domoticz.PRIORITY_EMERGENCY)	
            elseif item.switchType == 'Motion Sensor' and item.active then
                domoticz.notify(item.name,"Beweging gedetecteerd om "..tijd.."!",domoticz.PRIORITY_MODERATE)	
            end
        end
    end 
}

Re: multiple domoticz devices as local ..

Posted: Tuesday 16 April 2019 13:18
by dizzeenl
Thanks a lot, i didn't knew the switchType function jet.
I changed the light type to 'On/Off' and works perfect also.

The filter and foreach function are clear now but indeed, a bit to much for this script. I hope to use it in the future.