Build an Automated Booking System with Google Services and Loxone

Create a fully automated room booking system that generates random PIN codes, emails them to guests, and automatically manages access permissions using Google Calendar, Forms, Apps Script, and Loxone's user management API.

This comprehensive guide shows you how to build a fully automated booking system that creates temporary users, generates unique PIN codes, and manages access permissions automatically. The system integrates Google Calendar, Google Forms, and Google Apps Script with Loxone's user management API and NFC Code Touch for seamless access control.

Table of Contents

What This System Does

Here's the complete workflow in plain English:

  • Guests book a time slot through a Google Form
  • The system creates a brand-new Loxone user for that booking
  • Generates a unique PIN code and limits it to the event's start/end time
  • Assigns the user to the correct door group (Room 1 or Room 2)
  • Emails the PIN to the guest automatically
  • Deletes the user when the session ends

No extra hardware required—it uses your existing NFC Code Touch + Access function block and Loxone's user management API. All booking UI is handled by Google services, with Google Apps Script acting as the integration layer.

How It Works Behind the Scenes

The system polls your two calendars for events in the next 14 days. For each event it:

  1. Resolves the right group: either via your explicit ROOM_GROUPS, or infers "Room 1" → "AccessRoom1" / "Room 2" → "AccessRoom2" by calling /getgrouplist and parsing the JSON
  2. Creates a brand-new user with name like "Room 1 2025-08-10T18:00:00.000Z" and grabs the returned uuid
  3. Assigns the user to the group (so the door block grants permission)
  4. Sets validFrom/validUntil to the event's exact start/end and expirationAction: 1 (auto-delete)
  5. Sets a unique PIN (4-8 digits, configurable) and retries if the code collides until it gets a unique one
  6. Emails the PIN to the event guests
  7. Stores the uuid + PIN in the event's private properties to avoid double-provisioning

Cleanup later deletes the user (if not already auto-deleted by the miniserver).

Understanding Loxone User Management API

The system uses Loxone's User Management API to automate the entire user lifecycle. Here's what happens step by step:

Step-by-Step API Commands

1. Create User

Endpoint: /jdev/sps/createuser/<name>

Creates a new user with a unique name (e.g., "Room 1 2025-08-10T18:00:00.000Z"). The API returns a UUID that we'll use for all subsequent operations.

JSON response from Loxone API showing successful user creation with UUID
Click to expand

Successful user creation response with UUID for further operations

2. Assign User to Group

Endpoint: /jdev/sps/assignusertogroup/<uuidUser>/<uuidGroup>

Assigns the newly created user to the appropriate access group (AccessRoom1 or AccessRoom2). This grants the user permission to access the corresponding door.

3. Set User Validity and Auto-Delete

Endpoint: /jdev/sps/addoredituser/{json}

Sets the user's validity period to match the booking start/end times and configures automatic deletion when the session expires. The JSON payload includes:

  • uuid - The user's unique identifier
  • userState: 4 - Active user state
  • validFrom - Start time in Loxone timestamp format
  • validUntil - End time in Loxone timestamp format
  • expirationAction: 1 - Auto-delete when expired

4. Generate and Set PIN Code

Endpoint: /jdev/sps/updateuseraccesscode/<uuid>/<code>

Generates a random PIN (4-8 digits, configurable) and assigns it to the user. If there's a PIN conflict (HTTP 409), the script automatically generates a new PIN and retries up to 6 times.

5. Retrieve Group Information

Endpoint: /jdev/sps/getgrouplist

Retrieves all available user groups to map room names to group UUIDs. The API returns a JSON response where the value field may contain a JSON string that needs to be parsed twice.

6. Cleanup and Deletion

Endpoint: /jdev/sps/deleteuser/<uuidUser>

Removes expired users automatically. This can happen either through the API call or automatically by the miniserver when the validity period expires.

Authentication Methods

The script supports two authentication methods for maximum compatibility:

  • Token Authentication: First attempts to use Loxone's token-based login for enhanced security
  • HTTPS Basic Authentication: Falls back to Basic auth over HTTPS if token authentication isn't available

Both methods are secure when used over HTTPS, and the script automatically handles the fallback without exposing credentials in logs.

What You Need

  • Loxone Miniserver + NFC Code Touch - Wired to your lock/relay
  • Loxone Config App - To set up the access block and groups
  • Google Account - Calendar, Forms, Sheets, and Apps Script
  • Network Access - Miniserver reachable via local IP (testing) or CloudDNS URL (production)

Loxone Setup (One-Time Configuration)

1. Configure the Access Block

  1. In Loxone Config, add your NFC Code Touch and wire/assign it to an "Access" (door) function block that pulses your lock relay
  2. Set the pulse length/open time as you normally would
  3. Test by opening with an admin code to ensure everything works
Loxone Config showing NFC Code Touch connected to Access function block with lock relay output
Click to expand

Simple drag and drop: NFC Code Touch connected to Access block with lock relay output

2. Create User Groups

  1. In "Users & Groups" create groups named exactly AccessRoom1 and AccessRoom2
  2. Open the Access function block for each door and grant the corresponding group permission:
    • Door for Room 1 → add group AccessRoom1
    • Door for Room 2 → add group AccessRoom2
  3. Optional: Note their UUIDs by browsing to http://<miniserver-ip>/jdev/sps/getgrouplist (or your CloudDNS base)
Loxone Config showing user groups creation and access permissions assignment
Click to expand

Create AccessRoom1 and AccessRoom2 groups, then assign them to their respective doors

3. Create API User

  1. Users → add "BookingIntegration" with a strong password
  2. Permissions: Give it "User management" rights so it can create users, set access codes, and assign groups
  3. Do not give it full admin if you don't need to
Loxone Config showing BookingIntegration user creation with all required permissions
Click to expand

Create BookingIntegration user with User management permissions for API access

4. Test the Setup

Create a test user manually, put them in AccessRoom1, set a code, and confirm that code opens the Room 1 door. Delete the user again. If this works, your wiring/permissions are correct.

Browser showing Loxone API response with group names and UUIDs circled
Click to expand

API response showing group names and UUIDs - keep these safe for configuration

Google Services Setup

5. Create Room Calendars

  1. Go to your Google Calendar first and click on the settings cog
  2. Calendar → Settings → "Add calendar" → create Booking with Loxone — Room 1
  3. Repeat for Room 2
  4. In each calendar's settings, copy the calendar ID (long @group.calendar.google.com string)
Google Calendar settings showing room calendar creation process
Click to expand

Go to Calendar settings cog first, then create room-specific calendars

Google Calendar settings showing calendar ID location with ID crossed out for security
Click to expand

Calendar ID location - keep yours safe! (This one is exposed for tutorial purposes)

6. Create Booking Form

Google Forms → New form with these fields:

Note: We're using Google Forms for simplicity in this tutorial. For production use, you could integrate the booking form directly into your website and send triggers to Google Calendar from your backend—this is a future enhancement project.

  • Full Name (short answer)
  • Email Address (short answer)
  • Select Room (dropdown: "Room 1", "Room 2")
  • Booking Date (date picker)
  • Start Time (time picker)
  • End Time (time picker)

Form → "Responses" → "Link to Sheets" → create a new sheet

Google Forms showing all required fields for the booking form
Click to expand

Complete form setup with all required fields (click to expand for full view)

Google Forms showing form to sheets connection
Click to expand

Link form responses to Google Sheets for automation

Google Sheets showing Extensions → Apps Script menu
Click to expand

Access Apps Script from Google Sheets Extensions menu

7. Set Up Google Apps Scripts

You'll need two Google Apps Scripts to complete the automation. The setup process is:

  1. Open the linked sheet → Extensions → Apps Script
  2. Create two files: "Form to Calendar" and "Loxone Integration"
  3. Copy the scripts from the sections below
  4. Set up triggers for automated execution
  5. Configure script properties
Google Apps Script project showing main Loxone integration script and additional scripts button
Click to expand

Main Loxone integration script with option to create additional scripts

Google Apps Script project settings showing all required script properties
Click to expand

Configure all required script properties in Project Settings

Google Apps Script triggers page showing syncUpcoming and cleanupExpired triggers
Click to expand

Set up automated triggers for calendar monitoring and cleanup

How the Two Scripts Work Together

The system uses two Google Apps Scripts that work in sequence to create a complete automated booking flow:

  • Form to Calendar Script: Processes form submissions and creates calendar events with guest invitations
  • Loxone Integration Script: Monitors calendars and automatically creates Loxone users with PIN codes

Complete Workflow: Form submission → Calendar event created → Guest invited → Loxone script detects event → User created → PIN generated → Email sent → Access granted → User automatically deleted after booking

Testing the System

8. First End-to-End Test

  1. Submit the form for "Room 1" in the next 10–20 minutes
  2. Check the Room 1 calendar → event exists
  3. Apps Script → Executions → you should see logs like:
    • "Token login OK" or "Using Basic auth fallback"
    • "Loaded groups: … AccessRoom1(…), AccessRoom2(…)"
    • "assignusertogroup → LL.code=200 (user <uuid> → group <uuid>)"
    • "Provisioned user <uuid> for 'Room 1' PIN=#### group=<uuid>"
  4. Check your email (the guest address you entered) → you should get the PIN and times
  5. In the Loxone App → Users → you'll see the new user with validity window and the AccessRoom1 group
  6. At the NFC Code Touch, the PIN should work only between the event's start and end
  7. After the window, wait for cleanupExpired or run it manually → user is deleted
Google Calendar showing events created for both Room 1 and Room 2
Click to expand

Test events created in both room calendars with guest invitations

Loxone App showing newly created user with time validity and access group membership
Click to expand

New user created with correct time window and AccessRoom1 group membership

Email inbox showing received PIN code with room name and time validity
Click to expand

PIN code email received with all booking details

Complete Scripts

Below are the complete scripts you need to copy into your Google Apps Script project. Each script is collapsible to keep the page organized.

Form to Calendar Script

This script automatically converts form submissions into calendar events. It includes conflict checking, flexible time parsing, and automatic guest invitations.

  • Form Processing: Reads form data with flexible field matching
  • Time Parsing: Handles various time formats (24h, 12h, AM/PM)
  • Conflict Prevention: Checks for double bookings before creating events
  • Calendar Mapping: Automatically routes bookings to the correct room calendar
  • Guest Invitations: Sends calendar invites to the booking email
  • Error Handling: Comprehensive logging and error reporting

Configuration Required

Before using this script, you need to update the calendar IDs:

  • Replace the calendar IDs in the calendarMap object with your actual calendar IDs
  • Set your Google Sheet's timezone to match your local timezone
  • Ensure your form field names match the expected aliases in the script

Form to Calendar Script - Complete Code

Loxone Integration Script

This script monitors your calendars and automatically creates Loxone users with PIN codes for each booking.

  • Calendar Monitoring: Polls your room calendars every few minutes for upcoming events
  • User Creation: Creates a new Loxone user for each booking with a unique name
  • Group Assignment: Automatically assigns users to the correct access groups (AccessRoom1/AccessRoom2)
  • PIN Generation: Generates unique PIN codes (4-8 digits, configurable) with conflict resolution
  • Time Management: Sets user validity to match exactly the booking start/end times
  • Email Notifications: Sends PIN codes to guests automatically
  • Cleanup: Deletes expired users to keep your system clean

Script Properties Configuration

Open "Project Settings" → "Script properties" and add these configuration values:

  • LOX_HOST = https://dns.loxonecloud.com/<SERIALHEX> (or http(s)://<local-ip> when testing on-site)
  • LOX_USER = BookingIntegration
  • LOX_PASS = your password
  • CALENDARS = [{"id":"<room1_calendar_id>","room":"Room 1"},{"id":"<room2_calendar_id>","room":"Room 2"}]
  • Optional: ROOM_GROUPS = {"Room 1":"<uuid of AccessRoom1>","Room 2":"<uuid of AccessRoom2>"} to hard-pin the group mapping
  • PIN Configuration: Edit PIN_LENGTH in the _generateCode() function to change PIN length (4, 6, 8 digits, etc.)

Required Triggers

After setting up the script, you need to create two time-based triggers:

  • syncUpcoming: Run every 1-5 minutes to process new bookings
  • cleanupExpired: Run every 15 minutes to remove old users

To set up triggers: In Apps Script, click the clock icon → "Add Trigger" → Select function → Set frequency → Save

Loxone Integration Script - Complete Code

Common Issues and Solutions

Group Assignment Issues

  • Problem: Group didn't assign
  • Solution: Make sure your groups are literally AccessRoom1 and AccessRoom2 and that each door's Access block grants those groups; or set ROOM_GROUPS with the exact UUIDs

Email Delivery Issues

  • Problem: No email arrived
  • Solution: Ensure the event actually has a guest (the form→calendar script should invite the email); check Gmail quotas if you spam test

Timing Issues

  • Problem: Wrong time / PIN active at wrong hour
  • Solution: Set the Apps Script project time zone and the calendars' time zone to your local zone; your miniserver time must also be correct

Authentication Issues

  • Problem: Token login failed
  • Solution: The script automatically uses HTTPS basic auth; that's fine. Keep LOX_HOST as the CloudDNS "front door" URL; we follow redirects

Local vs External Testing

  • Problem: Testing locally vs externally
  • Solution: On-site you can point LOX_HOST to http://<local-ip>; for external, switch back to https://dns.loxonecloud.com/<SERIALHEX>

Use Cases and Applications

This system is perfect for various scenarios where you need temporary, secure access control:

  • Airbnb / B&B Self-Check-in: Code valid from check-in to check-out; emailed automatically; zero staff
  • Sports/Gyms: Simulators, squash, padel courts; code only works for the slot
  • Coworking/Meeting Rooms: Clients book online; get code for the room; billing stays in your booking tool
  • Unmanned Hotels / Hostels: One calendar per room, iCal imports from Booking.com/Expedia into those calendars, this script does the rest

Future Enhancements

Once you have the basic system working, consider these optional improvements:

  • Website Integration: Replace Google Forms with a custom booking form on your website, sending triggers directly to Google Calendar from your backend
  • Enhanced PIN Security: Configure PIN length (6-8 digits); store a guest reference in the user's custom fields
  • Multiple Delivery Methods: Add SMS delivery alongside email
  • Auto-Door Control: Auto-pulse door on event start (use device UUIDs from LoxApp3.json and /io/<uuid>/output/<n>)
  • Grace Periods: Add a "grace" buffer (e.g., validFrom-5min, validUntil+5min)
  • Performance Optimization: Rate limiting and retries are already built-in; raise or lower trigger frequency to suit your volume
  • Alternative Booking UI: Swap the Google Form for a Google Appointment Schedule if you prefer Google's native slot picker

Security Considerations

While this system is designed with security in mind, consider these important points:

  • PIN Code Security: PIN length is configurable: 4-digit PINs provide 10,000 combinations, 6-digit PINs provide 1,000,000 combinations, 8-digit PINs provide 100,000,000 combinations
  • Time-Limited Access: PINs only work during the exact booking window, minimizing the risk of unauthorized access
  • Automatic Cleanup: Users are automatically deleted after their session ends, preventing accumulation of inactive accounts
  • HTTPS Communication: All communication with Loxone uses HTTPS encryption, protecting credentials and data in transit
  • Limited API Permissions: The BookingIntegration user only has user management rights, not full admin access
  • Audit Trail: All actions are logged in Google Apps Script execution logs for monitoring and debugging

Note: This system is designed for low to medium security environments. For high-security applications, consider additional measures such as PIN complexity requirements, access attempt logging, and integration with your existing security systems.

Conclusion

This system provides a complete, automated solution for managing room access through bookings. By leveraging Google's suite of services and Loxone's powerful user management API, you can create a professional booking system that requires zero manual intervention while maintaining security and providing a seamless guest experience.

The integration handles all the complexity behind the scenes—user creation, PIN generation, group assignment, and cleanup—while providing a simple interface for guests to book and access their reserved spaces.

For more automation projects and Loxone integration tutorials, stay tuned to our blog.

Contact Me