Domoticz smart thermostat

From IOT4
Jump to navigation Jump to search

Create a virtual device:

Name: Thermo 
Sensor type: Thermostat setpoint

Thermo setpoint.png

Choose a IOT4SH01DS device for temperature sensor, in my case named it 'Nappali'.

Thermo nappali.png

Choose a IOT4SH01Relay device for controlling the central heating unit, in my case named 'futes'.

Thermo switch.png

In the Setup-> More options -> Events

Thermo events.png

Insert this code:

-- Domoticz passes information to scripts through a number of global tables

local heating_probe = 'Nappali' 
local thermostat_setpoint = 'Thermo'
local heating_unit = 'futes'

-- Use when a combined sensor (e.g. temperature and humidity) is used
-- Replace in "otherdevices[heating_probe]" to "otherdevices[heating_probe]" by "temp_only" (in the 2nd "if" and in the "elseif".
-- Remove the -- in the next two lines: 

--local naartekst = (tostring (otherdevices[heating_probe]))
--local temp_only = (string.sub(naartekst,1,4)) -- the digits (1,4) do point out what characters of the string are needed.

local hysteresis = 0.1

commandArray = {}

-- loop through all the devices
for deviceName,deviceValue in pairs(otherdevices) do
    if (deviceName== thermostat_setpoint ) then

        if tonumber(deviceValue) < tonumber(otherdevices[heating_probe]-hysteresis) then
            if (otherdevices[heating_unit] == "On") then
             --   commandArray['SendNotification']='Heating is off'
                print("Heating is Off")
        elseif tonumber(deviceValue) > tonumber(otherdevices[heating_probe]+hysteresis) then
            if (otherdevices[heating_unit] == "Off") then
            --    commandArray['SendNotification']='Heating is on'
                print("Heating is On")

-- loop through all the variables
for variableName,variableValue in pairs(uservariables) do


return commandArray

The event type set to Lua and set the event to active.

If you remove the -- (lua remark) before the commandArray['SendNotification'] lines the Domoticz will be notify heating status changes.

If you want can use higher hysteresis than 0.1 celsius, just simply modify the Lua code.

Thermo lua.png

When this all is ready you can simply set desired temperature with the Utility device thermo temperature.

Thermo set.png

On this device can set timers to change the temperature on time:

Thermo timers.png

And if you have installed the Homebridge can set the temperature with Siri .