Problem showing status of in HABPanel

Hello,
I am Running openhav 3.3
I have a tasmota device (light switch) that that has 2 states (ON, OFF). I created a widget in habpanel that changes color whether the device is ON or OFF. The code looks like the following:

<div ng-if="itemValue('mylight')!='OFF'">
  <button class="btn pnl-turn-off" ng-click="sendCmd('mylight', 'OFF')"> 
    <widget-icon class="pnl-icon-off" iconset="'smarthome-set'" icon="'bulb'" state=itemValue('mylight') size="75"></widget-icon>
    <span class="pnl-switchlabel">Light On/Off</span>
  </button>
</div>

<div ng-if="itemValue('mylight')=='OFF'">
  <button class="btn pnl-turn-on" ng-click="sendCmd('mylight', 'ON')"> 
    <widget-icon class="icon-on" iconset="'smarthome-set'" icon="'bulb'" state=itemValue('mylight') size="75"></widget-icon>
    <span class="pnl-switchlabel">Light On/Off</span>
  </button>
 </div>

This works as it is supposed to. If the device is ON, the widget has the on color. If the device is off, the widget has the off color.

I wanted to use the same method for another device i have. This device has 4 states (0,1,2,3). 0 is the off state, and all the others are on states.(The device is a fan).
I modified the previous code so it would look like this:

<div ng-if="itemValue('myfan')!='0'">
  <button class="btn pnl-turn-off" ng-click="sendCmd('myfan', 'OFF')"> 
    <widget-icon class="pnl-icon-off" iconset="'smarthome-set'" icon="'bulb'" state=itemValue('myfan') size="75"></widget-icon>
    <span class="pnl-switchlabel">Fan On/Off</span>
  </button>
</div>

<div ng-if="itemValue('myfan')=='0'">
  <button class="btn pnl-turn-on" ng-click="sendCmd('myfan', 'ON')"> 
    <widget-icon class="icon-on" iconset="'smarthome-set'" icon="'bulb'" state=itemValue('myfan') size="75"></widget-icon>
    <span class="pnl-switchlabel">Fan On/Off</span>
  </button>
 </div>

Somehow this code never changes the icon color to the off state. I feel like i am doing something silly, but i cannot see what it is. If someone could help me out figure out why this code is not switching to the off color, that would be great.

Thanks!

Check the state carefully; “0.0” is not the same as “0” for an example.

Hello @rossko57,

Thanks for the reply.
I thought the problem could be something of the sort, however, how can i see the “True” response of the device? Right now i am using openhab console to check the logs, and all i see is the status changing to 0, 1, 2 or 3. Is it ‘0’ instead of 0, or ‘0.0’ instead of 0? I am not sure. I am going with what i see in the logs output. I set and get the status changes through MQTT by the way.

Is there a way to debug this? The other thing i thought could be happening is, maybe this is some kind of value type issue, and i should be using a different operator.

Thanks

Also there is a difference between ‘0’ (what’s a string) and 0 (what’s a number). Maybe removing the ’ will help? :thinking: (I’m not an expert for hab panel, therefore not sure if item state is always a string or can also be a number)

That should be sufficient.
All the UIs use REST to query states, and so all states are reported as strings. I don’t know if HABpanel is smart enough to convert to numeric (other UI are not, you must do that yourself) but in this case ‘0’ should suffice?

Hi @Matze0211 ,
I did try this, to no avail. Thanks for the suggestion though.

I would hope so…I hoped that adding the quotes would do whatever automatic casting necessary…but no luck there

What’s happening if you put

itemValue('myfan')

into the span object to see it’s value via hab panel?

The Values, appear to be 0, 1,2 and 3, as expected.

Ah, maybe we are missing one important thing:

My first thoughts were, that the ng-if expression is not working correctly, but this should work fine (maybe add different text to the span object, to validate if the expression is working or not).

However your real issue is, that the icon is not changing, if I read your initial post again.
Your icon is a bulb and there are bulb-ON and buld-OFF icons available.
However as you use a different item with different states, there is no bulb-0, bulb-1, bulb-2 etc icons available, but the state of the icon is still linked to your item (state=itemValue(‘myfan’)).

Maybe hardcore the state to ON or OFF, as your item has different states …

The issue is not the icon, as the icon is not changing. Only the color of the icon is changing.

I have tried the solution using ‘ON’ and ‘OFF’ values. That works to a point, (Tasmota can evaluate ‘ON’ as 1 and ‘OFF’ as 0), however, when the status is reported again from tasmota(this happens periodically), it is reported as a number. Because i am evaulating the ‘ON’ and ‘OFF’ strings, the icon color updates to the wrong color again.

What I was suggesting is not too change your item but to change the widget from:

<widget-icon class="pnl-icon-off" iconset="'smarthome-set'" icon="'bulb'" state=itemValue('myfan') size="75"></widget-icon>

To

<widget-icon class="pnl-icon-off" iconset="'smarthome-set'" icon="'bulb'" state="OFF" size="75"></widget-icon>

And also changing

<widget-icon class="icon-on" iconset="'smarthome-set'" icon="'bulb'" state=itemValue('myfan') size="75"></widget-icon>

To

<widget-icon class="icon-on" iconset="'smarthome-set'" icon="'bulb'" state="ON" size="75"></widget-icon>

Yes, i have tried that too, with no difference.

It feels to me that the problem is the way HABpanel evaluates the inputs when you use (0,1,2,3) instead of (ON,OFF), but i cannot find why it does not work in the first case.