Allow switch on TV after entering correct PIN from LM2 visualization
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
- Create for each group address of PIN numbers Event-based script – 4 scripts together
- In the scripting editor add the following source (change 1 to respective PIN button number)
- pindigit(event, 1)
Function PINDIGIT
Add the following program to User Function Library located in Scripting –> Tools.
- function pindigit(event, digit)
- -- get input value
- local value = dpt.decode(event.datahex, dt.bool)
- -- false received, do nothing
- if not value then
- return
- end
-
- -- add digit to pin
- local pin = storage.get('pin', '')
- storage.set('pin', pin .. tostring(digit))
-
- -- reset digit status
- grp.write(event.dst, false, dt.bool)
- end
CLEAR button script
By pressing CLEAR button, you delete the previously entered PIN in the variable.
- local value = dpt.decode(event.datahex, dt.bool)
- if value then
- storage.set('pin', '')
- grp.write(event.dst, false, dt.bool)
- end
ENTER button script
If the entered PIN code is 1234, then switch on group address 2/2/2
- local value = dpt.decode(event.datahex, dt.bool)
- if value then
- -- get current pin
- local pin = storage.get('pin', '')
-
- -- verify pin number
- if pin == '1234' then
- grp.write('2/2/2', 1)
- end
-
- -- reset pin
- storage.set('pin', '')
- grp.write(event.dst, false, dt.bool)
- end