Domoticz smart thermostat: Difference between revisions

From IOT4
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:
[[File:Thermo nappali.png|1000px]]
[[File:Thermo nappali.png|1000px]]


Choose a IOT4SH01Relay device for controlling the central heating unit, in my case named 'futes'.
[[File:Thermo_switch.png|1000px]]
In the Setup-> More options -> Events
[[File:Thermo_events.png|1000px]]
Insert this code:


<source lang=lua>
<source lang=lua>
--
-- Domoticz passes information to scripts through a number of global tables
--
--
--
--
-- https://www.iot4.eu/wiki
local heating_probe = 'Nappali'  
local heating_probe = 'Nappali'  
local thermostat_setpoint = 'Thermo'
local thermostat_setpoint = 'Thermo'
Line 23: Line 40:
for deviceName,deviceValue in pairs(otherdevices) do
for deviceName,deviceValue in pairs(otherdevices) do
     if (deviceName== thermostat_setpoint ) then
     if (deviceName== thermostat_setpoint ) then
  --      print ("All based event fired1");
 
      --  print(deviceValue .. "-" ..otherdevices[heating_probe])
        if tonumber(deviceValue) < tonumber(otherdevices[heating_probe]-hysteresis) then
          
          
        if tonumber(deviceValue) < tonumber(otherdevices[heating_probe]-hysteresis) then
           
             if (otherdevices[heating_unit] == "On") then
             if (otherdevices[heating_unit] == "On") then
             --  commandArray['SendNotification']='Heating is off'
             --  commandArray['SendNotification']='Heating is off'
Line 35: Line 50:
              
              
         elseif tonumber(deviceValue) > tonumber(otherdevices[heating_probe]+hysteresis) then
         elseif tonumber(deviceValue) > tonumber(otherdevices[heating_probe]+hysteresis) then
            -- commandArray['a device name'] = "On"
            -- commandArray['Scene:MyScene'] = "Off"
             if (otherdevices[heating_unit] == "Off") then
             if (otherdevices[heating_unit] == "Off") then
                 commandArray[heating_unit]='On'
                 commandArray[heating_unit]='On'
Line 48: Line 61:
-- loop through all the variables
-- loop through all the variables
for variableName,variableValue in pairs(uservariables) do
for variableName,variableValue in pairs(uservariables) do
--    if (variableName=='myVariable') then
 
--        if variableValue == 1 then
--            commandArray['a device name'] = "On"
--            commandArray['Group:My Group'] = "Off AFTER 30"
--        end
--    end
end
end


Line 59: Line 67:


</source>
</source>
The event type set to Lua and set the event to active.
[[File:Thermo lua.png|1000px]]

Revision as of 19:16, 23 May 2017

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
--
--
-- 
--
-- https://www.iot4.eu/wiki

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

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

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

end

return commandArray

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

Thermo lua.png