Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Http Request for Sensibo don't work in VD


cuong.mhome

Question

Dear all, 

Pls help me for situation.

 

I'm try to intergate Sensibo (Smart IR for Air Conditioner),

But I got the problem when connect via Fibaro Virtual Device as:

 

1. With Web Browser it work.

Please login or register to see this link.

 

2. But I don't how to it work in FIBARO Virtual Device, I tried but it error?

 

local http = Net.FHttp("home.sensibo.com",80);
----------------------------------------
local Command  = '/api/v2/users/me/pods?fields=*&apiKey=O7LHDg0TID80NUyY0xqaqlGGlycqfg';

response ,status, errorCode  = http:GET(Command);

fibaro:debug(response);
fibaro:debug(status);
fibaro:debug(errorCode);

 

=> Error: 

[DEBUG] 18:46:21:
403 Forbidden
nginx

Link to comment
Share on other sites

Recommended Posts

  • 0

Hi All,

Need some help with the code:

Please login or register to see this link.

********** ( with my one key it get a all information)
In the code of the Scene I see the Next things:
local http = net.HTTPClient()  
  http:request('https://home.sensibo.com/api/v2/pods/'    << it's diffrent 

Because I doesn't work for me now

Link to comment
Share on other sites

  • 0

Found de issue: If you looking for the Device

Please login or register to see this attachment.

ID you need it pick it up from the webpage, not on the pakket.

Edited by morsink
Link to comment
Share on other sites

  • 0

Need help

 

[DEBUG] 23:13:30: nil
[DEBUG] 23:13:30: 2022-07-17 23:13:30.269814 [ fatal] Unknown exception: /opt/fibaro/scenes/37.lua:140: attempt to concatenate local 'value' (a nil value)

Link to comment
Share on other sites

  • 0

Upated code:
 

local apiKey = "SensiboAPI"
local LinkVitualDeviceId = VD id
local SensiboDeviceId = "SensiboID"

function Main()
      strCmd = fibaro:getValue(LinkVitualDeviceId, "ui.lblCmd.value") 
  
      if(strCmd == "") then
        UpdateMeasurement(SensiboDeviceId,apiKey,LinkVitualDeviceId)
        UpdateStatus(SensiboDeviceId,apiKey,LinkVitualDeviceId)
    
    elseif (strCmd == "On") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"on","true",false)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "Off") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"on","false", false)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
     elseif (strCmd == "Auto") then
        fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"mode","auto", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "Dry") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"mode","dry", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "Cool") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"mode","cool", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "Fan") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"mode","fan", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "Low") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"fanLevel","low", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "Medium") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"fanLevel","medium", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "High") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"fanLevel","high", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "FanAuto") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"fanLevel","auto", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "SwingOn") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"swing","rangeFull", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
    elseif (strCmd == "SwingOff") then
          fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"swing","stopped", true)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")
    
        UpdateStatus(SensiboDeviceId,apiKey,LinkVitualDeviceId)
    
    else 
        fibaro:debug(strCmd)
        SetProperties(SensiboDeviceId,apiKey,"targetTemperature",strCmd,false)
        fibaro:call(LinkVitualDeviceId,"setProperty","ui.lblCmd.value", "")        
          return
    end
end

local function json_decode(data)
    local ok, json = pcall(function() return json.decode(data) end)
    if ok then
        return json
    else
        return nil
    end
end

function UpdateMeasurement(SensiboId, apiKey, vdId)
    local http = net.HTTPClient()
    http:request('https://home.sensibo.com/api/v2/pods/'..SensiboId..'/measurements?apiKey=' .. apiKey, {
        success = function(resp)
            if resp.status == 200 then        
                local jsonResp = json_decode(resp.data)
                fibaro:call(vdId, "setProperty", "ui.lblActual.value", "Temp: " .. jsonResp.result[1].temperature .. ", Hum: " .. jsonResp.result[1].humidity)
            end
        end
    })
end

function UpdateStatus(SensiboId, apiKey, vdId)
    local http = net.HTTPClient()
    http:request('https://home.sensibo.com/api/v2/pods/'..SensiboId..'/acStates?fields=status,acState&limit=1&apiKey=' .. apiKey, {
        success = function(resp)
            if resp.status == 200 then 
                local jsonResp = json_decode(resp.data)
                local Status = jsonResp.result[1].acState.on and "On" or "Off"
                local TargetTemp = jsonResp.result[1].acState.targetTemperature or ""
                local acMode = jsonResp.result[1].acState.mode or ""
                local fanLevel = jsonResp.result[1].acState.fanLevel or ""
                local tempUnit = jsonResp.result[1].acState.temperatureUnit or ""
                local Swing = jsonResp.result[1].acState.swing or ""
                
                local displayStatus = "Zasilanie: ".. Status .. ", Temperatura: "..TargetTemp.. " " ..tempUnit
                local displayMode = "Tryb: ".. acMode ..", Moc: " .. fanLevel .. ", Swing: " .. Swing;
          
                fibaro:call(vdId, "setProperty", "ui.lblStatus.value", displayStatus)
                fibaro:call(vdId, "setProperty", "ui.lblModeStatus.value", displayMode)
            end
        end
    })
end

function SetProperties(id, apiKey, property, value, isString)
    local myJson = isString and '{"newValue": "'..value..'"}' or '{"newValue": '..value..'}'
    
    local http = net.HTTPClient()  
    http:request('https://home.sensibo.com/api/v2/pods/'..id..'/acStates/'..property..'?apiKey=' .. apiKey, {
        options = {
            method = 'PATCH',
            timeout = 5000,
            headers = {
                ["content-type"] = "application/x-www-form-urlencoded;"
            },
            data = myJson
        },
        success = function(resp)
            fibaro:debug("Response OK")
        end,
        error = function(err)
            fibaro:debug("Error : " .. err)
        end
    })       
end

Main();
 

Edited by Krzychurychu
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...