Example: Allow switch on TV after entering correct PIN from LM2 visualization

Task

On the logic Machine 2 visualization add PIN number icons, objects attached to these icons. Create program allowing to switch on TV on group address 2/2/2 only if the PIN code is entered correctly

Add KNX objects

Add 4 objects which will be attached to PIN number, 1 object for Enter button and 1 object for Clear button.

Add visualization icons

Create visualization map

Choose from the list added KNX object and respective visualization icon and add them to the map.

Event-based program for each PIN number

Source code    
  1. pindigit(event, 1)

Function PINDIGIT

Add the following program to User Function Library located in Scripting –> Tools.

Source code    
  1. function pindigit(event, digit)
  2. -- get input value
  3. local value = dpt.decode(event.datahex, dt.bool)
  4. -- false received, do nothing
  5. if not value then
  6. return
  7. end
  8.  
  9. -- add digit to pin
  10. local pin = storage.get('pin', '')
  11. storage.set('pin', pin .. tostring(digit))
  12.  
  13. -- reset digit status
  14. grp.write(event.dst, false, dt.bool)
  15. end

CLEAR button script

By pressing CLEAR button, you delete the previously entered PIN in the variable.

Source code    
  1. local value = dpt.decode(event.datahex, dt.bool)
  2. if value then
  3. storage.set('pin', '')
  4. grp.write(event.dst, false, dt.bool)
  5. end

ENTER button script

If the entered PIN code is 1234, then switch on group address 2/2/2

Source code    
  1. local value = dpt.decode(event.datahex, dt.bool)
  2. if value then
  3. -- get current pin
  4. local pin = storage.get('pin', '')
  5.  
  6. -- verify pin number
  7. if pin == '1234' then
  8. grp.write('2/2/2', 1)
  9. end
  10.  
  11. -- reset pin
  12. storage.set('pin', '')
  13. grp.write(event.dst, false, dt.bool)
  14. end