Skip to content
Senior IT Developer, Software Architect, AI masterDocumentation

← All guides

How to: automate heating, lights, sockets, thermometers and smart lock PINs (Tuya Automation)

After the Tuya connection works, every apartment gets a Tuya Automation box with four sections: “Heating”, “Lights & sockets”, “Smart lock PINs” and “Thermometers”. The plugin checks confirmed reservations every 15 minutes and sends a command only when the state changes; for smart locks it creates a time-limited PIN for every confirmed reservation.

1 First test each device on Bookings -> Tuya Automation: enter a Device ID (thermostat / valve) and a temperature such as 22 and click “Send heat command”, or enter a Device ID (light / socket) and click “Switch on” or “Switch off”. Errors are shown on the page and written to the log.
2 Edit the apartment and scroll to the Tuya Automation box. Fill in only the sections you need.
3 “Heating”: tick “Control heating automatically” and enter the Device IDs of thermostats or radiator valves, one per line. Set “Arrival temperature” (for example 22), choose in “After departure” either “Set idle temperature” (with “Idle temperature”, for example 16) or “Turn heating off”, and set “Start hours before check-in” (for example 3) and “Keep running hours after check-out” (usually 0).
4 “Lights & sockets”: tick “Switch on at arrival, switch off after departure” and enter the Device IDs of bulbs, sockets, relays or switches, one per line. Set “Switch on hours before check-in” (for example 1) and “Switch off hours after check-out” (for example 0). All on/off channels of a device are switched.
5 “Thermometers”: enter the Device IDs of temperature / humidity sensors, one per line. Optionally set “Low temperature alert below” (for example 5); the site admin then gets an e-mail when a sensor falls below that value, even when the apartment is empty.
6 “Smart lock PINs”: tick “Generate a PIN for every confirmed reservation” and enter the Device IDs of your Tuya smart locks, one per line (the same PIN is set on all of them). Set “PIN length” (6 to 10 digits, default 6), “Valid hours before check-in” (default 1), “Valid hours after check-out” (default 1) and “Create PIN days before check-in” (default 3).
7 Check that the Check-in and Check-out times of the apartment are filled in, because the schedule is built from them (defaults 14:00 and 10:00), then click Update.
8 Back on Bookings -> Tuya Automation check the table of apartments (state of each section and the latest thermometer readings) and click “Run synchronisation now”. The “Log” section lists every command and error, including every created lock PIN.

How the schedule works: “Heating” and “Lights & sockets” are active from the configured hours before check-in until the check-out time (plus the optional hours after) of a confirmed reservation; otherwise the apartment is idle. When reservations follow each other, nothing is switched off in between. Only confirmed reservations count; pending, cancelled and blocked ones are ignored.

The first time a section is processed and the apartment is idle, nothing is sent, so your manual settings stay untouched. Commands are sent only when the state changes to active (arrival) and back to idle afterwards.

“Turn heating off” switches the device off. Radiator valves without a power switch get their lowest temperature instead of being switched off completely.

Supported devices: thermostats and radiator valves with a target temperature setting, smart plugs and sockets, bulbs, relays, multi-channel switches and temperature / humidity sensors. Devices with non-standard data points may not respond; check the “Log” section to see what happened.

If a command fails (device offline, Tuya outage), the plugin retries every 15 minutes and e-mails the site admin once about the failure. Thermometer readings are refreshed every 15 minutes and count towards the API limits of your Tuya plan.

Smart lock PINs – how it works: within the configured number of days before check-in the plugin generates a random PIN for each confirmed reservation (trivial PINs such as 111111 or 123456 are skipped) and sets it on every listed lock as a temporary password valid from the check-in time minus the hours before until the check-out time plus the hours after. The PIN is saved with the reservation. When a reservation is cancelled or deleted, or the stay has ended, its PIN is removed from the lock automatically. A PIN that could not be created (lock offline) is retried every 15 minutes and the error is written to the log.

Smart lock PINs – sending the PIN to the guest: in the guest e-mails (for example the arrival instructions e-mail) use the placeholder {{door_pin}}. For reservations with a generated PIN it is replaced by that PIN; it replaces a fixed {{door_pin}} value of the apartment, so the guest always gets the code of their own stay. Placeholders are available in the Pro e-mail designer.

Smart lock PINs – requirements: in your Tuya Cloud project subscribe the Smart Lock Open Service under Service API (next to IoT Core), and the lock must support cloud temporary passwords and be online through WiFi or a gateway. Locks that work only over Bluetooth without a gateway cannot receive PINs. The PHP OpenSSL extension must be enabled.

WP-Cron runs only when the site receives visits. On a site with low traffic add a real cron job that calls wp-cron.php every 5 minutes and set DISABLE_WP_CRON to true in wp-config.php.

Plugin download: https://vachr.cz/plugins-for-wordpress/ – install it via Plugins -> Add New -> Upload Plugin, then follow the guide on connecting Tuya / Smart Life devices.