Page 1 of 1

Script sending muliple messages

Posted: Sunday 06 September 2020 19:59
by wouterlet
Hi,

I wrote an alarm script.
I have an alarm pad with an fibaro Smart implant attached. If I switch of the alarm ('Alarm Switch 1') by this box, the message 'Alarm uitgeschakeld' is send 3 times. I thought I fixed it with the uservariable 'Var Alarm. This fixed sending it 20 times, but it's still sending it 3 times.

'Alarm Switch 1' is an push-on button (also tried on/off button) with an of delay of 1 sec.
In the button log on 1 'on' is logged and then of, so no multiple 'on's' here.

Is there a way how to fix this different?

The same problem come up when I used an 433 button, but thisone is sending multiple 'on's'

Hope you can help:

Code: Select all

return {
	on = {
		devices = { 'Alarm Switch 1', 
		            'Alarm Switch 2', 
		            'Button alarm beneden', 
		            'Button alarm uit boven',
		            'Motion Bijkeuken', 
		            'Motion Zithoek', 
		            'Motion Speelhoek', 
		            'Motion Eetkamer', 
		            'Motion Keuken',
		            'Motion Overloop', 
		            'Motion Badkamer',
		            'Alarm hele huis',
		            'Alarm beneden'},
		            'Trigger alarm beneden',
		            'Trigger alarm hele huis'
	},
	data = {},
	logging = {},
	execute = function(dz, Item)
    if  dz.devices('Alarm Switch 2').state == 'On' and
        (dz.variables('Var Alarm').value == 0 or
        dz.variables('Var Alarm').value == 2)then 
        dz.devices('Trigger alarm hele huis').switchOn()                        -- Alarm trigger hele huis inschakelen
    end   
    if  dz.devices('Trigger alarm hele huis').state == 'On' and
        dz.devices('Motion Bijkeuken').state == 'Off' and                       
        dz.devices('Motion Zithoek').state == 'Off' and  
        dz.devices('Motion Speelhoek').state == 'Off' and  
        dz.devices('Motion Eetkamer').state == 'Off' and   
        dz.devices('Motion Keuken').state == 'Off' and                          -- Of ergens anders beneden
        dz.devices('Motion Overloop').state == 'Off' and   
        dz.devices('Motion Badkamer').state == 'Off' then      
        dz.devices('Alarm hele huis').switchOn()
        dz.notify('Alarm hele huis ingeschakeld')
        dz.variables('Var Alarm').set(1)
    end
    if  dz.devices('Button alarm beneden').state == 'On' and
        (dz.variables('Var Alarm').value == 0 or
        dz.variables('Var Alarm').value == 1) then                    
        dz.devices('Trigger alarm beneden').switchOn()                          -- Alarm trigger beneden inschakelen, voor de nacht, alleen de sensoren beneden triggeren het alarm
    end
    if  dz.devices('Trigger alarm beneden').state == 'On' and
        dz.devices('Motion Bijkeuken').state == 'Off' and                       
        dz.devices('Motion Zithoek').state == 'Off' and  
        dz.devices('Motion Speelhoek').state == 'Off' and  
        dz.devices('Motion Eetkamer').state == 'Off' and   
        dz.devices('Motion Keuken').state == 'Off' then                         -- Of ergens anders beneden     
        dz.devices('Alarm beneden').switchOn()
        dz.notify('Alarm beneden ingeschakeld')
        dz.variables('Var Alarm').set(2)
    end
    if  (dz.devices('Button alarm uit boven').state == 'On' or
        dz.devices('Alarm Switch 1').state == 'On')  and
        (dz.variables('Var Alarm').value == 1 or
        dz.variables('Var Alarm').value == 2)  then
        dz.devices('Trigger alarm hele huis').switchOff()
        dz.devices('Trigger alarm beneden').switchOff()                         -- Alarm uitschakelen
        dz.devices('Alarm hele huis').switchOff()
        dz.devices('Alarm beneden').switchOff()
        dz.devices('Alarm Sirene').switchOff()
        dz.notify('Alarm uitgeschakeld')
        dz.variables('Var Alarm').set(0)
    end
    if  dz.devices('Alarm hele huis').state == 'On' and                         -- Als het alarm aan staat
        (dz.devices('Motion Bijkeuken').active.forSec(30) or                    -- En er beweging langer dan 30 sec beweging is in de bijkeuken
        dz.devices('Motion Zithoek').active or
        dz.devices('Motion Speelhoek').active or
        dz.devices('Motion Eetkamer').active or
        dz.devices('Motion Keuken').active or                                   -- Of ergens anders beneden
        dz.devices('Motion Overloop').active or
        dz.devices('Motion Badkamer').active) then                              -- Of ergens boven
        dz.devices('Alarmsituatie hele huis').switchOn()                        -- Alarm hele huis aan
        dz.notify('Alarm hele huis')
    end
    if  dz.devices('Alarm beneden').state == 'On' and                           -- Als het alarm aan staat
        (dz.devices('Motion Bijkeuken').active or                               
        dz.devices('Motion Zithoek').active or
        dz.devices('Motion Speelhoek').active or
        dz.devices('Motion Eetkamer').active or
        dz.devices('Motion Keuken').active) then                                -- Als er beweging is beneden
        dz.devices('Alarmsituatie beneden').switchOn()                          -- Alarm beneden aan
        dz.notify('Alarm beneden')
    end
--    if  dz.devices('Alarmsituatie beneden').state == 'On' or
 --       dz.devices('Alarmsituatie hele huis').state == 'On' then
  --      dz.devices('Alarm Sirene').switchOn()
--	end
end
}

Re: Script sending muliple messages

Posted: Sunday 06 September 2020 20:59
by waaren
wouterlet wrote: Sunday 06 September 2020 19:59 I wrote an alarm script.
I have an alarm pad with an fibaro Smart implant attached. If I switch of the alarm ('Alarm Switch 1') by this box, the message
Hope you can help:
Happy to help but first I need to understand what you try to achieve. Can you please describe in text (not code) what you want to happen when ?

Re: Script sending muliple messages

Posted: Sunday 06 September 2020 21:50
by wouterlet
I'm sorry I'm staring at it for a while so it's naturally to me😉.

I switch on my alarm in 2 zones:

Or the complete house, when we leave.
The alarm is triggered by a keypad wit an Fibaro Smart Implant. This SI has 2 switches, 'Alarm Switch 1' and 'Alarm Switch 2'. Alarm switch 1 is for alarm off, alarm switch 2 for alarm on.

Or just downstairs when we sleep.
I have 2 buttons upstairs: 'Button alarm beneden' for alarm on, 'Button alarm uit boven' to switch the alarm off.

Both work the same only the 'alarm beneden' missies the motion sensors upstairs. So it won't trigger the alarm when we go to the toilet.

To switch on the alarm the button or keypad switches a dummy switch ('Trigger alarm hele huis' or 'Trigger alarm beneden' ). The next part looks if this trigger is true and all motion sensors are off. If this is the case the alarm is really switched on. Also a message is send that the alarm is on.

To switch of the alarm one of these buttons is pressed: 'Button alarm uit boven' or 'Button alarm uit boven'. Then all devices dummies enz are reset to rest. And a message is send that the alarm is off.

When the alarm is on and a motion sensor is triggered one off the dummy's alarmsituation is switched on. And a message is send that there is an alarm.

Next to that in the commented part a siren is triggered.

The alarm itself seems to work. If the alarm is switched on or off I get the message about 3 times. I want to reserve the message once.

Hopefully this is more clear to you? Of not let me know what you miss!

Re: Script sending muliple messages  [Solved]

Posted: Sunday 06 September 2020 23:38
by waaren
wouterlet wrote: Sunday 06 September 2020 21:50 Hopefully this is more clear to you? Of not let me know what you miss!
Sent you a private mail