Page 2 of 2
Re: Sensibo through dzVents
Posted: Monday 05 October 2020 21:25
by waaren
remcod wrote: ↑Monday 05 October 2020 20:16
2020-10-05 20:22:50.976 Status: dzVents: Error (2.4.19): /usr/local/domoticz/dzVents/runtime/Domoticz.lua:172: attempt to perform arithmetic on local 'x' (a nil value)
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
}
Re: Sensibo through dzVents
Posted: Tuesday 06 October 2020 14:23
by remcod
Thanks! problem solved. I added temperature as virtual switch and it had to be an virtual thermostat.
Thank you for the support!
Re: Sensibo through dzVents
Posted: Tuesday 23 March 2021 8:32
by delius
stupid question. How do I make a thermostat type switch? The other three are logical, but I don't see a thermostat in my type selection list.
Nevermind: found it
Re: Sensibo through dzVents
Posted: Thursday 25 March 2021 12:22
by delius
I made a second script that fills two dummy temperature / humidity sensors with the values of my Sensibo Sky devices. The script needs a dummy temperature and a dummy humidity sensor. You need to fill the
xxx with your own values.
Code: Select all
return
{
on =
{
timer =
{
'every 30 minutes',
},
httpResponses =
{
'trigger',
},
},
-- logging = { level = domoticz.LOG_DEBUG , },
execute = function(dz, item)
function extract_json( tbl )
local checklist = {}
local function innerdump( tbl, indent )
checklist[ tostring(tbl) ] = true
for k,v in pairs(tbl) do
if (k == "humidity") then
dz.openURL({
url = 'http://xxx.xxx.xxx.xxx:xxxx/json.htm?type=command¶m=udevice&idx=xxx&nvalue='..v,
method = 'GET',
callback = 'trigger',
})
end
if (k == "temperature") then
dz.openURL({
url = 'http://xxx.xxx.xxx.xxx:xxx/json.htm?type=command¶m=udevice&idx=xxx&nvalue=0&svalue='..v,
method = 'GET',
callback = 'trigger', -- see httpResponses above.
})
end
if (type(v) == "table" and not checklist[ tostring(v) ]) then
innerdump(v,indent .. tostring(k) .. ".")
end
end
end
checklist[ tostring(tbl) ] = true
innerdump( tbl, "Key: " )
end
local json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local device_id = 'xxxxxxxx'
local api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
if item.isTimer then
dz.openURL({
url = 'https://home.sensibo.com/api/v2/pods/'..device_id..'/measurements?apiKey='..api_key,
method = 'GET',
callback = 'trigger',
})
end
if (item.isHTTPResponse) then
if item.ok then
if (item.isJSON) then
local ACInfo = json:decode(item.data)
extract_json(ACInfo)
elseif LOGGING == true then
print('There was a problem handling the request', dz.LOG_ERROR)
print(item, dz.LOG_ERROR)
end
end
end
end
}
I struggled a lot with the LUA - JSON combination. Hence the somewhat wonderful extract_json loop. If someone succeeds in picking the correct value directly from the JSON, please let me know.
Re: Sensibo through dzVents
Posted: Thursday 25 March 2021 14:07
by waaren
delius wrote: ↑Thursday 25 March 2021 12:22
I struggled a lot with the LUA - JSON combination. Hence the somewhat wonderful extract_json loop. If someone succeeds in picking the correct value directly from the JSON, please let me know.
If you add
directly after line
And share the log, I might be able to show how you can access the data using native dzVents / Lua
Re: Sensibo through dzVents
Posted: Friday 26 March 2021 9:27
by delius
waaren wrote: ↑Thursday 25 March 2021 14:07
If you add
directly after line
And share the log, I might be able to show how you can access the data using native dzVents / Lua
I've tried, but that's part of the problem. dumpTable does not output. Actually all JSON functions do not output, hence the strange construction.
Re: Sensibo through dzVents
Posted: Friday 26 March 2021 10:20
by waaren
delius wrote: ↑Friday 26 March 2021 9:27
I've tried, but that's part of the problem. dumpTable does not output. Actually all JSON functions do not output, hence the strange construction.
OK. Can you then please try to add
Code: Select all
dz.utils.dumpTable(item.data)
dz.utils.dumpTable(globalvariables)
dz.log(package.path, dz.LOG_FORCE)
directly after line
Re: Sensibo through dzVents
Posted: Friday 26 March 2021 12:23
by waaren
rolandtwilt wrote: ↑Friday 26 March 2021 11:34
friends of automation, I have a Blocky script and there is a decent delay here at 34 seconds to be exact.
Post moved to Blockly subtopic.
@rolandtwilt Please do not hijack another unrelated topic for this. Thx