Domoticz lua scripts, developed by Creasol https://www.creasol.it/domotics
In this repository you can find several LUA scripts and config files for Domoticz, the easy and powerful open-source home automation system controller.
More information, scripts, application notes, examples are available at https://www.creasol.it/support/domotics-home-automation-and-diy
Some scripts require that you install the dkjson package, with the command apt install lua-dkjson
All scripts are free to use, with absolute no warranty. Use them at your own risk.
All global variables and functions are stored in the files globalvariables.lua and globalfunctions.lua.
** The scripts are used with out set of industrial and home automation system modules, made in Italy: for more info, check below! **
For any requests, you can join DomBus channel on Telegram
This is a main script called every time a device changes state: it's optimized to
- run quickly
- ignore useless device changes
- call the appropriate scripts associated to the changed devices: for example if the changed device is named PIR* or MCS* or SIREN* , the alarm.lua script will be called, while if the device is named power*, the power.lua script will be called.
File: power.lua and config_power.lua
Destination directory: DOMOTICZ_DIR/scripts/lua
Called by script_device_master.lua and triggered when a device containing Power or Button in its name changes state.
Used to check power from energy meter (SDM120, SDM230, ...) and performs the following actions
- Send notification when consumed power is above a threshold (to avoid power outage)
- Enabe/Disable electric heaters or other appliances, to reduced power consumption from the electric grid
- Emergency lights: turn ON some LED devices in case of power outage, and turn off when power is restored
- Show on DomBusTH LEDs red and green the produced/consumed power: red LED flashes 1..N times if power consumption is greater than 1..N kW; green LED flashes 1..M times if photovoltaic produces up to 1..M kW
Files: script_time_selfconsumption.lua config_power.lua globalfunctions.lua globalvariables.lua
Destination directory: DOMOTICZ_DIR/scripts/lua
Called every minute
This is a mandatory script for those who have at least one reneable generation plant in their building.
It manages one or more energy production plants (photovoltaic on the roof, photovoltaic in the garden and or wind turbine, ...) computing the total generated energy/power, total used energy/power, self-consumption energy/power, self-consumption percentage and self-sufficiency percentage.
These are goods indicators to know if the building is optimized or not.
Detailed info are available at www.creasol.it/SelfConsumption page.
Script that, every time a power meter changes, computes the sum of 2 or more power meters and feeds that value to the DomBusEVSE virtual device
Files: script_device_evsegridpower.lua
This simple script is meant to compute the total power from the grid and feed it to the DomBusEVSE module, EV charging system that must know the total power from the grid, to prevent overloads and manage solar charging. In case of 2 or 3 meters are used (for example, a meter for the house, a meter for the electric car, and another meter for the garage, it computes the total power.
Files: heatpump.lua (script_time_heatpump_emmeti.lua) and config_heatpump_emmeti.lua
Destination directory: DOMOTICZ_DIR/scripts/lua
Called every minute
This script is designed for radiant systems:
- it measures the temperature in each room, computes a derivative of a temperature to states if the house is warming or not (PID control) and regulates the heat pump power to satisfy the warming/cooling needs for the best comfort.
- it's possible to define peak hours where power consumption should be limited, to give your contribution for electricity grid stabilization
- if photovoltaic or wind generator is available, try to consume most energy from renewable production plants, improving self consumption
- for each room it's possible to define a period where the set-temperature can be reduced (in Winter, or increased in Summera)
Files: script_time_heatpump.lua and heatpump_conf.lua
Destination directory: DOMOTICZ_DIR/scripts/lua
Called every minute
This script manages the heat pump, adjusting power and fluid temperature to meet the building demand.
If a photovoltaic system is installed, with a power meter measuring the power exchanged with the electric grid, during the summer the heat pump will try to work only when extra power from photovoltaic is produce. No power => heat pump off or at minimum level.
During the winter, the heat pump will work expecially during the day, when external temperature is high, and regulates the fluid temperature smartly to get the heat pump consuming the most energy from photovoltaic and working hard when external temperature is high, and works at minimum (or off) when the external temperature does not permit to get an high efficiency
Files: alarm.lua (script_device_alarm.lua) alarm_config.lua alarm_sendsnapshot.sh and alarmSet.sh
Destination directory: DOMOTICZ_DIR/scripts/lua
Called by script_device_master.lua and triggered when a device with name starting with PIR , MCS , SIREN, TAMPER, ALARM or Light, changes state, or when the variable alarmLevelNew is not zero (alarm started or stopped)
Scripts that manages a burglar alarm system: magnetic contact sensors on doors/windows/blinds, PIRs and radars, tampers, sirens.
Full notifications on Telegram and 3 working modes fully configurable:
- DAY: it shortly activates internal sirens when a door/window opens or a PIR is activated
- NIGHT: in case of alarm, only activates the internal sirens and turns ON some lights.
- AWAY: in case of alarm, both internal and external sirens are activated.
Other features:
- External sirens delay when alarm is activated on some configurable sensors (for example, main door)
- Records short videos when external sensors have been activated (when someone or a cat walk outside)
- Recode short videos to 2x speed, and sends to Telegram channel/group
- House presence lights will be managed when AWAY alarm is active, between Sunset and Sunrise, to simulate that someone is inside the house.
More info at https://www.creasol.it/freeBurglarAlarm
Files: script_time_fireAlarm.lua config_fireAlarm.lua
Destination directory: DOMOTICZ_DIR/scripts/lua
LUA script that loads the rooms information from config_fireAlarm.lua and for any room if Temperature > averageTemperature + deltaT => fire alarm detected => send notification by Telegram
More information available at fire alarm page
File: script_time_rainCheck.lua
Destination directory: DOMOTICZ_DIR/scripts/lua
Called every minute
Script that checks the raining rate and wind speed, and performs several functions:
-
If raining rate is over 8mm/h, disable external socket in the garden (connected to the Xmas tree!!).
-
Checks wind speed and direction and disable ventilation when wind speed is zero or wind comes from south or west, where there are few building using wood stoves generating bad smoke smell.
-
Sends weather telemetry to WindGuru
-
Send buzzer alert if a trash bin should be carried out:
- 1 beep (followed by 4s pause) for paper
- 2 beeps (followed by 4s pause) for plastic/metal
- 3 beeps (followed by 4s pause) for unsorted
- 4 beeps (followed by 4s pause) for glass
It's programmed to work with the cheap DomBusTH module which can be placed in a blank cover (in a wallbox) and already provide a piezo buzzer output, red+green+white leds, touch sensor (simulating a pushbutton, that can be used to cancel the alarm), other 4 I/Os, temperature and humidity sensors. DomBusTH video
-
Enable/Disable gate power supply to reduce energy consumption and improve antitheft security: check vehicle position to determine if it's approaching (gate should be enabled) or it's moving away (gate should be disabled). In any case, the gate power supply is turned OFF when the alarm system is in NIGHT or AWAY mode.
File: script_time_fronius.lua
Destination directory: DOMOTICZ_DIR/scripts/lua
Simple script that every minute fetch data, by http, from Fronius solar inverter.
File script_time_earthquake.lua , together with globalvariables.lua and globalfunctions.lua, can be used to get earthquakes alert on Domoticz and, if magnitude is stronger than a certain threshold, also sends alert on a Telegram channel or group.
File script_device_power2p1.lua is a LUA script for Domoticz useful for the Energy Dashboard. It can be used to update a virtual P1 meter (that you have to create by yourself from Setup -> Hardware menu), writing the current power and energy (usage and return). Also, the script can handle more generators (photovoltaic on roof, photovoltaic in the garden, wind generator, ...) compute the sum of the power to a virtual device, used by the Energy Dashboard.
Just copy this script in scripts/lua folder and update the 6 variables at the top of file.
Script that fetches electricity energy price from ENTSO-e website (for your specific zone, if you reside in EU)
File script_time_entsoe.lua is a LUA script for Domoticz that:
- fetches every day, in the afternoon, the day-ahead electricity prices for your zone
- update a custom virtual device with the current energy price (that changes every hour)
- compute your real energy cost (including taxes, fees, ...) and update a custom virtual device with that price
- let Domoticz core to get electricity price from the last custom virtual device, so Domoticz can show energy costs in the energy dashboard
- store in a user variable the energy price of the day, hour by hour, separated by semicolon, and in last position the average price: in this way it's possible to include in automations the management of load devices (for example climate heat pump) to reduce or increase their power based on the current energy price. For example, it's possible to set every hour the climate heat pump to work to a targetPower * averagePrice / currentPrice , to save energy when price is high and consume more energy when power is low. Similar policy can be chosen to charge the electric vehicle when energy cost is low. Although in Italy electric energy cost is based on the montly average price for 3 time slots (day, early morning/evening, night/Sunday), we should aim to regulate the power consumed by our buildings to increase it when there is more availability and reduce it when there is less availability of electricity.
- Copy files script_time_entsoe.lua globalvariables.lua globalfunctions.lua to the DOMOTICZ/scripts/lua directory
- Edit script_time_entsoe.lua : you'll find a description of the procedure to register to ENTSO-e website, get a security token and create two custom devices
Example of a domotic system managing lights, door bell, alarm, heat pump, ventilation, irrigation, ...
-- script_time_example.lua : simple example script that write a message to Telegram channel/group if temperature is less than 5
commandArray={}
dofile "script/lua/globalvariables.lua" -- read a file with some variables, including Telegram API key and ChatID
dofile "script/lua/globalfunctions.lua" -- read a file with some functions
if (tonumber(otherdevices['Temp_outdoor']) < 5) then -- check that Temp_outdoor temperature sensor is >=5 Celsius, or send a notice to Telegram
telegramNotify("Low temperature: bring flowers inside") -- send message by Telegram
end
return commandArray
- batteryMin.zip : battery level min (used for EVehicles)
- batteryMax.zip : battery level max (used for EVehicles)
Below a list of modules, produced in Europe by Creasol, designed for Domoticz to be reliable and optimized for very very low power consumption.
Our industrial and home automation modules are designed to be
- very low power (around 10mW with relays OFF)
- reliable (no disconnections)
- bus connected (no radiofrequency interference, no battery to replace).
Modules are available in two version:
- with DomBus proprietary protocol, working with Domoticz only
- with Modbus standard protocol, working with Home Assistant, OpenHAB, Node-RED
Store website - Information website
Complete solution to make a Smart EVSE, charging the electric vehicle using only energy from renewable source (photovoltaic, wind, ...), or adding 25-50-75-100% of available power from the grid.
- Single-phase and three-phase, up to 32A (8kW or 22kW)
- Needs external contactor, RCCB (protection) and EV cable
- Optional power meter to measure charging power, energy, voltage and power factor
- Optional power meter to measure the power usage from the grid (not needed if already exists)
- Two max grid power thresholds can be programmed: for example, in Italy who have 6kW contractual power can drain from the grid Max (6* 1.27)=7.6kW for max 90 minutes followed by (6* 1.1)=6.6kW for another 90 minutes: in this case the EVSE module can drain ALL available power when programmed to charge at 100% minimizing the charge time and increasing the charging efficiency.
- Works without the domotic controller (stand-alone mode), and can also work in managed mode, with an automation in the home automation system setting the charging current
DomBusTH - Compact board to be placed on a blank cover, with temperature and humidity sensor and RGW LEDs
Compact board, 32x17mm, to be installed on blank cover with a 4mm hole in the middle, to exchange air for the relative humidity sensor. It can be installed in every room to monitor temperature and humidity, check alarm sensors, control blind motor UP/DOWN, send notifications (using red and green leds) and activate white led in case of power outage.
Includes:
- temperature and relative humidity sensor
- red, green and white LEDs
- 4 I/Os configurable as analog or digital inputs, pushbuttons, counters (water, gas, S0 energy, ...), NTC temperature and ultrasonic distance sensors
- 2 ports are configured by default as open-drain output and can drive up to 200mA led strip (with dimming function) or can be connected to the external module DomRelay2 to control 2 relays; they can also be configured as analog/digital inputs, pushbuttons and distance sensors.
Very compact, versatile and cost-effective module with 9 ports. Each port can be configured by software as:
- analog/digital inputs
- pushbutton and UP/DOWN pushbutton
- counters (water, gas, S0 energy, ...)
- NTC temperature and ultrasonic distance sensors
- 2 ports are configured by default as open-drain output and can drive up to 200mA led strip (with dimming function) or can be connected to the external module DomRelay2 to control 2 relays.
Very compact domotic module providing:
- 3x latching relays SPST, max current 15A (3kW): no power consumption when relays are On or Off!
- 1x 230V AC opto-isolated input to detect 230V and power outage, with zero-detection to switch relays/loads minimizing in-rush current
- 4x I/O lines, configurable as analog/digital inputs, temperature/distance sensor, counter, meter, ...
Versatile module designed to control gate or garage door.
- 2x relays SPST 5A
- 1x 10A 30V mosfet (led stripe dimming)
- 2x 0-10V analog output: each one can be configured as open-drain output to control external relay
- 2x I/O lines, configurable as analog/digital inputs, temperature/distance sensor, counter, ...
- 2x low voltage AC/DC opto-isolated inputs, 9-40V
- 1x 230V AC opto-isolated input
DIN rail low profile module, with 8 relays and very low power consumption:
- 6x relays SPST 5A
- 2x relays STDT 10A
- Only 10mW power consumption with all relays OFF
- Only 500mW power consumption with all 8 relays ON !!
Versatile module with 230V inputs and outputs, and 5 low voltage I/Os.
- 3x relays SPST 5A
- 3x 115/230Vac optoisolated inputs
- Single common for relays and AC inputs
- 5x general purpose I/O, each one configurable as analog/digital inputs, pushbutton, counter, temperature and distance sensor.
Module designed to control 3 lights already existing and actually controlled by 230V pushbuttons and step-by-step relays. In this way each light can be activated by existing pushbuttons, and by the domotic controller.
- 3x relays SPST 5A
- 3x 115/230Vac optoisolated inputs
- Single common for relays and AC inputs
- 5x general purpose I/O, each one configurable as analog/digital inputs, pushbutton, counter, temperature and distance sensor.
Each relay can toggle the existing step-relay, switching the light On/Off. The optoisolator monitors the light status. The 5 I/Os can be connected to pushbuttons to activate or deactivate one or all lights.
DIN rail module, low profile, with 12 relays outputs and very low power consumption.
- 12x relays SPST 5A
- Relays are grouped in 3 blocks, with a single common per block, for easier wiring
- Only 12mW power consumption with all relays OFF
- Only 750mW power consumption with all 12 relays ON !!
Module designed to interface alarm sensors (magnetc contact sensors, PIRs, tampers): it's able to monitor mains power supply (power outage / blackout) and also have 3 relays outputs.
- 12x low voltage inputs (analog/digital inputs, buttons, alarm sensors, balanced double/triple biased alarm sensors, counters, meters, temperature and distance sensors, ...)
- 3x 115/230Vac optoisolated inputs
- 2x relays SPST 5A
- 1x relay SPST 10A
Module designed to interface alarm sensors (magnetc contact sensors, PIRs, tampers), lights and appliances outputs, ...
- 12x low voltage inputs (analog/digital inputs, buttons, alarm sensors, balanced double/triple biased alarm sensors, counters, meters, temperature and distance sensors, ...)
- 1x 115/230Vac optoisolated input to detect power outage and for zero-crossing detection (to switch relays minimizing the in-rush current)
- 4x relays SPDT 10A (with Normally Open and Normally Closed contacts)
- 2x relays SPST 10A (with only Normally Open contacts)
DomBusTracker - Dual axis sun tracker controller working with Domoticz, Home Assistant, Node-RED, Modbus, ... and also working in standalone with no external controllers
Module that check a deep-hole sun sensor to detect the direction of maximal sun radiation, working also in case of cloudy weather.
- Controls two external actuators/motors (linear or not) to move motors to reach the best tilt / elevation and azimuth position to optimize photovoltaic production.
- Check current through the motors to detect internal limit switch (useful for linear actuators) and find where the tracker reach the final/initial position.
- Works autonomously (stand-alone), without any home automation system controller, but also can be interface by Domoticz (DomBus protocol) and Home Assistant, NodeRED, OpenHAB, ... (using Modbus protocol).
- Wire connection (RS485) to the domotic controller for the best reliability.
Simple module with 2 relays, to be used with DomBus modules (like DomBusTH and DomBus12) or other electronic boards with open-collector or open-drain outputs
- 2x SPST relays 5A (Normally Open contact)
- Overvoltage protection (for inductive loads, like motors)
- Overcurrent protection (for capacitive laods, like AC/DC power supply, LED bulbs, ...)
IoT board designed for NodeMCU v3 board using ESP8266 WiFi microcontroller
- 9÷24V power supply input, with high efficiency DC/DC regulator with 5V output
- 4x SPST relays 5A with overvoltage protection (varistor)
- 2x mosfet outputs (max 30V, 10A) for LED dimming or other DC loads
- 1x I²C interface for sensors, extended I/Os and more)
- 1x OneWire interface (DS18B20 or other 1wire sensors/devices)