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

How change icon in scene window?


Guest samuelboerhoop

Question

Guest samuelboerhoop
Posted

When you are adding a scene iand programming in Lua code, your are also able to change the icon in the general tab.

 

When i write s program in lua, i want to be able to change the icon from the scene if the state change...

 

How to do so?

 

My setup:

------------------------------------------------------------------------------

 if ( humidity >= 69 ) then 
    fibaro:call(283, "turnOn");
    log("Ventilation ON");
    fibaro:call(272, "setProperty", "currentIcon", 1057) 
    fibaro:call(259, "sendDefinedPushNotification", "278"); 
 end
--------------------------------------------------------------------------------
 
272 = Id of the scene
fibaro:call(272, "setProperty", "currentIcon", 1057) 
is this correct to add this line. because nothing change!
 
Asking same question as in topic: 

Please login or register to see this link.

12 answers to this question

Recommended Posts

  • 0
Posted

Please login or register to see this code.

-- use this lua code in scene:

local url = 'http://127.0.0.1:11111/api/scenes'

local function putMethod(requestUrl, successCallback, errorCallback)

local http = net.HTTPClient()

http:request(requestUrl, {

options = {

method = 'PUT',

data = message

},

success = successCallback,

error = errorCallback

})

end

message = '{"id": 272, "iconID": 1057}' -- this scene id = 272 and new icon id = 1057

putMethod(url,

function(resp)

print('Status dla PUT: ' .. resp.status)

end,

function(err)

print('error' .. err)

end

)

  • 0
Posted

I tried this code but with no success.

It doesn't change the Scene Icon

 

I get this message in the debug: Status dla PUT: 401

Am I missing something??

  • 0
Guest samuelboerhoop
  • Inquirer
  • Posted

    error in the following line:

    http:request(requestUrl, {

     

    error message in debug: [ERROR] 11:30:16: line 8: attempt to index global 'net' (a nil value)

     
    which starts with:
    local function putMethod(requestUrl, successCallback, errorCallback)
    local http = net.HTTPClient()
    http:request(requestUrl, {
     
    What is wrong in this script?
    • 0
    Posted (edited)

    scene code in LUA is ok. I try it now and work good.

     

    You must only change in this code your id of scene and your id icon.

     

     

    ...please show your script of scene here..

    Edited by Jacek
    • 0
    Posted

    ....copy 1 to 1 all LUA script in your scene. Change id of scene for yours and id of icon.

    Id icon must be true. Run script of scene.

    • 0
    Posted

    It works fine now.

    I used to change the URL to my Home Center IP address.

    It is supposed to be left as is.

    • 0
    Posted

    ...i know, you change adress IP ! It was mistake.

    • 0
    Guest samuelboerhoop
  • Inquirer
  • Posted

    This is my scene: Auto Ceiling Fan - with ID:248

    The image in the scene is not changing, see scene below:

     

     
    --[[
    %% properties
    276 value
    --268 value
    %% events
    %% globals
    --]]
     
    -- to be checked --
    local debug = true; --true -- false
    local Ceiling_Fan = 276; -- Ceiling Fan
    local Temp_Sensor = 268; -- Temp Sensor Family Lounge
    local StartSource = fibaro:getSourceTrigger()
    local powerfan = tonumber(fibaro:getValue(Ceiling_Fan, "power")); -- power ceiling fan lamp
    local ceilingfan = tonumber(fibaro:getValue(Ceiling_Fan, "value"));
    local Temperature = tonumber(fibaro:getValue(Temp_Sensor, "value"));
     
    local function log(str)
      if debug then 
        fibaro:debug(str); end; end
     
    if (tonumber(fibaro:countScenes()) > 2) then  --1
      log("Script already running.");
      fibaro:abort(); 
    end
     
        if (Temperature >= 22) and (ceilingfan > 0) and (powerfan <= 6 ) then 
          fibaro:call(104, "pressButton", "2"); -- Turn Light OFF
          log("Light OFF"); 
          fibaro:call(104, "pressButton", "5"); -- Set Fan Speed to III
          log("Speed III ON");
      
      
                -- change running fan icon
                local url = '

    Please login or register to see this link.

              
              local function putMethod(requestUrl, successCallback, errorCallback)
                local http = net.HTTPClient()
                http:request(requestUrl, {
                    options = {
                      method = 'PUT',
                      data = message
                    },
                    success = successCallback,
                    error = errorCallback
                })
              end
                  message = '{"id": 248, "iconID": 1055}'  -- this scene id = 248 and new icon id = 1055
                  putMethod(url, 
                    function(resp)  
                      print('Status dla PUT: ' .. resp.status) 
                    end, 
                    function(err)   
                      print('error' .. err) 
                    end 
                  )
                  -- end changing fan icon script
      
        end
       
    -- loop until below threshold temperature
    while (Temperature >= 22) and (ceilingfan > 0) do
      
      local ceilingfan = tonumber(fibaro:getValue(276, "value"));
      local Temperature = tonumber(fibaro:getValue(Temp_Sensor, "value"));
     
      -- check temperature from sensor
    log("Temperature = "..Temperature.." ℃");
           
    log("Wait 30 seconds for next Measurement")
    fibaro:sleep(30*1000); 
     --::stop:: 
     -- fibaro:abort(); 
      
            if (ceilingfan == 0) then 
            log("Ceiling Fan was Turned OFF");
            --fibaro:abort(); 
            goto stop
            end
     
    end
     
     ::stop::
     
        if (Temperature <= 19) then
          fibaro:call(104, "pressButton", "6");
          log("Speed III OFF");  
        end  
     
                -- change running fan icon
                local url = '

    Please login or register to see this link.

              
              local function putMethod(requestUrl, successCallback, errorCallback)
                local http = net.HTTPClient()
                http:request(requestUrl, {
                    options = {
                      method = 'PUT',
                      data = message
                    },
                    success = successCallback,
                    error = errorCallback
                })
              end
                  message = '{"id": 248, "iconID": 1060}'  -- this scene id = 248 is Fan ON and new icon id = 1060 
                  putMethod(url, 
                    function(resp)  
                      print('Status dla PUT: ' .. resp.status) 
                    end, 
                    function(err)   
                      print('error' .. err) 
                    end 
                  )
                  -- end changing fan icon script
     

     

    • 0
    Posted

    try only this code in your scene id = 248:

    Please login or register to see this code.

    and run script of scene.

    • 0
    Guest samuelboerhoop
  • Inquirer
  • Posted

    I add a new scene with another ID 276 and put the scene in manual mode. (tried later in automatic mode)

    HC2 V4.090

     

    it does work on the webinterface, but i need to refresh the page to make the change visible. How can that be avoided?

    • 0
    Posted

    Yes the same here.

    Either from the mobile app or from the web interface, I need to refresh to see that change in icon.

    • 0
    Guest samuelboerhoop
  • Inquirer
  • Posted

    Something for Fibaro to work on, as a feature to make it work

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    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...