• Professional advice
  • Order before 16.30 uur shipped today
  • Almost always available (+31 73 762 0 762)
  • Monday open late

FIBARO HC2 ICY Thermostat integration

How to control your ICY (essent) E-thermostat from a HC2 

Since support of https calls it finally became possible to have you control your ICY thermostat from your HC2. Some coding lines are required and it works flawless but a plugin from FIBARO would work better.

ICY E-thermostat

This thermostat has been made popular by Essent (a power company in the netherlands) but is available to the public in your local DIY store. After having one all you need is a account at E-thermostaat to control it from your smartphone. It is a basic on/off thermostat but has a good programming capability, frost protection and motion detection. Since the arrival of HTTPS support in the FIBARO HC2 it is now possible to communicate with it

THE FIBARO HTTPS PROTOCOL

Unfortunatly the HTTPS protocol is only accesible from scenes or plugins. So unfortunatly for now, there is no way to do this from within a virtual device. That is a shame because it means creating multiple components to get it to work.

What we did to make it work:


-Created 2 global variables to store the security token and UID of your thermostat

-Created a Predefined Variable to store the 3 preset values

Predfined Variable

- Created a virtual device with 2 labels and 3 preset buttons. (click here for our .vfib)

Virtueel Apparaat

- Created a data collection scene (ID: 233 in my case)

- Created a scene to set the new temperature that is trigger by a change in the Predefined variable
 

HOW DOES THE VIRTUAL DEVICE WORK

In hte main loop of the virtual device every 300 seconds the data is collected and with that, if needed, a new security token is collected.

--Put the data scene ID in here
fibaro:startScene(233)

fibaro:sleep(300*1000)

Each button of the virtual device changes the Predefined variable to the correct setting, waits one second, then collects data to show the change. (This is the code for the 20C button)

fibaro:setGlobal("ICY", "20");
fibaro:sleep(1*1000)
fibaro:startScene(233);

THE SCENES

The first scene does most the work. It collects the data from your thermostat and gets your security token so that you are allowed to communicate with it

--[[
%% properties

%% globals
--]]


--Import the virtual ICY thermostat and look up the ID. Fill in Below
local VirtualICY = 112


--Fill in your login details for the ICY thermostat
local username='myICYusername'
local password='myICYpassword'


--This gets a security token from ICY
function GetToken()
        local http = net.HTTPClient({ timeout = 3000 })
        local message='username='..username..'&password='..password
        local controlHeaders = {['content-type'] = 'application/x-www-form-urlencoded'}
        http:request('https://portal.icy.nl/login', {
        options = {
                    headers = {
                      ['content-type'] = 'application/x-www-form-urlencoded',
                      },
                    method = 'POST',
                    data=message
               },
        success = function(param)
                if param.status == 200 then
                print('Succes STATUS: ', param.status)
                  local responds = json.decode(param.data)
                  local token = responds.token
                  local serialthermostat1 = responds.serialthermostat1
                  fibaro:setGlobal('ICYuid',serialthermostat1)
                  fibaro:setGlobal('IcyToken',token)
                end
        end,
        error = function(error)      end
        })
end


--This reads the details of the current settings
function ReadData()
          local SecurityToken = fibaro:getGlobal('IcyToken')
          
        local http = net.HTTPClient({ timeout = 3000 })
        local request_body=''

        http:request('https://portal.icy.nl/data', {
        options = {
                    headers= {
            ['content-type'] = 'application/x-www-form-urlencoded',
            ['session-token'] = SecurityToken,
            },
                    method = 'GET',
                    data=request_body
               },
      
        success = function(param)
        if param.status == 200 then
                print('Data Receiving: ', param.status)
                  local json_input = json.decode(param.data)
                local temperature1 = json_input.temperature1
                    print('Set temp: ', temperature1)
                fibaro:call(VirtualICY, "setProperty", "ui.TempSet.value",temperature1)
                temperature2 = json_input.temperature2
                    print('Current temp: ',temperature2)
                  fibaro:call(VirtualICY, "setProperty", "ui.TempNow.value",temperature2);
                  serial = json_input.serialthermostat1
        elseif param.status == 401 then
              --This is where we need to get a new token
            GetToken()
          end
        end,
        error = function(error)      end
        })

end

ReadData()

The second scene sends the new setpoint temperature to your thermostat and is triggered automatically by a change in the predefined variable.

--[[
%% properties
%% globals
ICY
--]]

function setTemp(targettemp)
        local serialthermostat1 = fibaro:getGlobal('ICYuid')
        local SecurityToken = fibaro:getGlobal('IcyToken')

              local request_body= 'uid=' .. serialthermostat1
              message = request_body .. '&temperature1=' .. targettemp
              print(message)
              local data_length = string.len(message)
              print(data_length)
            local http = net.HTTPClient({ timeout = 3000 })

            http:request('https://portal.icy.nl/data', {
            options = {
                    headers= {
            ['content-type'] = 'application/x-www-form-urlencoded',
            ['session-token'] = SecurityToken,
            },
                    method = 'POST',
                    data=message
               },

        success = function(param)
        fibaro:debug(json.encode(param))
        if param.status == 200 then
                print('Data Receiving: ', param.status)
                  --print(param.data)
--                  local json_input = json.decode(param.data)
--                temperature1 = json_input.temperature1
--                    print('Set temp: ', temperature1)
--                temperature2 = json_input.temperature2
--                    print('Current temp: ',temperature2)
                
          end
        end,
        error = function(error)      end
        })

end
NewTemp = fibaro:getGlobalValue("ICY")
setTemp(NewTemp)

 

And from now on your thermostat can be controlled from your HC2

Any feedback is welcome

ROBBshop

 

 

There are no products matching the selection.

 
Customer Service Phone

+31737620762
mon-fri: 10am-5pm and sat 10am-3pm

 
Adress

Gerstakker 16 5236 VG Empel Netherlands

Google maps