Sensibo through dzVents  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensibo through dzVents

Post 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
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
remcod
Posts: 2
Joined: Wednesday 30 September 2020 15:50
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Sensibo through dzVents

Post by remcod »

Thanks! problem solved. I added temperature as virtual switch and it had to be an virtual thermostat.
Thank you for the support!
delius
Posts: 11
Joined: Monday 02 January 2017 16:44
Target OS: Linux
Domoticz version: beta
Location: Netherlands
Contact:

Re: Sensibo through dzVents

Post 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
delius
Posts: 11
Joined: Monday 02 January 2017 16:44
Target OS: Linux
Domoticz version: beta
Location: Netherlands
Contact:

Re: Sensibo through dzVents

Post 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&param=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&param=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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensibo through dzVents

Post 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

Code: Select all

dz.utils.dumpTable(item.json)

directly after line

Code: Select all

 if (item.isJSON) then
And share the log, I might be able to show how you can access the data using native dzVents / Lua
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
delius
Posts: 11
Joined: Monday 02 January 2017 16:44
Target OS: Linux
Domoticz version: beta
Location: Netherlands
Contact:

Re: Sensibo through dzVents

Post by delius »

waaren wrote: Thursday 25 March 2021 14:07
If you add

Code: Select all

dz.utils.dumpTable(item.json)

directly after line

Code: Select all

 if (item.isJSON) then
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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensibo through dzVents

Post 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

Code: Select all

 if (item.isJSON) then
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sensibo through dzVents

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest