ESPEasy Aircondition Inverter IR control

From Domoticz
Jump to navigation Jump to search

Purpose

With this script you will be able to control your heatpump supported by toniA's heatpumpir library. Check his lib to see supported heatpumps / AC https://github.com/ToniA/arduino-heatpumpir You shall use ESPEASY that also contains Toni's heatpumpir plugin, I have also added 1 pcs DS18B20, so I am able to monitor airtemp blown out from heatpump

Hardware

Wemos D1 Mini Pro

USB power supply

940nm IR LED

100 Ohm resister

DS18B20

Cables and pinheader connectors

Software

ESPEASY: http://www.letscontrolit.com/wiki/index.php/ESPEasy

Download heatpumpIr lib: https://github.com/ToniA/arduino-heatpumpir

I use Arduino IDE, Compile it all and upload your firmware to the Wemos D1 Mini Pro

Check heatpumpIR

How to add this ESPEASY to your own wifi is not in this scope and can be found in ESPEASY help pages

ESPEASY shall look like this, depending of your chosen GPIO pins

Since I use Wemos D1 Mini Pro, use GPio 16 -> D0 on the actual Wemos D1 Mini Pro, if you choose to other GPIO pin, then compare here: Wemos D1 Mini Pro


Check that you are able to control your heatpump from a webbrowser: I have an IVT model

switch on: http://192.168.1.2/control?cmd=heatpumpir,ivt,1,2,1,24,0,0

Switch off: http://192.168.1.2/control?cmd=heatpumpir,ivt,0,2,1,24,0,0

If you are able to control heatpump from the webrowser then you can control it from domoticz

Dummy devices in Domoticz

Notice that LUA scripts are case sensitive, so you need to pay attention to spelling, "AC Fan Speed" is not same as "ac fan speed"

IVT temperature is not really needed, but I have added 1 pcs DS18B20, create a dummy device and put it to a temperature sensor, remember the IDX number, which you add to ESPEASY, in my setup it's idx120.

All 3 devices shall be created as dummy devices like those pics show

Then you should get those below devices

LUA script to control heatpumpIR

--[[
Script created by hpapagaj and modified by bjacobse
to use with ToniA's heatpumpir lib + ESpeasy and _P115_heatpumpir 

Create the following dummy switches (Note that LUA are case sensitiv):
'AC Mode''AC Fan Speed''AC Set Temperature'

and if your AC/heatpoump support then also create:
'AC Hor dir''AC Vert dir'
And add -- in front of line 27. And remove -- in line 29


 https://github.com/ToniA/arduino-heatpumpir/blob/master/HeatpumpIR.h


Changelog:
 
    Version 1.0, 2017 January
    - Initial release
]]

--Set espeasy heatpump IP address
local ipadress = '192.168.2.6'
local model = 'ivt'

commandArray = {}
for key, value in pairs(devicechanged) do
  --if (key == 'AC Mode' or key == 'AC Fan Speed' or key == 'AC Set Temperature' or key == 'AC Hor dir' or key == 'AC Ver dir') then
  if (key == 'AC Mode' or key == 'AC Fan Speed' or key == 'AC Set Temperature') then

    print ("HeatpumpIR event started")


-- Power mode is ON if operating modes are in use
--// Power state
--#define POWER_OFF   0
--#define POWER_ON    1
    local power = 1


--// Operating modes
--#define MODE_AUTO   1
--#define MODE_HEAT   2
--#define MODE_COOL   3
--#define MODE_DRY    4
--#define MODE_FAN    5
--#define MODE_MAINT  6
    local mode = 2
    if (otherdevices['AC Mode']) == 'Off' then
        mode = 0
        power = 0
    elseif (otherdevices['AC Mode'] == 'Auto') then
        mode = 1        
    elseif (otherdevices['AC Mode'] == 'Heat') then
        mode = 2        
    elseif (otherdevices['AC Mode'] == 'Cool') then
        mode = 3        
    elseif (otherdevices['AC Mode'] == 'Dry') then
        mode = 4        
    elseif (otherdevices['AC Mode'] == 'fan') then
        mode = 5        
    elseif (otherdevices['AC Mode'] == 'Maint') then
        mode = 6        
    end

--print (otherdevices_svalues['AC mode'])
 --for i, v in pairs(devicechanged) do print(i, v) end

--// Fan speeds. Note that some heatpumps have less than 5 fan speeds
--#define FAN_AUTO    0
--#define FAN_1       1
--#define FAN_2       2
--#define FAN_3       3
--#define FAN_4       4
--#define FAN_5       5
    local fan = 1
    if (otherdevices['AC Fan Speed']) == 'Auto' then
        fan = 0
    elseif (otherdevices['AC Fan Speed']) == '1' then
        fan = 1        
    elseif (otherdevices['AC Fan Speed']) == '2' then
        fan = 2        
    elseif (otherdevices['AC Fan Speed']) == '3' then
        fan = 3        
    elseif (otherdevices['AC Fan Speed']) == '4' then
        fan = 4        
    elseif (otherdevices['AC Fan Speed']) == '5' then
        fan = 5
    end

--Set temperature
    local settemperature = 23
    settemperature = tonumber(otherdevices['AC Set Temperature'])


--// Vertical air directions. Note that these cannot be set on all heat pumps
--#define VDIR_AUTO   0
--#define VDIR_MANUAL 0
--#define VDIR_SWING  1
--#define VDIR_UP     2
--#define VDIR_MUP    3
--#define VDIR_MIDDLE 4
--#define VDIR_MDOWN  5
--#define VDIR_DOWN   6
    local verdir = 0
    if (otherdevices['AC Ver dir']) == 'Auto' then
        verdir = 0
    elseif (otherdevices['AC Ver dir']) == 'Manual' then
        verdir = 0        
    elseif (otherdevices['AC Ver dir']) == 'Swing' then
        verdir = 1        
    elseif (otherdevices['AC Ver dir']) == 'Up' then
        verdir = 2        
    elseif (otherdevices['AC Ver dir']) == 'Mup' then
        verdir = 3        
    elseif (otherdevices['AC Ver dir']) == 'Middle' then
        verdir = 4        
    elseif (otherdevices['AC Ver dir']) == 'Mdown' then
        verdir = 5
    elseif (otherdevices['AC Ver dir']) == 'Down' then
        verdir = 6
    end


--// Horizontal air directions. Note that these cannot be set on all heat pumps
--#define HDIR_AUTO   0
--#define HDIR_MANUAL 0
--#define HDIR_SWING  1
--#define HDIR_MIDDLE 2
--#define HDIR_LEFT   3
--#define HDIR_MLEFT  4
--#define HDIR_MRIGHT 5
--#define HDIR_RIGHT  6
    local hordir = 0
    if (otherdevices['AC Hor dir']) == 'Auto' then
        hordir = 0
    elseif (otherdevices['AC Hor dir']) == 'Manual' then
        hordir = 0        
    elseif (otherdevices['AC Hor dir']) == 'Swing' then
        hordir = 1        
    elseif (otherdevices['AC Hor dir']) == 'Middle' then
        hordir = 2        
    elseif (otherdevices['AC Hor dir']) == 'Left' then
        hordir = 3        
    elseif (otherdevices['AC Hor dir']) == 'Mleft' then
        hordir = 4        
    elseif (otherdevices['AC Hor dir']) == 'Mright' then
        hordir = 5
    elseif (otherdevices['AC Hor dir']) == 'Right' then
        hordir = 6
    end
 

    print ("HeatpumpIR event transmitted")

    print ('http://' ..ipadress.. '/control?cmd=heatpumpir,' .. model..','..power..','..mode..','..fan..','..settemperature..','..verdir..','..hordir)
    commandArray['OpenURL'] = 'http://' ..ipadress.. '/control?cmd=heatpumpir,' .. model..','..power..','..mode..','..fan..','..settemperature..','..verdir..','..hordir
    end
end
return commandArray