I guess the setPoint cannot be found so the round function will fail. I added some extra log to below script.
Can you try it and show ALL loglines from one execution of this script?
Code: Select all
return {
on = {
devices = { 'Airco', 'Airco temperatuur', 'Airco fan', 'Airco mode' },
httpResponses = { 'Airco' } -- matches callback string below
},
logging =
{
level = 'domoticz.LOG_DEBUG',
marker = 'Sensibo',
},
execute = function(domoticz, triggerItem)
local device_id = 'yyyyy' -- change to id of salon
local api_key = 'zzzzz' -- change to API key
--define related switches
local ac_state = domoticz.devices('Airco')
local ac_mode = domoticz.devices('Airco mode')
local ac_fan_level = domoticz.devices('Airco fan')
local ac_salon_termo = domoticz.devices('Airco temperatuur')
domoticz.log(tostring(ac_salon_termo.setPoint), domoticz.LOG_DEBUG)
if ac_salon_termo.setPoint == nil then
domoticz.log('setPoint not found. Will set it to 19 ', domoticz.LOG_ERROR)
end
local function boo() -- the on parameter must be passed as a boolean. This function does that
if ac_state.state == 'On' then
return true
else
return false
end
end
--get the levels from the related switches
local acmode = ac_mode.levelName
local flevel = ac_fan_level.levelName
local set_temp = domoticz.utils.round((ac_salon_termo.setPoint or 19), 0)
preppostData = {
acState = {
on = boo(),
targetTemperature = set_temp,
mode = acmode,
fanLevel = flevel
}
}
--domoticz.utils.dumpTable(preppostData)
if (triggerItem.isDevice) then
domoticz.openURL({
url = 'https://home.sensibo.com/api/v2/pods/'..device_id..'/acStates?apiKey='..api_key,
method = 'POST',
callback = 'Airco',
postData = preppostData
})
elseif (triggerItem.isHTTPResponse) then
local response = triggerItem
if (response.ok and response.isJSON) then
print('Command sent OK to Airco')
else
print('**Airco failed to fetch info')
end
end
end
}