Dynamic background color in Habpanel?

Is it possible to have the color of a widget change when the item changes? For example, I would like a door widget to change red when the door is open. I have it working when the door is open and the page is refreshed, but when the page is already open only the item status changes in the panel, not the color.

This is my current ng-style setting in my custom door widget.

      'background-color': itemValue(config.ITEM_ID)=='OPEN' ? '{{(config.OPEN_COLOR)}}' : '{{(config.CLOSED_COLOR)}}'

I think you can lose a few quotes and curly braces, your ng-style should be:

      'background-color': itemValue(config.ITEM_ID)=='OPEN' ? config.OPEN_COLOR : config.CLOSED_COLOR
1 Like

Thanks! That did it. I guess I need to learn more than just cut and paste.

A questions on top of that. I want to have a box in habpanel showing status of all windows. It would be nice to show box in green if all windows are closed and in red if one or more windows/dores are open. Has anyone done something similar and can help me with this?

Yes, this is the exact scenario I was working on. I created 2 custom widgets, 1 for single doors/windows, and 1 for groups of items. If door/window in the group is open, the color changes to red.

Attached are the widgets. Within the widget settings you can pick the open and closed colors, and icon. It assumes the standard icons, so if you type “window” for the icon setting, it will use the icons window-open and window-closed depending on the state. I also have an icon size setting as I use the same widgets on a table and a phone, and for the phone I needed smaller image sizes.

door-window.widget.json (1.4 KB)
door-window-group.widget.json (1.4 KB)

Here are some screen shots. The first screen are the group


@ David. Great. I thought of displaying al list of the items. But this is even better. THANKS! I now have to figure out, how to integrate. Hoepfully tonight I have some time when kids are in bed. I am just a beginner mirgrating from the Fibaro HC2.
Thanks to everyone in this forum for joining your experience. This realy helps much to move forward.

@ David: An additional question: can you also share your code for the two weather widges? The would cover my needs. For the beginning I started with a workaround. I integrated a small html file I have saved in a folder on my website. This contains the code that was provided form a weather website as html code for integrating in your website. Works, but does not look that nice… I started with getting an api-code from weahterunderground. For the beginning my plan was to work only with 2.0 bindings. But I think I will start with playing around with the “old” ones as well.

Sure here they are. They may not look great on a larger screen. I was specifically trying to shrink these down to fit on a phone, with the assumption that the phone is only 3 columns of widgets. With that in mind, you need to size the widgets to be 2 columns wide.

forecast.widget.json (4.7 KB)
new-weather.widget.json (2.2 KB)

edit: should also note they also use the climacons

Great. Thanks for sharing. In my current old set up I have a fibaro wall-plug. its color is green when windows are closed and it turns red, when a window is open. The wall plug is next to the android tab close to the entrance door. Unfortunately it looks like there is no item for the wall plug to change its color. In the Fibaro-world there is a virtual device that can be imported. And than you can “press” via a line in lua-code different buttons to change the color. So I do not have to switch the tab on. I directly see red/green before I leave the house. Others are using a hue that covers this functionality.

I’m not sure I fully understand, and know nothing about fibaro, but if there is a way to send a command to the switch to change the color, then you could likely have a rule created to send the command whenever there is a status change for the group of items.

I have successfully included my first Z-Wave device last weekend - a Fibaro Wall Plug. And it is working.
One of the available things is “Color when On” and another “Color when Off” there are values from 0 to 8 possible.
Adding this in HabPanal as a slider is working excelent. :slight_smile:
So I can integrate the functionality I am aiming for :slight_smile:

@ David How do you create the item group in the item file?



Hi David, the door-window.widget works fine for me, Thx, but in case for the group it doesn’t work. Do you use the normal group item ?

@tlrider, @anon27730737

sorry for the delay. here is my group item for the window.

Group:Contact:OR(OPEN,CLOSED) DSCWindows "Windows [(%d)]" <contact> (DSCAlarm,All)

1 Like

Thanks for sharing. One thing I did change is the following line:

<widget-icon iconset="(config.ICONSET)" icon="(config.ICON)"

I changed the manually typed in iconset to a setting variable and created the following setting:

After placing the widget onto a dashboard and editing it there, this is what it looks like changing the icon set:

This is what I have in the bottom right of my main HABpanel dashboard:

Seems to work great. The garage one is the only one I have currently configured and working correctly. I have it tied to my MyQ binding, but would like to use this with the DSC Alarm binding instead. Still have more work to do.

I’m trying to do this same thing with icons instead of background color, but I can’t seem to get it to work. This works for background color:

  <td style="border: 2px solid #76899e; border-radius: 10px; padding: 5px;">
    <div ng-style="{'background-color': itemValue(config.B2item) == 'OFF' ?  '#001428'  : itemValue(config.B2item) == 0 ?  '#001428''#76899e'}">
 		  <widget-switch ng-model="button2" />

but if I try something similar for the icon definition it does not. I’ve tried putting that in the same place as the background color, inside the widget-switch braces, and in the button2 definition to no avail.

How can I make this work with icons?



Hi @ysc

is there a method to change an SVG icon to be on/coloured , if an item state = ON within HabPanel?

I have a picture of a light globe, it would be great to illuminate this if any of my lights are on as an easy way to see if something is on quickly.

See attached


Hi David,

First of all, thanks for creating this widget. The post is a bit older, but I only came across it recently and I have a question.
I installed the widgets in the HabPanel as well as created the group item. So far so good.
Values arrive when there is a change in the item(s) (for me ON and OFF) and are also correctly displayed in the group item (value change for me → ON: OFF).

But what somehow doesn’t work is changing the color of the widget. However, the value does not change color. Likewise, the icon does not change from window closed to window open.
Is there still a rule missing or am I doing something wrong in principle?
In the widget code itself there is OPEN / CLOSE in relation to the “background-color” → Item.value == OPEN, does it have something to do with the fact that the states do not change? Is an OPEN / CLOSE expected and an ON / OFF received?