In pages oh-cell widget I use as switch which shows modbus item state. as it takes time after the command to send command to modbus and then to read it, I postUpdate UNDEF to the swith to show that it is in transition. so when modbus updates the switch, it goes to ON/OFF.
I want it to be reflected in oh-cell color, so I have this statement.
thanks, but my line is in quotes and it does actually work. Except the only OFF condition. When item is ON it turns blue, when UNDEF - yellow, when OFF - no color. Why>
Maybe when the item is undef the condition fails. Have you tried with the expression tester to see what is the value when UNDEF? Perhaps you can use a condition that test explicitly for undef
Please use code fences when posting code snippets to the forum.
```
code goes here
```
The epxression looks OK but definitly do what @Lionello_Marrelli suggests and test it in the expression tester in the Developer Sidebar (alt-shift-d).
There are a number of shortcuts that could be used here as well to make the expression more concise. Maybe applying one of those will bypass the error.
This is the issue. As I said, your expression is not the problem. The color is being set to red, it’s just that the color is being ignored.
There are a couple of things going on behind the scenes here. In addition to being able to set the cell color, the oh-cell comes with an on property. When that property is some true value then the cell background takes on the color set in the color property. When on is some falsy value the color property is ignored and the background will be set to the default value.
You’re not using the on property, but you have set the item property. When on is not defined, the cell uses the state of the item defined in item as a shortcut for the on property. However, the item’s UNDEF state does not count as a true value for on, so the cell gets on: false and ignores the background color.
There are a few fixes for this, but the simplest is just to explicitly set on to true: