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

Get the current device icon


tieske

Question

I can set the device icon, but how can I read it?

This code;

Please login or register to see this code.

This is what I get;

Please login or register to see this code.

Is there some alternate way? Am I missing something?

Link to comment
Share on other sites

20 answers to this question

Recommended Posts

  • 0

Do you just want to get id of current icon?

Please login or register to see this code.

variable "icon" will contain id of current icon in string format.

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thx for the feedback, but it doesn't work;

    Please login or register to see this code.

    returns;

    Please login or register to see this code.

    Am I missing something?

    Link to comment
    Share on other sites

    • 0

    If you want to stop button from changing main icon you can do something like this:

    Please login or register to see this code.

    If it doesn't help, please describe what you want to achieve.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • The code I gave was just sample code to test the basics; I want to create a toggle button. Press it once, lights on, press it again, lights off (as a virtual device main button). As my virtual device also uses icons for the on and off state, I should be able to do this by checking the icon value (I cannot use globals). If the current icon is the ON icon, turn off, if it has the OFF icon, turn it on.

    So my sample code sets the icon to ID '1000'. So when I read it back, I would expect to get '1000' as a return value but instead I get '28'.

    Link to comment
    Share on other sites

    • 0

    Ok, so first remember to use fibaro:getValue() function instead of fibaro:get(), also notice, that currentIcon's type is different from deviceIcon's type. And you can try to add a short pause before reading new value of variable.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Ok, so first remember to use fibaro:getValue() function instead of fibaro:get(), also notice, that currentIcon's type is different from deviceIcon's type.

    What is the difference in type? I need to read the icon that I have set before, to make a sensible comparison to decide whether the light is currently on or off.

    Link to comment
    Share on other sites

    • 0

    After a few tries i don't think that would work well without use of global variables, because after restart for example, state of icon would be unknown. So i'm afraid you need to rethink the way you want to do this.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • after a restart the light will be read and icon set in the mainloop. So the icon will Always have a proper value.

    So why does the code return 28 instead of 1000 ?

    Link to comment
    Share on other sites

    • 0

    Use of main loop will cause some delay in update of icon, and thats why it's not perfect solution. I made a device for you, capable of changing icon and toogling state of switch. All you need to do is entering id of switch and id's of ON and OFF icons. Of course you need to upload 2 more icons and read their ID's from api.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I see what you did, you are polling the device status and then setting the icon from there.

    I can't use polling. The device isn't a zwave device, but a virtual device and some do not support polling. Those will just be set to some 'startup state'. So I must store the state myself, and I don't want to use a global.

    Tried again using a 5 seconds delay;

    Please login or register to see this code.

    But it keeps printing '28' for the icon value in the debug window. Bug maybe?

    Link to comment
    Share on other sites

    • 0

    Instead

    Please login or register to see this code.

    you should use

    Please login or register to see this code.

    Changing currentIcon will not affect deviceIcon, it will remain the same. Is the code you posted in a main loop or button?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • same result (which is logical).

    I'm using this code from a button (I want to create a toggle button)

    Link to comment
    Share on other sites

    • 0

    You can't change deviceIcon by changing currentIcon, these are two different values. DeviceIcon is changed manually by hitting "change icon" button in virtual device configuration. How you want to create toogle button without reading state of some other device or variable?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • You can't change deviceIcon by changing currentIcon, these are two different values. DeviceIcon is changed manually by hitting "change icon" button in virtual device configuration.

    Then how can I read the 'currentIcon'?

    How you want to create toogle button without reading state of some other device or variable?

    The state is stored in the 'currentIcon' property, if the value is the 'offIcon' then the light is off, otherwise it has the 'onIcon' value and the light is on. I'm 'abusing' the icon to store the state.

    And as it is possible to set the 'currentIcon' property, I want to know how to read it...

    Link to comment
    Share on other sites

    • 0

    After hitting button, the virtual device will set icon of button as "currentIcon", so checking state of currentIcon in button section has no sense. Maybe you should change button icon to match the state of device. Reading currentIcon is simple as that:

    Please login or register to see this code.

    buf if you are changing icon in the same button you need to add some delay or it will alway show id of button.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Now I have it working, using a 5 second delay; but only in the same code block.

    Sample code:

    Please login or register to see this code.

    Output in the debug window after 2 presses;

    Please login or register to see this code.

    Notice the 2nd press, it starts again with 0. It appears to me that whenever a piece of Lua code is run, the icon first gets reset to the default device icon, so the state I saved in the icon gets lost. This is also shown in the web interface, where the 'blue box' icon is shortly visible.

    Is that intentional? Why would the HC reset that icon?

    Link to comment
    Share on other sites

    • 0

    As i said before after hitting button, the virtual device will set icon of button as "currentIcon". That is why you are getting id 0 in the first place. You can change icon of every button manually and it will replace defaul device icon, once button is hit. It is a feature of our system. And that is why i said that checking icon of device after you hit the button is pointless and you need to check state of module itself.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Sorry I missed that. Probably because it seems so weird to me. If an icon is set, why in the world would you want to have it reverted automatically?

    What's the rationale behind this?

    Link to comment
    Share on other sites

    • 0

    For example, when you want to control light with virtual device you can set icons of two buttons to represent lights on and lights off. When you hit "on" button the code enables light and replace icon to show current state of module. Same for "off".

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • OK, so the icon I select for a specific button will be assigned to the device when that button is clicked.

    Then please update the behaviour that it will only update the device icon, if the button related icon is NOT the default blue box. Or provide a checkbox "don't set icon when button is clicked" for buttons.

    [ Added: 2014-06-19, 11:51 ]

    Just posted in the bugzilla tool;

    Please login or register to see this link.

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