Re: Daikin Hardware
Posted: Wednesday 11 November 2020 19:44
hello
Yes i have exactly that
but how to get a selector switch after?
Yes i have exactly that
but how to get a selector switch after?
Hi
Hello can i get some help please?
Code: Select all
return
{
--[[
Show hourly energy consumption from Daikin web server
Daikin clock is sync via Internet
Daikin web server send values after *:00
For call at 00:05 -> value to be extract from yesterday array
So, we have a 1 hour decay on the graph. To be exact, it will be necessary to update last value in sql base ....
doc : https://www.domoticz.com/forum/viewtopic.php?f=34&t=21126&sid=6eef839efc599b4eb44db319e1435060&start=20
from "yomark" 10/11/2020
Modify Ph Marsault 25/11/2020
]]--
on =
{
timer = { 'at *:05' },
httpResponses = { 'energyRetrievedRoom_1' }
},
logging =
{
--level = domoticz.LOG_DEBUG, -- for debugging
level = domoticz.LOG_INFO,
marker = "Daikin energy"
},
execute = function (dz, item)
local IP_Daikin = '192.168.2.121'
local Idx_device = 99
-- Retrieve in a neat way via HTTP
if (item.isTimer) then
dz.openURL({
url = 'http://'..IP_Daikin..'/aircon/get_day_power_ex',
method = 'GET',
callback = 'energyRetrievedRoom_1'
})
elseif (item.isHTTPResponse) then
if (item.ok) then -- statusCode == 2xx
local HTTPRaWData = item.data
-- Example (1 line) :
-- ret=OK,
-- curr_day_heat=0/0/1/3/2/5/4/4/5/15/19/14/6/1/3/2/3/4/6/5/5/5/0/0,
-- prev_1day_heat=0/0/1/2/3/4/5/4/6/5/5/4/4/3/3/3/2/3/4/4/4/4/4/7,
-- curr_day_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0,
-- prev_1day_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0
local firstSplit = dz.utils.stringSplit(HTTPRaWData,',') -- split the response string on comma -> one assignment per row
local results = {}
for _, row in ipairs(firstSplit) do
local hTable = dz.utils.stringSplit(row,'=') -- split every row into a helper table containing a key and a value
local key = hTable[1]
local value = tonumber(hTable[2]) or hTable[2] -- store value as number when possible. If not store as string
results[key] = hTable[2]
-- dz.log ('key ->'..key..'<- hTable[2] ->'..results[key])
end
-- Split the words at the top further with function.
local arrayTodayHeat = dz.utils.stringSplit(results["curr_day_heat"],'/') -- Contain 24 values energy today heating
local arrayLastDayHeat = dz.utils.stringSplit(results["prev_1day_heat"],'/') -- Contain 24 values energy yesterday heating
local arrayTodayCool = dz.utils.stringSplit(results["curr_day_cool"],'/') -- Contain 24 values energy today cooling
local arrayLastDayCool = dz.utils.stringSplit(results["prev_1day_cool"],'/') -- Contain 24 values energy yesterday cooling
local LastHour = dz.time.hour
local LastHourHeat =0
local LastHourCool =0
local LastHourWatth=0
if (LastHour == 0) then
-- this call is just after midnight to the energy between 23h and 24h yesterday
-- So values are now in yesterday arrays
-- last value updated
LastHourHeat = arrayLastDayHeat[24] * 100 -- convert to Wh (Number w count each 100W)
LastHourCool = arrayLastDayCool[24] * 100 -- convert to Wh (Number w count each 100W)
else
-- call for energy between 0h and 23h (last today call is at 23h05)
-- last value updated
LastHourHeat = arrayTodayHeat[LastHour] * 100 -- convert to Wh (Number w count each 100W)
LastHourCool = arrayTodayCool[LastHour] * 100 -- convert to Wh (Number w count each 100W)
end
-- dz.log('LastHour ->'..LastHour..' - LastHourHeat ->'..LastHourHeat)
-- Total with Heat and Cool
LastHourWatth = LastHourHeat + LastHourCool
-- Time / Hour
-- Update device
local DaikinConsumptionRoom_1 = dz.devices(Idx_device) -- Electric Dummy Counter
local NewTotal = DaikinConsumptionRoom_1.WhTotal + LastHourWatth
-- args : updateElectricity ( Power , Energy )
DaikinConsumptionRoom_1.updateElectricity ( LastHourWatth , NewTotal )
else
dz.notify('Unsuccesful connection airco sensor')
end
end
end
}
Code: Select all
return
--[[
Daikin PID controller with an independent temperature sensor and a virtual thermostat
SETPOINT stemp MUST BE ROUNDED by half degree for command, example :
http://192.168.x.xxx/aircon/set_control_info?pow=1&mode=4&f_rate=A&f_dir=2&stemp=21.5&shum=0
Tested on a FTXM50N Prefera
Dependencies :
Dummy device -> Thermostat set point
Dummy device -> Switch On/Off
Device temperature -> reference room temperature (NOT internal Daikin temerature)
Optional for tests :
Dummy device -> Custom sensor axis "°C" (PID_prop)
Dummy device -> Custom sensor axis "°C*mn" (PID_sum)
Dummy device -> Custom sensor axis "°C/mn" (PID_diff)
doc :
https://www.domoticz.com/forum/viewtopic.php?f=34&t=21126&sid=6eef839efc599b4eb44db319e1435060&start=20
https://www.domoticz.com/wiki/DzVents:_next_generation_Lua_scripting
https://en.wikipedia.org/wiki/PID_controller
https://www.domoticz.com/wiki/Daikin_wifi
https://www.domoticz.com/wiki/Plugins/Smart_Virtual_Thermostat.html
Philippe Marsault 29/11/2020
]]--
{
active = true,
on = {
timer = {'every 5 minutes'},
httpResponses = {'Read_Daikin'}
},
data =
{
h_delta_T = { history = true, maxItems = 10 }
},
-- logging =
-- {
-- level = domoticz.LOG_DEBUG, -- for debugging
-- -- level = domoticz.LOG_INFO,
-- marker = "Daikin control"
-- },
execute = function(dz, item)
function round(x)
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
local IP_Daikin = '192.168.2.121'
local Idx_sonde_T = 93 -- reference room temperature
local Idx_thermostat = 103 -- Room thermostat
local Idx_ther_OnOff = 100 -- Global swith for this script, example : use for holidays
local Daikin_set_max = 25 -- Set point internal temperature max for Daikin
local Daikin_set_min = 15 -- Set point internal temperature min for Daikin
local Idx_ecart_T = 104 -- Delta Room thermostat
local Idx_PID_sum = 105 -- PID_sum -> for test (not necessary)
local Idx_PID_prop = 106 -- PID_prop -> for test (not necessary)
local Idx_PID_diff = 107 -- PID_diff -> for test (not necessary)
local Idx_ther_Daikin = 102 -- Internal Daikin set point -> for test (not necessary)
-- from test -> Ku de l'ordre de 1.2
-- from test -> oscillation period Tu ~ 240 mn
local Kp = 0.6 -- PID coefficient proportionnal (Kp=Ku*0.60)
local Ki = 0.006 -- PID coefficient integral (1.2*Ku/Tu)
local Kd = 21.6 -- PID coefficient differential (3*Ku*Tu/40)
local ther_OnOff = dz.devices(Idx_ther_OnOff).state -- Read thermostat control switch On-Off
-- if is polling time and control switch is ON
if ((item.isTimer) and (ther_OnOff == 'On' )) then
dz.openURL({
url = 'http://'..IP_Daikin..'/aircon/get_control_info',
callback = 'Read_Daikin',
})
elseif (item.isHTTPResponse and (item.trigger == 'Read_Daikin') ) then
-- this section : receive HTTPResponse for the command Read_Daikin
-- if (item.trigger == 'loggedin') then
if item.ok then -- self.statusCode >= 200 and self.statusCode <= 299 : response is OK
dz.log('get_control_info : Succesful connection for Read_Daikin')
-- dz.log(item.data)
local ther_setpoint = dz.devices(Idx_thermostat).setPoint -- Read thermostat set point
local room_temperature = dz.devices(Idx_sonde_T).temperature -- Read room temperature
-- dz.log('room_temperature ->'..room_temperature)
local response = item.data
local firstSplit = dz.utils.stringSplit(response,',') -- split the response string on comma -> one assignment per row
local results = {}
for _, row in ipairs(firstSplit) do
local hTable = dz.utils.stringSplit(row,'=') -- split every row into a helper table containing a key and a value
local key = hTable[1]
local value = tonumber(hTable[2]) or hTable[2] -- store value as number when possible. If not store as string
results[key] = value
end
Daikin_setpoint = results.stemp -- actual setpoint stored by Daikin server
-- dz.log ('Daikin_setpoint read from Daikin ->'..Daikin_setpoint)
-- dz.devices(Idx_ther_Daikin).updateTemperature(Daikin_setpoint) -- Sync Daikin internal set point and Domotocz setpoint
local fanDir_Daikin = tostring(results.f_dir) -- read actual fan dir
local mode_Daikin = tostring(results.mode) -- read actual mode (heat or cool or auto)
-- Delta temperature between reference room and Domoticz thermostat set point
-- adding value to the historical variable
dz.data.h_delta_T.add(room_temperature - ther_setpoint)
local delta_T = dz.data.h_delta_T.get(1).data -- newest value in the historical table
-- dz.log ('delta_T ->'..delta_T)
-- PID variables
local PID_sum = dz.data.h_delta_T.sum()*5 -- like integral value
local PID_prop = delta_T -- like proportionnal value
local PID_num = dz.data.h_delta_T.size
local PID_diff = 0
if PID_num > 3 then
PID_diff = (dz.data.h_delta_T.get(1).data - dz.data.h_delta_T.get(3).data)*0.1 -- like différential value
end
local delta_T_PID = Kp*PID_prop + Ki*PID_sum + Kd*PID_diff
-- Optional for tests
dz.devices(Idx_PID_sum).updateCustomSensor(PID_sum) -- Update Custom sensor coeff in Domotocz
dz.devices(Idx_PID_prop).updateCustomSensor(PID_prop) -- Update Custom sensor coeff in Domotocz
dz.devices(Idx_PID_diff).updateCustomSensor(PID_diff) -- Update Custom sensor coeff in Domotocz
dz.devices(Idx_ecart_T).updateCustomSensor(delta_T_PID) -- Update Custom sensor in Domotocz PID calculé
-- Apply delta_T to the old Daikin internal set point
local Daikin_setpoint = Daikin_setpoint - delta_T_PID
Daikin_setpoint = round(Daikin_setpoint*2)*0.5 -- MUST BE ROUNDED by half degree step
dz.log ('Daikin_setpoint with delta ->'..Daikin_setpoint)
Daikin_setpoint = math.min(Daikin_setpoint,Daikin_set_max) -- limit max
Daikin_setpoint = math.max(Daikin_setpoint,Daikin_set_min) -- limit min
local c_stemp = string.format("%.1f", Daikin_setpoint) -- string set point for Daikin command
-- build command string
-- http://192.168.2.121/aircon/set_control_info?pow=1&mode=4&f_rate=A&f_dir=2&stemp=24.0&shum=0
local command_setpoint = 'http://'..IP_Daikin..'/aircon/set_control_info?pow=1&mode='..mode_Daikin..'&f_rate=A&f_dir='..fanDir_Daikin..'&stemp='..c_stemp..'&shum=0'
-- dz.log ('command_write setpoint ->'..command_setpoint)
dz.openURL({url = command_setpoint}) -- send command to Daikin server
-- Optional for tests
Daikin_setpoint = tonumber(c_stemp) -- value convert to number for Domoticz screen
dz.devices(Idx_ther_Daikin).updateTemperature(Daikin_setpoint) -- Update Daikin internal set point in Domotocz
-- dz.log ('Daikin_setpoint limited ->'..Daikin_setpoint)
else
dz.log('get_control_info : Unsuccesful connection for Read_Daikin')
end
end
end
}